1 #include "ace/ATM_Stream.h"
3 #if defined (ACE_HAS_ATM)
5 #include "ace/OS_NS_string.h"
7 #if !defined (__ACE_INLINE__)
8 #include "ace/ATM_Stream.inl"
9 #endif /* __ACE_INLINE__ */
11 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
13 ACE_ALLOC_HOOK_DEFINE (ACE_ATM_Stream
)
16 ACE_ATM_Stream::get_peer_name (void) const
18 ACE_TRACE ("ACE_ATM_Stream::get_peer_name");
19 #if defined (ACE_HAS_FORE_ATM_XTI)
20 // // Use t_getprotaddr for XTI/ATM
21 // struct t_bind *localaddr
22 // = (struct t_bind *) ACE_OS::t_alloc (get_handle (),
25 // struct t_bind *peeraddr
26 // = (struct t_bind *) ACE_OS::t_alloc (get_handle (),
29 // ::t_getprotaddr (get_handle (),
33 // char* connected_name = (char*) ACE_OS::malloc (peeraddr->addr.len + 1);
34 // ACE_OS::strcpy (connected_name,
35 // peeraddr->addr.buf);
36 // ACE_OS::t_free ((char *) localaddr,
38 // ACE_OS::t_free ((char *) peeraddr,
40 // return (connected_name);
42 #error "This doesn't seem to work. May need to jimmy-rig something with the"
43 #error "/etc/xti_hosts file - Ugh!"
47 name
.maxlen
= sa
.get_size ();
48 name
.buf
= (char *) sa
.get_addr ();
49 ACE_OS::t_getname (this->get_handle (), &name
, REMOTENAME
);
50 // ACE_OS::ioctl (this->get_handle (),
55 #elif defined (ACE_HAS_FORE_ATM_WS2)
56 // Use getpeername for WinSock2.
57 struct sockaddr_atm name
;
58 ACE_OS::memset (&name
, 0, sizeof (name
));
59 int nameSize
= sizeof (name
);
61 if (ACE_OS::getpeername (this->get_handle (),
62 (struct sockaddr
*) &name
,
68 for (unsigned int index
= 0; index
< ATM_ADDR_SIZE
- 1; index
++) {
69 buffer
[ index
* 3 ] = '\0';
70 ACE_OS::sprintf (buffer
, "%s%02x.", buffer
, name
.satm_number
.Addr
[ index
]);
72 buffer
[ (ATM_ADDR_SIZE
- 1) * 3 ] = '\0';
73 ACE_OS::sprintf (buffer
, "%s%02x.", buffer
, 0);
74 buffer
[ ATM_ADDR_SIZE
* 3 - 1 ] = '\0';
75 for (index
= 0; index
< ACE_OS::strlen (buffer
); ++index
)
76 buffer
[index
] = ACE_OS::ace_tolower (buffer
[index
]);
78 ifstream
atm_hosts ("C:/WINNT/atmhosts");
79 assert (atm_hosts
.is_open ());
81 // Find the host address in the ATM hosts file and return the
84 char *host_ptr
, *host_name
= 0;
85 ACE_NEW_RETURN (host_name
, char[256], 0);
86 while (!atm_hosts
.eof ()) {
87 atm_hosts
.getline (line
, 256);
88 // Convert the line to lower case to ease comparison
89 for (index
= 0; index
< ACE_OS::strlen (line
); ++index
)
90 line
[index
] = ACE_OS::ace_tolower (line
[index
]);
91 if (ACE_OS::strstr (line
, buffer
) != 0)
94 // Grab the second token which is the host name
95 ACE_OS::strtok_r (line
, " \t", &strtok_p
);
96 host_ptr
= ACE_OS::strtok (0, " \t", &strtok_p
);
97 ACE_OS::strcpy (host_name
, host_ptr
);
103 #elif defined (ACE_HAS_LINUX_ATM)
105 int nameSize
= sizeof (name
.sockaddratmsvc
);
107 if (ACE_OS::getpeername (this->get_handle (),
108 (struct sockaddr
*) & (name
.sockaddratmsvc
),
110 ACE_OS::perror ("ACE_ATM_Stream (get_peer_name) : ");
114 static ACE_TCHAR buffer
[MAX_ATM_ADDR_LEN
+ 1];
116 if ((total_len
= atm2text (buffer
,sizeof buffer
,
117 (struct sockaddr
*) & (name
.sockaddratmsvc
),
118 A2T_PRETTY
|A2T_NAME
)) < 0) {
119 ACELIB_DEBUG ((LM_DEBUG
,ACE_TEXT ("ACE_ATM_Stream (get_peer_name) :%d"),errno
));
123 return (char*) buffer
;
126 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
130 ACE_ATM_Stream::get_handle (void) const
132 ACE_TRACE ("ACE_ATM_Stream::get_handle");
133 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2) || defined (ACE_HAS_LINUX_ATM)
134 return stream_
.get_handle ();
137 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
141 ACE_ATM_Stream::get_vpi_vci (ACE_UINT16
&vpi
,
142 ACE_UINT16
&vci
) const
144 ACE_TRACE ("ACE_ATM_Stream::get_vpi_vci");
145 #if defined (ACE_HAS_FORE_ATM_XTI)
146 struct t_atm_conn_prop conn_prop
;
147 char* connect_opts
= (char *) &conn_prop
;
148 int opt_size
= sizeof (t_atm_conn_prop
);
150 struct t_optmgmt opt_req
, opt_ret
;
152 if (ACE_OS::t_getinfo (stream_
.get_handle (),
155 ACE_OS::t_error ("t_getinfo");
159 char *buf_req
= (char *) ACE_OS::malloc (info
.options
);
162 ACE_OS::fprintf (stderr
,
163 "Unable to allocate %ld bytes for options\n",
168 char *buf_ret
= (char *) ACE_OS::malloc (info
.options
);
171 ACE_OS::fprintf (stderr
,
172 "Unable to allocate %ld bytes for options\n",
177 ACE_OS::memset (&opt_req
, 0, sizeof (opt_req
));
178 ACE_OS::memset (&opt_ret
, 0, sizeof (opt_ret
));
180 struct t_opthdr
*popt
= (struct t_opthdr
*) buf_req
;
181 struct t_opthdr
*popt_ret
= (struct t_opthdr
*) buf_ret
;
183 popt
->len
= sizeof (struct t_opthdr
) + opt_size
;
185 // We are only concerned with SVCs so no other check or values are needed
187 popt
->level
= T_ATM_SIGNALING
;
188 popt
->name
= T_ATM_CONN_PROP
;
191 opt_req
.opt
.len
= popt
->len
;
192 opt_req
.opt
.buf
= (char *) popt
;
193 opt_req
.flags
= T_CURRENT
;
195 popt
= T_OPT_NEXTHDR (buf_req
,
198 opt_ret
.opt
.maxlen
= info
.options
;
199 opt_ret
.opt
.buf
= (char *) popt_ret
;
201 if (ACE_OS::t_optmgmt (stream_
.get_handle (),
204 ACE_OS::t_error ("t_optmgmt");
208 ACE_OS::memcpy (connect_opts
,
209 (char *) popt_ret
+ sizeof (struct t_opthdr
),
212 ACE_OS::free (buf_ret
);
213 ACE_OS::free (buf_req
);
218 #elif defined (ACE_HAS_FORE_ATM_WS2)
219 ATM_CONNECTION_ID connID
;
222 if (::WSAIoctl ((int) this -> get_handle (),
223 SIO_GET_ATM_CONNECTION_ID
,
227 sizeof (ATM_CONNECTION_ID
),
232 ACE_OS::printf ("Error: WSAIoctl %d\n", WSAGetLastError ());
235 vpi
= (ACE_UINT16
) connID
.VPI
;
236 vci
= (ACE_UINT16
) connID
.VCI
;
239 #elif defined (ACE_HAS_LINUX_ATM)
240 #if defined (SO_ATMPVC) /* atm version>=0.62 */
241 struct sockaddr_atmpvc mypvcaddr
;
242 int addrpvclen
= sizeof (mypvcaddr
);
243 if (ACE_OS::getsockopt (stream_
.get_handle (),
246 reinterpret_cast<char*> (&mypvcaddr
),
248 ACELIB_DEBUG (LM_DEBUG
,
249 ACE_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"),
253 vpi
= (ACE_UINT16
) mypvcaddr
.sap_addr
.vpi
;
254 vci
= (ACE_UINT16
) mypvcaddr
.sap_addr
.vci
;
257 #elif defined (SO_VCID) /* patch for atm version 0.59 */
258 struct atm_vcid mypvcid
;
259 int pvcidlen
= sizeof (mypvcid
);
260 if (ACE_OS::getsockopt (stream_
.get_handle (),
262 reinterpret_cast<char*> (&mypvcid
),
264 ACELIB_DEBUG (LM_DEBUG
,
265 ACE_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"),
269 vpi
= (ACE_UINT16
) mypvcid
.vpi
;
270 vci
= (ACE_UINT16
) mypvcid
.vci
;
274 ACELIB_DEBUG (LM_DEBUG
,
275 ACE_TEXT ("ACE_ATM_Stream::get_vpi_vci: Not implemented in this ATM version. Update to >= 0.62\n Or patch 0.59"));
276 ACE_UNUSED_ARG (vci
);
277 ACE_UNUSED_ARG (vpi
);
280 #endif /* SO_ATMPVC || SO_VCID */
283 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
286 ACE_END_VERSIONED_NAMESPACE_DECL
288 #endif /* ACE_HAS_ATM */