Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / ATM_Stream.cpp
blobe750a45770295a4d9c3a6a5ae7d4a34e90b0d255
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)
15 char*
16 ACE_ATM_Stream::get_peer_name () 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 (),
23 // T_BIND,
24 // T_ADDR);
25 // struct t_bind *peeraddr
26 // = (struct t_bind *) ACE_OS::t_alloc (get_handle (),
27 // T_BIND,
28 // T_ADDR);
29 // ::t_getprotaddr (get_handle (),
30 // localaddr,
31 // peeraddr);
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,
37 // T_BIND);
38 // ACE_OS::t_free ((char *) peeraddr,
39 // T_BIND);
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!"
45 ACE_ATM_Addr sa;
46 struct netbuf name;
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 (),
51 // TI_GETPEERNAME,
52 // &name);
53 return (name.buf);
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,
63 &nameSize) != 0) {
64 return 0;
67 char buffer[256];
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
82 // host name
83 char line[256];
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)
93 char *strtok_p;
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);
98 break;
102 return host_name;
103 #elif defined (ACE_HAS_LINUX_ATM)
104 ATM_Addr name;
105 int nameSize = sizeof (name.sockaddratmsvc);
107 if (ACE_OS::getpeername (this->get_handle (),
108 (struct sockaddr *) & (name.sockaddratmsvc),
109 &nameSize) < 0) {
110 ACE_OS::perror ("ACE_ATM_Stream (get_peer_name) : ");
111 return 0;
114 static ACE_TCHAR buffer[MAX_ATM_ADDR_LEN + 1];
115 int total_len;
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));
120 return 0;
123 return (char*) buffer;
124 #else
125 return 0;
126 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
129 ACE_HANDLE
130 ACE_ATM_Stream::get_handle () 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 ();
135 #else
136 return 0;
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);
149 struct t_info info;
150 struct t_optmgmt opt_req, opt_ret;
152 if (ACE_OS::t_getinfo (stream_.get_handle (),
153 &info) < 0)
155 ACE_OS::t_error ("t_getinfo");
156 return -1;
159 char *buf_req = (char *) ACE_OS::malloc (info.options);
160 if (buf_req == 0)
162 ACE_OS::fprintf (stderr,
163 "Unable to allocate %ld bytes for options\n",
164 info.options);
165 return -1;
168 char *buf_ret = (char *) ACE_OS::malloc (info.options);
169 if (buf_ret == 0)
171 ACE_OS::fprintf (stderr,
172 "Unable to allocate %ld bytes for options\n",
173 info.options);
174 return -1;
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
186 // here.
187 popt->level = T_ATM_SIGNALING;
188 popt->name = T_ATM_CONN_PROP;
189 popt->status = 0;
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,
196 info.options,
197 popt);
198 opt_ret.opt.maxlen = info.options;
199 opt_ret.opt.buf = (char *) popt_ret;
201 if (ACE_OS::t_optmgmt (stream_.get_handle (),
202 &opt_req,
203 &opt_ret) < 0) {
204 ACE_OS::t_error ("t_optmgmt");
205 return -1;
208 ACE_OS::memcpy (connect_opts,
209 (char *) popt_ret + sizeof (struct t_opthdr),
210 opt_size);
212 ACE_OS::free (buf_ret);
213 ACE_OS::free (buf_req);
215 vpi = conn_prop.vpi;
216 vci = conn_prop.vci;
217 return 0;
218 #elif defined (ACE_HAS_FORE_ATM_WS2)
219 ATM_CONNECTION_ID connID;
220 DWORD bytes = 0;
222 if (::WSAIoctl ((int) this -> get_handle (),
223 SIO_GET_ATM_CONNECTION_ID,
226 (LPVOID) &connID,
227 sizeof (ATM_CONNECTION_ID),
228 &bytes,
231 == SOCKET_ERROR) {
232 ACE_OS::printf ("Error: WSAIoctl %d\n", WSAGetLastError ());
235 vpi = (ACE_UINT16) connID.VPI;
236 vci = (ACE_UINT16) connID.VCI;
238 return 0;
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 (),
244 SOL_ATM,
245 SO_ATMPVC,
246 reinterpret_cast<char*> (&mypvcaddr),
247 &addrpvclen) < 0) {
248 ACELIB_DEBUG (LM_DEBUG,
249 ACE_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"),
250 errno);
251 return -1;
253 vpi = (ACE_UINT16) mypvcaddr.sap_addr.vpi;
254 vci = (ACE_UINT16) mypvcaddr.sap_addr.vci;
256 return 0;
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 (),
261 SOL_ATM,SO_VCID,
262 reinterpret_cast<char*> (&mypvcid),
263 &pvcidlen) < 0) {
264 ACELIB_DEBUG (LM_DEBUG,
265 ACE_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"),
266 errno);
267 return -1;
269 vpi = (ACE_UINT16) mypvcid.vpi;
270 vci = (ACE_UINT16) mypvcid.vci;
272 return 0;
273 #else
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);
279 return -1;
280 #endif /* SO_ATMPVC || SO_VCID */
281 #else
282 return -1;
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 */