Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ATM_Stream.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: ATM_Stream.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:20 chad Exp $
00003 
00004 #include "ace/ATM_Stream.h"
00005 
00006 ACE_RCSID (ace, ATM_Stream, "$Id: ATM_Stream.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:20 chad Exp $")
00007 
00008 #if defined (ACE_HAS_ATM)
00009 
00010 #if !defined (__ACE_INLINE__)
00011 #include "ace/ATM_Stream.i"
00012 #endif /* __ACE_INLINE__ */
00013 
00014 ACE_ALLOC_HOOK_DEFINE (ACE_ATM_Stream)
00015 
00016 void
00017 ACE_ATM_Stream::dump (void) const
00018 {
00019   ACE_TRACE ("ACE_ATM_Stream::dump");
00020 }
00021 
00022 char*
00023 ACE_ATM_Stream::get_peer_name (void) const
00024 {
00025   ACE_TRACE ("ACE_ATM_Stream::get_peer_name");
00026 #if defined (ACE_HAS_FORE_ATM_XTI) 
00027   //   // Use t_getprotaddr for XTI/ATM
00028   //   struct t_bind *localaddr 
00029   //     = (struct t_bind *) ACE_OS::t_alloc (get_handle (),
00030   //                                          T_BIND,
00031   //                                          T_ADDR);
00032   //   struct t_bind *peeraddr 
00033   //      = (struct t_bind *) ACE_OS::t_alloc (get_handle (),
00034   //                                           T_BIND,
00035   //                                           T_ADDR);
00036   //   ::t_getprotaddr (get_handle (),
00037   //                   localaddr,
00038   //                   peeraddr);
00039 
00040   //   char* connected_name = (char*) ACE_OS::malloc (peeraddr->addr.len + 1);
00041   //   ACE_OS::strcpy (connected_name,
00042   //                  peeraddr->addr.buf);
00043   //   ACE_OS::t_free ((char *) localaddr,
00044   //                   T_BIND);
00045   //   ACE_OS::t_free ((char *) peeraddr,
00046   //                   T_BIND);
00047   //   return (connected_name);
00048 
00049 #error "This doesn't seem to work. May need to jimmy-rig something with the"
00050 #error "/etc/xti_hosts file - Ugh!"
00051 
00052   ACE_ATM_Addr sa;
00053   struct netbuf name;
00054   name.maxlen = sa.get_size ();
00055   name.buf = (char *) sa.get_addr ();
00056   ACE_OS::t_getname (this->get_handle (), &name, REMOTENAME);
00057   //  ACE_OS::ioctl (this->get_handle (),
00058   //               TI_GETPEERNAME,
00059   //               &name);
00060   return (name.buf);
00061 
00062 #elif defined (ACE_HAS_FORE_ATM_WS2) 
00063   // Use getpeername for WinSock2.
00064   struct sockaddr_atm name;
00065   ACE_OS::memset (&name, 0, sizeof (name));
00066   int nameSize = sizeof (name);
00067 
00068   if (ACE_OS::getpeername (this->get_handle (),
00069  (struct sockaddr *) &name,
00070                           &nameSize) != 0) {
00071     return 0;
00072   }
00073 
00074   char buffer[256];
00075   for (unsigned int index = 0; index < ATM_ADDR_SIZE - 1; index++) {
00076     buffer[ index * 3 ] = '\0';
00077     sprintf (buffer, "%s%02x.", buffer, name.satm_number.Addr[ index ]);
00078   }
00079   buffer[ (ATM_ADDR_SIZE - 1) * 3 ] = '\0';
00080   sprintf (buffer, "%s%02x.", buffer, 0);
00081   buffer[ ATM_ADDR_SIZE * 3 - 1 ] = '\0';
00082   for (index = 0; index < ACE_OS::strlen (buffer); ++index) 
00083     buffer[index] = tolower (buffer[index]);
00084 
00085   ifstream atm_hosts ("C:/WINNT/atmhosts");
00086   assert (atm_hosts.is_open ());
00087 
00088   // Find the host address in the ATM hosts file and return the
00089   //  host name
00090   char line[256];
00091   char *host_ptr, *host_name = 0;
00092   ACE_NEW_RETURN (host_name, char[256], 0);
00093   while (!atm_hosts.eof ()) {
00094     atm_hosts.getline (line, 256);
00095     // Convert the line to lower case to ease comparison
00096     for (index = 0; index < ACE_OS::strlen (line); ++index) 
00097       line[index] = tolower (line[index]);
00098     if (ACE_OS::strstr (line, buffer) != 0) 
00099       {
00100         char *strtok_p;
00101         // Grab the second token which is the host name
00102         ACE_OS::strtok_r (line, " \t", &strtok_p);
00103         host_ptr = strtok (0, " \t", &strtok_p);
00104         ACE_OS::strcpy (host_name, host_ptr);
00105         break;
00106       }
00107   }
00108 
00109   return host_name;
00110 #elif defined (ACE_HAS_LINUX_ATM) 
00111   ATM_Addr name;
00112   int nameSize = sizeof (name.sockaddratmsvc);
00113 
00114   if (ACE_OS::getpeername (this->get_handle (),
00115  (struct sockaddr *) & (name.sockaddratmsvc),
00116                           &nameSize) < 0) {
00117     ACE_OS::perror ("ACE_ATM_Stream (get_peer_name) : ");
00118     return 0;
00119   }
00120 
00121   static ACE_TCHAR buffer[MAX_ATM_ADDR_LEN + 1];
00122   int total_len;
00123   if ((total_len = atm2text (buffer,sizeof buffer,
00124  (struct sockaddr *) & (name.sockaddratmsvc), 
00125                             A2T_PRETTY|A2T_NAME)) < 0) {
00126     ACE_DEBUG ((LM_DEBUG,ACE_LIB_TEXT ("ACE_ATM_Stream (get_peer_name) :%d"),errno));
00127     return 0;
00128   }
00129 
00130   return (char*) buffer;
00131 #else
00132   return 0;
00133 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
00134 }
00135 
00136 ACE_HANDLE
00137 ACE_ATM_Stream::get_handle (void) const
00138 {
00139   ACE_TRACE ("ACE_ATM_Stream::get_handle");
00140 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2) || defined (ACE_HAS_LINUX_ATM) 
00141   return stream_.get_handle ();
00142 #else
00143   return 0;
00144 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
00145 }
00146 
00147 int
00148 ACE_ATM_Stream::get_vpi_vci (ACE_UINT16 &vpi,
00149                              ACE_UINT16 &vci) const
00150 {
00151   ACE_TRACE ("ACE_ATM_Stream::get_vpi_vci");
00152 #if defined (ACE_HAS_FORE_ATM_XTI) 
00153   struct t_atm_conn_prop conn_prop;
00154   char* connect_opts = (char *) &conn_prop;
00155   int opt_size = sizeof (t_atm_conn_prop);
00156   struct t_info info;
00157   struct t_optmgmt opt_req, opt_ret;
00158 
00159   if (ACE_OS::t_getinfo (stream_.get_handle (),
00160                         &info) < 0) 
00161     {
00162       ACE_OS::t_error ("t_getinfo");
00163       return -1;
00164     }
00165 
00166   char *buf_req = (char *) ACE_OS::malloc (info.options);
00167   if (buf_req == 0) 
00168     {
00169       ACE_OS::fprintf (stderr,
00170                       "Unable to allocate %ld bytes for options\n",
00171                       info.options);
00172       return -1;
00173     }
00174 
00175   char *buf_ret = (char *) ACE_OS::malloc (info.options);
00176   if (buf_ret == 0) 
00177     {
00178       ACE_OS::fprintf (stderr,
00179                       "Unable to allocate %ld bytes for options\n",
00180                       info.options);
00181       return -1;
00182     }
00183 
00184   ACE_OS::memset (&opt_req, 0, sizeof (opt_req));
00185   ACE_OS::memset (&opt_ret, 0, sizeof (opt_ret));
00186 
00187   struct t_opthdr *popt = (struct t_opthdr *) buf_req;
00188   struct t_opthdr *popt_ret = (struct t_opthdr *) buf_ret;
00189 
00190   popt->len= sizeof (struct t_opthdr) + opt_size;
00191 
00192   // We are only concerned with SVCs so no other check or values are needed
00193   //  here.
00194   popt->level = T_ATM_SIGNALING;
00195   popt->name = T_ATM_CONN_PROP;
00196   popt->status = 0;
00197 
00198   opt_req.opt.len = popt->len;
00199   opt_req.opt.buf = (char *) popt;
00200   opt_req.flags = T_CURRENT;
00201 
00202   popt = T_OPT_NEXTHDR (buf_req,
00203                        info.options,
00204                        popt);
00205   opt_ret.opt.maxlen  = info.options;
00206   opt_ret.opt.buf = (char *) popt_ret;
00207 
00208   if (ACE_OS::t_optmgmt (stream_.get_handle (),
00209                         &opt_req,
00210                         &opt_ret) < 0) {
00211     ACE_OS::t_error ("t_optmgmt");
00212     return -1;
00213   }
00214 
00215   ACE_OS::memcpy (connect_opts,
00216  (char *) popt_ret + sizeof (struct t_opthdr),
00217                  opt_size);
00218 
00219   ACE_OS::free (buf_ret);
00220   ACE_OS::free (buf_req);
00221 
00222   vpi = conn_prop.vpi;
00223   vci = conn_prop.vci;
00224   return (0);
00225 #elif defined (ACE_HAS_FORE_ATM_WS2) 
00226   ATM_CONNECTION_ID connID;
00227   DWORD bytes = 0;
00228   
00229   if (::WSAIoctl ((int) this -> get_handle (), 
00230                   SIO_GET_ATM_CONNECTION_ID, 
00231                   0, 
00232                   0, 
00233  (LPVOID) &connID, 
00234                   sizeof (ATM_CONNECTION_ID), 
00235                   &bytes, 
00236                   0, 
00237                   0) 
00238        == SOCKET_ERROR) {
00239     ACE_OS::printf ("Error: WSAIoctl %d\n", WSAGetLastError ());
00240   }
00241 
00242   vpi = (ACE_UINT16) connID.VPI;
00243   vci = (ACE_UINT16) connID.VCI;
00244 
00245   return 0;
00246 #elif defined (ACE_HAS_LINUX_ATM) 
00247 #if defined (SO_ATMPVC) /* atm version>=0.62 */
00248   struct sockaddr_atmpvc mypvcaddr;
00249   int addrpvclen = sizeof (mypvcaddr);
00250   if (ACE_OS::getsockopt (stream_.get_handle (),
00251                          SOL_ATM,
00252                          SO_ATMPVC, 
00253                          ACE_reinterpret_cast (char*,&mypvcaddr),
00254                          &addrpvclen) < 0) {
00255     ACE_DEBUG (LM_DEBUG,
00256               ACE_LIB_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"),
00257               errno);
00258     return -1;
00259   }
00260   vpi = (ACE_UINT16) mypvcaddr.sap_addr.vpi;
00261   vci = (ACE_UINT16) mypvcaddr.sap_addr.vci;
00262 
00263   return 0;
00264 #elif defined (SO_VCID) /* patch for atm version 0.59 */
00265   struct atm_vcid mypvcid; 
00266   int pvcidlen = sizeof (mypvcid);
00267   if (ACE_OS::getsockopt (stream_.get_handle (),
00268                          SOL_ATM,SO_VCID,
00269                          ACE_reinterpret_cast (char*,&mypvcid),
00270                          &pvcidlen) < 0) {
00271     ACE_DEBUG (LM_DEBUG,
00272               ACE_LIB_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"),
00273               errno);
00274     return -1;
00275   }
00276   vpi = (ACE_UINT16) mypvcid.vpi;
00277   vci = (ACE_UINT16) mypvcid.vci;
00278 
00279   return 0;
00280 #else
00281   ACE_DEBUG (LM_DEBUG,
00282             ACE_LIB_TEXT ("ACE_ATM_Stream::get_vpi_vci: Not implemented in this ATM version. Update to >= 0.62\n Or patch 0.59"));
00283   ACE_UNUSED_ARG (vci);
00284   ACE_UNUSED_ARG (vpi);
00285 
00286   return (-1);
00287 #endif /* SO_ATMPVC || SO_VCID */
00288 #else
00289   return (-1);
00290 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
00291 }
00292 
00293 #endif /* ACE_HAS_ATM */

Generated on Mon Jun 16 11:19:09 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002