1 // Defines the Internet domain address family address format.
3 #include "ace/ATM_Addr.h"
4 #if defined (ACE_HAS_ATM)
6 #include "ace/Log_Category.h"
8 #if defined (ACE_HAS_FORE_ATM_WS2)
9 #include /**/ "forews2.h"
10 #endif /* ACE_HAS_FORE_ATM_WS2 */
12 #if !defined (__ACE_INLINE__)
13 #include "ace/ATM_Addr.inl"
14 #endif /* __ACE_INLINE__ */
16 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
18 ACE_ALLOC_HOOK_DEFINE(ACE_ATM_Addr
)
20 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2)
21 #define BHLI_MAGIC "FORE_ATM"
22 // This is line rate in cells/s for an OC-3 MM interface.
23 const long ACE_ATM_Addr::LINE_RATE
= 353207;
24 const int ACE_ATM_Addr::OPT_FLAGS_CPID
= 0x1;
25 const int ACE_ATM_Addr::OPT_FLAGS_PMP
= 0x2;
26 const int ACE_ATM_Addr::DEFAULT_SELECTOR
= 0x99;
27 #elif defined (ACE_HAS_LINUX_ATM)
29 //pbrandao:for now stick with current definitions
30 //pbrandao:see if later need to change
31 const long ACE_ATM_Addr::LINE_RATE
= 353207;
32 const int ACE_ATM_Addr::OPT_FLAGS_CPID
= 0;
33 const int ACE_ATM_Addr::OPT_FLAGS_PMP
= 0;
34 const int ACE_ATM_Addr::DEFAULT_SELECTOR
= 0x99;
36 const long ACE_ATM_Addr::LINE_RATE
= 0L;
37 const int ACE_ATM_Addr::OPT_FLAGS_CPID
= 0;
38 const int ACE_ATM_Addr::OPT_FLAGS_PMP
= 0;
39 const int ACE_ATM_Addr::DEFAULT_SELECTOR
= 0x0;
40 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
42 // Default constructor
44 ACE_ATM_Addr::ACE_ATM_Addr (u_char selector
)
45 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2)
47 #elif defined (ACE_HAS_LINUX_ATM)
48 : ACE_Addr (PF_ATMSVC
,
50 : ACE_Addr (AF_UNSPEC
,
51 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
52 sizeof this->atm_addr_
)
54 // ACE_TRACE ("ACE_ATM_Addr::ACE_ATM_Addr");
55 (void) ACE_OS::memset ((void *) &this->atm_addr_
,
57 sizeof this->atm_addr_
);
58 this->init (selector
);
63 ACE_ATM_Addr::ACE_ATM_Addr (const ACE_ATM_Addr
&sap
,
65 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2)
67 #elif defined (ACE_HAS_LINUX_ATM)
68 : ACE_Addr (PF_ATMSVC
,
70 : ACE_Addr (AF_UNSPEC
,
71 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
72 sizeof this->atm_addr_
)
74 ACE_TRACE ("ACE_ATM_Addr::ACE_ATM_Addr");
75 this->set (sap
, selector
);
76 #if defined (ACE_HAS_LINUX_ATM)
77 this->atm_addr_
.sockaddratmsvc
.sas_family
= PF_ATMSVC
;
78 this->atm_addr_
.atmsap
.blli
[0].l3_proto
= ATM_L3_NONE
;
79 this->atm_addr_
.atmsap
.blli
[0].l2_proto
= ATM_L2_NONE
;
80 this->atm_addr_
.atmsap
.bhli
.hl_type
= ATM_HL_NONE
;
81 #endif /* ACE_HAS_LINUX_ATM */
84 ACE_ATM_Addr::ACE_ATM_Addr (const ATM_Addr
*sap
,
86 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2)
88 #elif defined (ACE_HAS_LINUX_ATM)
89 : ACE_Addr (PF_ATMSVC
,
91 : ACE_Addr (AF_UNSPEC
,
92 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
93 sizeof this->atm_addr_
)
95 ACE_TRACE ("ACE_ATM_Addr::ACE_ATM_Addr");
96 this->set (sap
, selector
);
100 ACE_ATM_Addr::ACE_ATM_Addr (const ACE_TCHAR sap
[],
102 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2)
104 #elif defined (ACE_HAS_LINUX_ATM)
105 : ACE_Addr (PF_ATMSVC
,
107 : ACE_Addr (AF_UNSPEC
,
108 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
109 sizeof this->atm_addr_
)
111 ACE_TRACE ("ACE_ATM_Addr::ACE_ATM_Addr");
112 this->set (sap
, selector
);
115 // Return the address.
117 ACE_ATM_Addr::get_addr () const
119 ACE_TRACE ("ACE_ATM_Addr::get_addr");
120 return (void *) &this->atm_addr_
;
124 ACE_ATM_Addr::init (u_char selector
)
126 #if defined (ACE_HAS_FORE_ATM_XTI)
127 // Note: this approach may be FORE implementation-specific. When we
128 // bind with tag_addr ABSENT and tag_selector PRESENT, only the
129 // selector (i.e. address[19]) is used by the TP. The rest of the
130 // local address is filled in by the TP and can be obtained via the
131 // 'ret' parameter or with t_getname ()/t_getprotaddr ().
133 atm_addr_
.addressType
= (u_int16_t
) AF_ATM
;
135 atm_addr_
.sap
.t_atm_sap_addr
.SVE_tag_addr
= (int8_t) T_ATM_ABSENT
;
136 atm_addr_
.sap
.t_atm_sap_addr
.SVE_tag_selector
= (int8_t) T_ATM_PRESENT
;
138 atm_addr_
.sap
.t_atm_sap_addr
.address_format
= (u_int8_t
) T_ATM_ENDSYS_ADDR
;
139 atm_addr_
.sap
.t_atm_sap_addr
.address_length
= ATMNSAP_ADDR_LEN
;
140 atm_addr_
.sap
.t_atm_sap_addr
.address
[ATMNSAP_ADDR_LEN
- 1] = selector
;
142 atm_addr_
.sap
.t_atm_sap_layer2
.SVE_tag
= (int8_t) T_ATM_ABSENT
;
143 atm_addr_
.sap
.t_atm_sap_layer3
.SVE_tag
= (int8_t) T_ATM_ABSENT
;
145 atm_addr_
.sap
.t_atm_sap_appl
.SVE_tag
= (int8_t) T_ATM_PRESENT
;
146 atm_addr_
.sap
.t_atm_sap_appl
.ID_type
= (u_int8_t
) T_ATM_USER_APP_ID
;
148 ACE_OS::memcpy (atm_addr_
.sap
.t_atm_sap_appl
.ID
.user_defined_ID
,
150 sizeof atm_addr_
.sap
.t_atm_sap_appl
.ID
);
151 #elif defined (ACE_HAS_FORE_ATM_WS2)
152 ACE_OS::memset ((void *)&atm_addr_
, 0, sizeof atm_addr_
);
153 atm_addr_
.satm_number
.Addr
[ ATM_ADDR_SIZE
- 1 ] = (char)selector
;
154 atm_addr_
.satm_family
= AF_ATM
;
155 atm_addr_
.satm_number
.AddressType
= ATM_NSAP
;
156 atm_addr_
.satm_number
.NumofDigits
= ATM_ADDR_SIZE
;
157 atm_addr_
.satm_blli
.Layer2Protocol
= SAP_FIELD_ABSENT
;
158 atm_addr_
.satm_blli
.Layer3Protocol
= SAP_FIELD_ABSENT
;
159 atm_addr_
.satm_bhli
.HighLayerInfoType
= SAP_FIELD_ABSENT
;
161 // Need to know the correspondence.
162 //atm_addr_.sap.t_atm_sap_appl.SVE_tag = (int8_t) T_ATM_PRESENT;
163 //atm_addr_.sap.t_atm_sap_appl.ID_type = (u_int8_t) T_ATM_USER_APP_ID;
164 //ACE_OS::memcpy (atm_addr_.sap.t_atm_sap_appl.ID.user_defined_ID,
166 // sizeof atm_addr_.sap.t_atm_sap_appl.ID);
167 #elif defined (ACE_HAS_LINUX_ATM)
168 atm_addr_
.sockaddratmsvc
.sas_family
= AF_ATMSVC
;
169 atm_addr_
.sockaddratmsvc
.sas_addr
.prv
[ATM_ESA_LEN
- 1] = (char)selector
;
170 atm_addr_
.atmsap
.blli
[0].l3_proto
= ATM_L3_NONE
;
171 atm_addr_
.atmsap
.blli
[0].l2_proto
= ATM_L2_NONE
;
172 atm_addr_
.atmsap
.bhli
.hl_type
= ATM_HL_NONE
;
174 ACE_UNUSED_ARG (selector
);
175 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
179 ACE_ATM_Addr::set (const ACE_ATM_Addr
&sap
,
182 ACE_TRACE ("ACE_ATM_Addr::set");
184 this->init (selector
);
186 this->ACE_Addr::base_set (sap
.get_type (),
189 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2)
190 ACE_ASSERT (sap
.get_type () == AF_ATM
);
191 #elif defined (ACE_HAS_LINUX_ATM)
192 ACE_ASSERT (sap
.get_type () == PF_ATMSVC
);
193 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 */
195 (void) ACE_OS::memcpy ((void *) &this->atm_addr_
,
196 (void *) &sap
.atm_addr_
,
197 sizeof this->atm_addr_
);
202 ACE_ATM_Addr::set (const ATM_Addr
*sap
,
205 ACE_TRACE ("ACE_ATM_Addr::set");
207 this->init (selector
);
209 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2)
210 this->ACE_Addr::base_set (AF_ATM
,
211 #elif defined (ACE_HAS_LINUX_ATM)
212 this->ACE_Addr::base_set (PF_ATMSVC
,
214 this->ACE_Addr::base_set (AF_UNSPEC
,
215 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 */
218 (void) ACE_OS::memcpy ((void *) &this->atm_addr_
,
220 sizeof this->atm_addr_
);
225 ACE_ATM_Addr::set (const ACE_TCHAR address
[],
228 ACE_TRACE ("ACE_ATM_Addr::set");
231 this->init (selector
);
233 #if defined (ACE_HAS_FORE_ATM_XTI)
234 atm_addr_
.sap
.t_atm_sap_addr
.SVE_tag_addr
=
235 (int8_t) T_ATM_PRESENT
;
236 #endif /* ACE_HAS_FORE_ATM_XTI */
238 ret
= this -> string_to_addr (address
);
239 this -> set_selector (selector
);
243 // Transform the string into the current addressing format.
246 ACE_ATM_Addr::string_to_addr (const ACE_TCHAR sap
[])
248 ACE_TRACE ("ACE_ATM_Addr::string_to_addr");
250 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2)
251 this->ACE_Addr::base_set (AF_ATM
,
252 #elif defined (ACE_HAS_LINUX_ATM)
253 this->ACE_Addr::base_set (PF_ATMSVC
,
255 this->ACE_Addr::base_set (AF_UNSPEC
,
256 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
257 sizeof this->atm_addr_
);
258 #if defined (ACE_HAS_FORE_ATM_XTI)
259 struct hostent
*entry
;
260 struct atmnsap_addr
*nsap
;
262 // Yow, someone gave us a NULL ATM address!
268 else if ((entry
= gethostbyname_atmnsap ((ACE_TCHAR
*)sap
)) != 0)
270 ACE_OS::memcpy (atm_addr_
.sap
.t_atm_sap_addr
.address
,
271 entry
->h_addr_list
[0],
272 ATMNSAP_ADDR_LEN
- 1);
274 else if ((nsap
= atmnsap_addr (sap
)) != 0)
276 ACE_OS::memcpy (atm_addr_
.sap
.t_atm_sap_addr
.address
,
284 #elif defined (ACE_HAS_FORE_ATM_WS2)
287 WSAQUERYSETW qsRestrictions
;
288 CSADDR_INFO csaBuffer
;
291 MultiByteToWideChar (CP_ACP
, MB_PRECOMPOSED
, sap
, -1, tmpWStr
, 100);
293 csaBuffer
.LocalAddr
.iSockaddrLength
= sizeof (struct sockaddr_atm
);
294 csaBuffer
.LocalAddr
.lpSockaddr
= (struct sockaddr
*)&atm_addr_
;
295 csaBuffer
.RemoteAddr
.iSockaddrLength
= sizeof (struct sockaddr_atm
);
296 csaBuffer
.RemoteAddr
.lpSockaddr
= (struct sockaddr
*)&atm_addr_
;
298 qsRestrictions
.dwSize
= sizeof (WSAQUERYSETW
);
299 qsRestrictions
.lpszServiceInstanceName
= 0;
300 qsRestrictions
.lpServiceClassId
= &FORE_NAME_CLASS
;
301 qsRestrictions
.lpVersion
= 0;
302 qsRestrictions
.lpszComment
= 0;
303 qsRestrictions
.dwNameSpace
= FORE_NAME_SPACE
;
304 qsRestrictions
.lpNSProviderId
= 0;
305 qsRestrictions
.lpszContext
= L
"";
306 qsRestrictions
.dwNumberOfProtocols
= 0;
307 qsRestrictions
.lpafpProtocols
= 0;
308 qsRestrictions
.lpszQueryString
= tmpWStr
;
309 qsRestrictions
.dwNumberOfCsAddrs
= 1;
310 qsRestrictions
.lpcsaBuffer
= &csaBuffer
;
311 qsRestrictions
.lpBlob
= 0; //&blob;
313 if (::WSALookupServiceBeginW (&qsRestrictions
, LUP_RETURN_ALL
, &hLookup
)
315 ACE_OS::printf ("Error: WSALookupServiceBeginW failed! %d\n",
316 ::WSAGetLastError ());
320 dwValue
= sizeof (WSAQUERYSETW
);
322 if (::WSALookupServiceNextW (hLookup
, 0, &dwValue
, &qsRestrictions
)
324 if (WSAGetLastError () != WSA_E_NO_MORE
) {
325 ACE_OS::printf ("Error: WSALookupServiceNextW failed! %d\n",
326 ::WSAGetLastError ());
331 if (WSALookupServiceEnd (hLookup
) == SOCKET_ERROR
) {
332 ACE_OS::printf ("Error : WSALookupServiceEnd failed! %d\n",
333 ::WSAGetLastError ());
337 #elif defined (ACE_HAS_LINUX_ATM)
338 if (sap
== 0 || !ACE_OS::strcmp (sap
,"")) {
343 if (text2atm ((ACE_TCHAR
*)sap
,
344 (struct sockaddr
*)& (atm_addr_
.sockaddratmsvc
),
345 sizeof (atm_addr_
.sockaddratmsvc
),
346 T2A_SVC
| T2A_NAME
) < 0) {
347 ACELIB_DEBUG (LM_DEBUG
,
348 "Error : text2atm failed!\n");
353 ACE_UNUSED_ARG (sap
);
356 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
358 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2) || defined (ACE_HAS_LINUX_ATM)
360 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 */
363 // Transform the current address into string format.
366 ACE_ATM_Addr::addr_to_string (ACE_TCHAR addr
[],
367 size_t addrlen
) const
369 ACE_TRACE ("ACE_ATM_Addr::addr_to_string");
371 #if defined (ACE_HAS_FORE_ATM_XTI)
372 ACE_TCHAR buffer
[MAXNAMELEN
+ 1];
373 struct atmnsap_addr nsap
;
374 ACE_OS::memcpy (nsap
.atmnsap
,
375 atm_addr_
.sap
.t_atm_sap_addr
.address
,
377 ACE_OS::sprintf (buffer
,
379 atmnsap_ntoa (nsap
));
381 size_t total_len
= ACE_OS::strlen (buffer
) + sizeof ('\0');
383 if (addrlen
< total_len
)
386 ACE_OS::strcpy (addr
, buffer
);
389 #elif defined (ACE_HAS_FORE_ATM_WS2)
390 ACE_TCHAR buffer
[MAXNAMELEN
+ 1];
393 if (addrlen
< ATM_ADDR_SIZE
+ 1)
396 for (i
= 0; i
< ATM_ADDR_SIZE
; i
++) {
397 buffer
[ i
* 3 ] = '\0';
398 ACE_OS::sprintf (buffer
, ACE_TEXT ("%s%02x."),
400 atm_addr_
.satm_number
.Addr
[ i
]);
403 buffer
[ ATM_ADDR_SIZE
* 3 - 1 ] = '\0';
404 ACE_OS::strcpy (addr
, buffer
);
407 #elif defined (ACE_HAS_LINUX_ATM)
408 ACE_TCHAR buffer
[MAX_ATM_ADDR_LEN
+ 1];
410 if ((total_len
= atm2text (buffer
,
412 (struct sockaddr
*)& (atm_addr_
.sockaddratmsvc
),
414 ACELIB_DEBUG ((LM_DEBUG
,"ACE_ATM_Addr (addr_to_string): atm2text failed\n"));
417 if (addrlen
< (size_t)total_len
)
420 ACE_OS::strcpy (addr
,
425 ACE_UNUSED_ARG (addr
);
426 ACE_UNUSED_ARG (addrlen
);
428 #endif /* ACE_HAS_FORE_ATM_XTI && ACE_HAS_FORE_ATM_WS2 */
432 ACE_ATM_Addr::addr_to_string () const
434 ACE_TRACE ("ACE_ATM_Addr::addr_to_string");
436 static ACE_TCHAR addr
[MAXHOSTNAMELEN
+ 1];
437 if (this->addr_to_string (addr
,
438 MAXHOSTNAMELEN
+ 1) < 0)
444 // Set a pointer to the address.
446 ACE_ATM_Addr::set_addr (const void *addr
, int len
)
448 ACE_TRACE ("ACE_ATM_Addr::set_addr");
450 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2)
451 this->ACE_Addr::base_set (AF_ATM
,
452 #elif defined (ACE_HAS_LINUX_ATM)
453 this->ACE_Addr::base_set (PF_ATMSVC
,
455 this->ACE_Addr::base_set (AF_UNSPEC
,
456 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_WS2 */
458 ACE_OS::memcpy (&this->atm_addr_
, addr
, len
);
461 // Compare two addresses for inequality.
464 ACE_ATM_Addr::operator != (const ACE_ATM_Addr
&sap
) const
466 ACE_TRACE ("ACE_ATM_Addr::operator !=");
467 return ! ((*this) == sap
);
470 // Compare two addresses for equality.
473 ACE_ATM_Addr::operator == (const ACE_ATM_Addr
&sap
) const
475 ACE_TRACE ("ACE_ATM_Addr::operator ==");
477 #if defined (ACE_HAS_LINUX_ATM)
478 return (atm_equal ((const struct sockaddr
*)& (this->atm_addr_
.sockaddratmsvc
),
479 (const struct sockaddr
*)& (sap
.atm_addr_
.sockaddratmsvc
),
483 sap_equal (& (this->atm_addr_
.atmsap
),
484 & (sap
.atm_addr_
.atmsap
),
487 return ACE_OS::memcmp (&atm_addr_
,
489 sizeof (ATM_Addr
)) == 0;
490 #endif /* ACE_HAS_LINUX_ATM */
494 ACE_ATM_Addr::dump () const
496 #if defined (ACE_HAS_DUMP)
497 ACE_TRACE ("ACE_ATM_Addr::dump");
499 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
501 ACE_TCHAR s
[ACE_MAX_FULLY_QUALIFIED_NAME_LEN
+ 16];
504 this->addr_to_string ());
505 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("%s"), s
));
506 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
507 #endif /* ACE_HAS_DUMP */
510 ACE_END_VERSIONED_NAMESPACE_DECL
512 #endif /* ACE_HAS_ATM */