#include <INET_Addr.h>
Inheritance diagram for ACE_INET_Addr:


Public Methods | |
| ACE_INET_Addr (void) | |
| Default constructor. More... | |
| ACE_INET_Addr (const ACE_INET_Addr &) | |
| Copy constructor. More... | |
| ACE_INET_Addr (const sockaddr_in *, int len) | |
| Creates an <ACE_INET_Addr> from a sockaddr_in structure. More... | |
| ACE_INET_Addr (u_short port_number, const char host_name[], int address_family=AF_UNSPEC) | |
Creates an <ACE_INET_Addr> from a <port_number> and the remote <host_name>. The port number is assumed to be in host byte order. To set a port already in network byte order, please
| |
| ACE_EXPLICIT | ACE_INET_Addr (const char address[]) |
| ACE_INET_Addr (u_short port_number, ACE_UINT32 ip_addr=INADDR_ANY) | |
| ACE_INET_Addr (const char port_name[], const char host_name[], const char protocol[]="tcp") | |
| Uses <getservbyname> to create an <ACE_INET_Addr> from a <port_name>, the remote <host_name>, and the <protocol>. More... | |
| ACE_INET_Addr (const char port_name[], ACE_UINT32 ip_addr, const char protocol[]="tcp") | |
| ACE_INET_Addr (u_short port_number, const wchar_t host_name[], int address_family=AF_UNSPEC) | |
| ACE_EXPLICIT | ACE_INET_Addr (const wchar_t address[]) |
| ACE_INET_Addr (const wchar_t port_name[], const wchar_t host_name[], const wchar_t protocol[]=ACE_TEXT_WIDE("tcp")) | |
| ACE_INET_Addr (const wchar_t port_name[], ACE_UINT32 ip_addr, const wchar_t protocol[]=ACE_TEXT_WIDE("tcp")) | |
| ~ACE_INET_Addr (void) | |
| Default dtor. More... | |
| int | set (const ACE_INET_Addr &) |
| Initializes from another <ACE_INET_Addr>. More... | |
| int | set (u_short port_number, const char host_name[], int encode=1, int address_family=AF_UNSPEC) |
| int | set (u_short port_number, ACE_UINT32 ip_addr=INADDR_ANY, int encode=1) |
| int | set (const char port_name[], const char host_name[], const char protocol[]="tcp") |
| Uses <getservbyname> to initialize an <ACE_INET_Addr> from a <port_name>, the remote <host_name>, and the <protocol>. More... | |
| int | set (const char port_name[], ACE_UINT32 ip_addr, const char protocol[]="tcp") |
| int | set (const char addr[]) |
| int | set (const sockaddr_in *, int len) |
| Creates an <ACE_INET_Addr> from a sockaddr_in structure. More... | |
| int | set (u_short port_number, const wchar_t host_name[], int encode=1, int address_family=AF_UNSPEC) |
| int | set (const wchar_t port_name[], const wchar_t host_name[], const wchar_t protocol[]=ACE_TEXT_WIDE("tcp")) |
| int | set (const wchar_t port_name[], ACE_UINT32 ip_addr, const wchar_t protocol[]=ACE_TEXT_WIDE("tcp")) |
| int | set (const wchar_t addr[]) |
| virtual void * | get_addr (void) const |
| Return a pointer to the underlying network address. More... | |
| int | get_addr_size (void) const |
| virtual void | set_addr (void *, int len) |
| Set a pointer to the address. More... | |
| virtual int | addr_to_string (ACE_TCHAR buffer[], size_t size, int ipaddr_format=1) const |
| virtual int | string_to_addr (const char address[]) |
| void | set_port_number (u_short, int encode=1) |
| int | set_address (const char *ip_addr, int len, int encode=1) |
| u_short | get_port_number (void) const |
| Return the port number, converting it into host byte-order. More... | |
| int | get_host_name (char hostname[], size_t hostnamelen) const |
| int | get_host_name (wchar_t hostname[], size_t hostnamelen) const |
| const char * | get_host_name (void) const |
| const char * | get_host_addr (void) const |
| Return the "dotted decimal" Internet address. More... | |
| const char * | get_host_addr (char *dst, int size) const |
| ACE_UINT32 | get_ip_address (void) const |
| Return the 4-byte IP address, converting it into host byte order. More... | |
| int | operator< (const ACE_INET_Addr &rhs) const |
| int | operator== (const ACE_INET_Addr &SAP) const |
| Compare two addresses for equality. The addresses are considered equal if they contain the same IP address and port number. More... | |
| int | operator!= (const ACE_INET_Addr &SAP) const |
| Compare two addresses for inequality. More... | |
| virtual u_long | hash (void) const |
| Computes and returns hash value. More... | |
| void | dump (void) const |
| Dump the state of an object. More... | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Private Methods | |
| int | get_host_name_i (char hostname[], size_t hostnamelen) const |
| Insure that hostname is properly null-terminated. More... | |
| void * | ip_addr_pointer (void) const |
| int | ip_addr_size (void) const |
| int | determine_type (void) const |
| void | reset (void) |
| Initialize underlying inet_addr_ to default values. More... | |
Private Attributes | |
| union { | |
| sockaddr_in in4_ | |
| } | inet_addr_ |
| Underlying representation. This union uses the knowledge that the two structures share the first member, sa_family (as all sockaddr structures do). More... | |
Definition at line 35 of file INET_Addr.h.
|
|
Default constructor.
Definition at line 96 of file INET_Addr.cpp. References reset.
|
|
|
Copy constructor.
Definition at line 189 of file INET_Addr.cpp. References ACE_TRACE, reset, and set.
|
|
||||||||||||
|
Creates an <ACE_INET_Addr> from a sockaddr_in structure.
Definition at line 484 of file INET_Addr.cpp. References ACE_TRACE, reset, and set.
|
|
||||||||||||||||
|
Creates an <ACE_INET_Addr> from a <port_number> and the remote <host_name>. The port number is assumed to be in host byte order. To set a port already in network byte order, please
Definition at line 376 of file INET_Addr.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TEXT_CHAR_TO_TCHAR, ACE_TRACE, LM_ERROR, ACE_OS_String::memset, and set.
00379 : ACE_Addr (this->determine_type(), sizeof (inet_addr_)) 00380 { 00381 ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); 00382 ACE_OS::memset (&this->inet_addr_, 0, sizeof (this->inet_addr_)); 00383 if (this->set (port_number, 00384 host_name, 00385 1, 00386 address_family) == -1) 00387 #if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) 00388 ACE_ERROR ((LM_ERROR, 00389 (char *)"ACE_INET_Addr::ACE_INET_Addr: %p\n", 00390 (((char *) host_name == 0) ? 00391 ((char *) "<unknown>") : 00392 ((char *) (host_name))))); 00393 #else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ 00394 ACE_ERROR ((LM_ERROR, 00395 ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr: %p\n"), 00396 ACE_TEXT_CHAR_TO_TCHAR ((host_name == 0) ? 00397 "<unknown>" : host_name))); 00398 #endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ 00399 } |
|
|
Initializes an <ACE_INET_Addr> from the <address>, which can be "ip-number:port-number" (e.g., "tango.cs.wustl.edu:1234" or "128.252.166.57:1234"). If there is no ':' in the <address> it is assumed to be a port number, with the IP address being INADDR_ANY. Definition at line 168 of file INET_Addr.cpp. References ACE_TRACE, reset, and set.
|
|
||||||||||||
|
Creates an <ACE_INET_Addr> from a <port_number> and an Internet <ip_addr>. This method assumes that <port_number> and <ip_addr> are in host byte order. If you have addressing information in network byte order,
Definition at line 495 of file INET_Addr.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, reset, and set.
00497 : ACE_Addr (this->determine_type(), sizeof (inet_addr_)) 00498 { 00499 ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); 00500 this->reset(); 00501 if (this->set (port_number, inet_address) == -1) 00502 ACE_ERROR ((LM_ERROR, 00503 ACE_LIB_TEXT ("%p\n"), 00504 ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr"))); 00505 } |
|
||||||||||||||||
|
Uses <getservbyname> to create an <ACE_INET_Addr> from a <port_name>, the remote <host_name>, and the <protocol>.
Definition at line 510 of file INET_Addr.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, reset, and set.
00513 : ACE_Addr (this->determine_type(), sizeof (inet_addr_)) 00514 { 00515 ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); 00516 this->reset(); 00517 if (this->set (port_name, 00518 host_name, 00519 protocol) == -1) 00520 ACE_ERROR ((LM_ERROR, 00521 ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr"))); 00522 } |
|
||||||||||||||||
|
Uses <getservbyname> to create an <ACE_INET_Addr> from a <port_name>, an Internet <ip_addr>, and the <protocol>. This method assumes that <ip_addr> is in host byte order. Definition at line 543 of file INET_Addr.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, reset, and set.
00546 : ACE_Addr (this->determine_type(), sizeof (inet_addr_)) 00547 { 00548 ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); 00549 this->reset(); 00550 if (this->set (port_name, 00551 inet_address, 00552 protocol) == -1) 00553 ACE_ERROR ((LM_ERROR, 00554 ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr"))); 00555 } |
|
||||||||||||||||
|
Definition at line 402 of file INET_Addr.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TEXT_WCHAR_TO_TCHAR, ACE_TEXT_WIDE, ACE_TRACE, LM_ERROR, ACE_OS_String::memset, and set.
00405 : ACE_Addr (this->determine_type(), sizeof (inet_addr_)) 00406 { 00407 ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); 00408 ACE_OS::memset (&this->inet_addr_, 0, sizeof (this->inet_addr_)); 00409 if (this->set (port_number, 00410 host_name, 00411 1, 00412 address_family) == -1) 00413 #if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) 00414 ACE_ERROR ((LM_ERROR, 00415 (char *)"ACE_INET_Addr::ACE_INET_Addr: %p\n", 00416 (((char *) host_name == 0) ? 00417 ((char *) "<unknown>") : 00418 ((char *) (host_name))))); 00419 #else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ 00420 ACE_ERROR ((LM_ERROR, 00421 ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr: %p\n"), 00422 ACE_TEXT_WCHAR_TO_TCHAR ((host_name == 0) ? 00423 ACE_TEXT_WIDE ("<unknown>") : 00424 host_name))); 00425 #endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ 00426 } |
|
|
Definition at line 177 of file INET_Addr.cpp. References ACE_TRACE, reset, and set.
|
|
||||||||||||||||
|
Definition at line 525 of file INET_Addr.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, reset, and set.
00528 : ACE_Addr (this->determine_type(), sizeof (inet_addr_)) 00529 { 00530 ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); 00531 this->reset(); 00532 if (this->set (port_name, 00533 host_name, 00534 protocol) == -1) 00535 ACE_ERROR ((LM_ERROR, 00536 ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr"))); 00537 } |
|
||||||||||||||||
|
Definition at line 558 of file INET_Addr.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, reset, and set.
00561 : ACE_Addr (this->determine_type(), sizeof (inet_addr_)) 00562 { 00563 ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); 00564 this->reset(); 00565 if (this->set (port_name, 00566 inet_address, 00567 protocol) == -1) 00568 ACE_ERROR ((LM_ERROR, 00569 ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr"))); 00570 } |
|
|
Default dtor.
Definition at line 8 of file INET_Addr.i.
00009 {
00010 }
|
|
||||||||||||||||
|
Transform the current <ACE_INET_Addr> address into string format. If <ipaddr_format> is non-0 this produces "ip-number:port-number" (e.g., "128.252.166.57:1234"), whereas if <ipaddr_format> is 0 this produces "ip-name:port-number" (e.g., "tango.cs.wustl.edu:1234"). Returns -1 if the <size> of the <buffer> is too small, else 0. Definition at line 22 of file INET_Addr.cpp. References ACE_LIB_TEXT, ACE_TCHAR, ACE_TEXT_CHAR_TO_TCHAR, ACE_TRACE, get_host_addr, get_port_number, ACE_OS::sprintf, and ACE_OS_String::strlen. Referenced by ACE_MEM_Addr::addr_to_string, dump, and ACE_Asynch_Connector::parse_address.
00025 {
00026 ACE_TRACE ("ACE_INET_Addr::addr_to_string");
00027
00028 // XXX Can we (should we) include the scope id for IPv6 addresses?
00029
00030 size_t total_len = (ipaddr_format == 0 ?
00031 ACE_OS::strlen (this->get_host_name ()) :
00032 ACE_OS::strlen (this->get_host_addr ()))
00033 + ACE_OS::strlen ("65536") // Assume the max port number.
00034 + sizeof (':')
00035 #if defined ACE_HAS_IPV6
00036 + ACE_OS::strlen ("[]")
00037 #endif
00038 + sizeof ('\0'); // For trailing '\0'.
00039
00040 if (size < total_len)
00041 return -1;
00042 else
00043 {
00044 ACE_OS::sprintf (s,
00045 #if defined ACE_HAS_IPV6
00046 ACE_LIB_TEXT ("[%s]:%d"),
00047 #else
00048 ACE_LIB_TEXT ("%s:%d"),
00049 #endif
00050 ACE_TEXT_CHAR_TO_TCHAR (ipaddr_format == 0
00051 ? this->get_host_name ()
00052 : this->get_host_addr ()),
00053 this->get_port_number ());
00054 return 0;
00055 }
00056 }
|
|
|
Definition at line 27 of file INET_Addr.i. References ACE_Sock_Connect::ipv6_enabled.
00028 {
00029 #if defined (ACE_HAS_IPV6)
00030 # if defined (ACE_USES_IPV4_IPV6_MIGRATION)
00031 return ACE_Sock_Connect::ipv6_enabled () ? AF_INET6 : AF_INET;
00032 # else
00033 return AF_INET6;
00034 # endif /* ACE_USES_IPV4_IPV6_MIGRATION */
00035 #endif /* ACE_HAS_IPV6 */
00036 return AF_INET;
00037 }
|
|
|
Dump the state of an object.
Reimplemented from ACE_Addr. Definition at line 59 of file INET_Addr.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_MAX_FULLY_QUALIFIED_NAME_LEN, ACE_TCHAR, ACE_TRACE, addr_to_string, and LM_DEBUG. Referenced by ACE_TSS_Connection::dump, and ACE_MEM_Addr::dump.
00060 {
00061 ACE_TRACE ("ACE_INET_Addr::dump");
00062
00063 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00064
00065 ACE_TCHAR s[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 16];
00066 this->addr_to_string(s, ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 16);
00067 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("%s"), s));
00068 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00069 }
|
|
|
Return a pointer to the underlying network address.
Reimplemented from ACE_Addr. Definition at line 95 of file INET_Addr.i. References ACE_TRACE, and inet_addr_. Referenced by ACE_Sock_Connect::bind_port, ACE_MEM_Addr::get_addr, and ACE_Asynch_Acceptor::open.
00096 {
00097 ACE_TRACE ("ACE_INET_Addr::get_addr");
00098 return (void*)&this->inet_addr_;
00099 }
|
|
|
Definition at line 102 of file INET_Addr.i. References ACE_TRACE, ACE_Addr::get_type, and inet_addr_.
00103 {
00104 ACE_TRACE ("ACE_INET_Addr::get_addr_size");
00105 #if defined (ACE_HAS_IPV6)
00106 if (this->get_type () == PF_INET)
00107 return sizeof this->inet_addr_.in4_;
00108 else
00109 return sizeof this->inet_addr_.in6_;
00110 #else
00111 return sizeof this->inet_addr_.in4_;
00112 #endif /* ACE_HAS_IPV6 */
00113 }
|
|
||||||||||||
|
Definition at line 850 of file INET_Addr.cpp. References ACE_HTONL, get_ip_address, ACE_Addr::get_type, ACE_OS::inet_ntoa, ACE_OS::inet_ntop, and ACE_OS_String::strsncpy.
00851 {
00852 #if defined (ACE_HAS_IPV6)
00853 if (this->get_type () == AF_INET6)
00854 {
00855 if (IN6_IS_ADDR_V4MAPPED (&this->inet_addr_.in6_.sin6_addr))
00856 {
00857 ACE_UINT32 addr;
00858 addr = this->get_ip_address();
00859 addr = ACE_HTONL (addr);
00860 return ACE_OS::inet_ntop (AF_INET, &addr, dst, size);
00861 }
00862
00863 const char *ch = ACE_OS::inet_ntop (AF_INET6,
00864 &this->inet_addr_.in6_.sin6_addr,
00865 dst,
00866 size);
00867 return ch;
00868 }
00869 #endif /* ACE_HAS_IPV6 */
00870
00871 #if defined (VXWORKS)
00872 // It would be nice to be able to encapsulate this into
00873 // ACE_OS::inet_ntoa(), but that would lead to either inefficiencies
00874 // on vxworks or lack of thread safety.
00875 //
00876 // So, we use the way that vxworks suggests.
00877 ACE_INET_Addr *ncthis = ACE_const_cast (ACE_INET_Addr *, this);
00878 inet_ntoa_b (this->inet_addr_.in4_.sin_addr, ncthis->buf_);
00879 return &buf_[0];
00880 #else /* VXWORKS */
00881 char *ch = ACE_OS::inet_ntoa (this->inet_addr_.in4_.sin_addr);
00882 ACE_OS::strsncpy (dst, ch, size);
00883 return ch;
00884 #endif
00885 }
|
|
|
Return the "dotted decimal" Internet address.
Definition at line 889 of file INET_Addr.cpp. References ACE_TRACE, INET6_ADDRSTRLEN, and ACE_OS::inet_ntoa. Referenced by addr_to_string, and ACE_MEM_Addr::get_host_addr.
00890 {
00891 ACE_TRACE ("ACE_INET_Addr::get_host_addr");
00892 #if defined (ACE_HAS_IPV6)
00893 static char buf[INET6_ADDRSTRLEN];
00894 return this->get_host_addr (buf, INET6_ADDRSTRLEN);
00895 #else
00896 return ACE_OS::inet_ntoa (this->inet_addr_.in4_.sin_addr);
00897 #endif
00898 }
|
|
|
Return the character representation of the hostname (this version is non-reentrant since it returns a pointer to a static data area). Definition at line 638 of file INET_Addr.cpp. References ACE_TRACE, MAXHOSTNAMELEN, and ACE_OS_String::strcpy. Referenced by get_host_name.
00639 {
00640 ACE_TRACE ("ACE_INET_Addr::get_host_name");
00641
00642 static char name[MAXHOSTNAMELEN + 1];
00643 if (this->get_host_name (name, MAXHOSTNAMELEN + 1) == -1)
00644 ACE_OS::strcpy (name, "<unknown>");
00645 return name;
00646 }
|
|
||||||||||||
|
Definition at line 612 of file INET_Addr.cpp. References ACE_TRACE, get_host_name, MAXHOSTNAMELEN, and ACE_OS_String::strcpy.
00614 {
00615 ACE_TRACE ("ACE_INET_Addr::get_host_name");
00616
00617 char char_hostname [MAXHOSTNAMELEN + 1];
00618
00619 // We have a build in limitation of MAXHOSTNAMELEN
00620 if (len > MAXHOSTNAMELEN + 1)
00621 len = MAXHOSTNAMELEN + 1;
00622
00623 // Call the char version
00624 int result = this->get_host_name (char_hostname, len);
00625
00626 // And copy it over, if successful
00627 if (result == 0)
00628 ACE_OS_String::strcpy (hostname,
00629 ACE_Ascii_To_Wide (char_hostname).wchar_rep ());
00630
00631 return result;
00632 }
|
|
||||||||||||
|
Return the character representation of the name of the host, storing it in the <hostname> (which is assumed to be <hostnamelen> bytes long). This version is reentrant. If <hostnamelen> is greater than 0 then <hostname> will be NUL-terminated even if -1 is returned. Definition at line 574 of file INET_Addr.cpp. References ACE_TRACE, and get_host_name_i. Referenced by ACE_MEM_Connector::connect, ACE_MEM_Addr::get_host_name, and ACE_Service_Manager::handle_input.
00576 {
00577 ACE_TRACE ("ACE_INET_Addr::get_host_name");
00578
00579 int result;
00580 if (len > 1)
00581 {
00582 result = get_host_name_i(hostname,len);
00583 if (result < 0)
00584 {
00585 if (result == -2)
00586 {
00587 result = -1;
00588 // We know that hostname is nul-terminated
00589 }
00590 else
00591 {
00592 //result == -1;
00593 // This could be worse than hostname[len -1] = '\0'?
00594 hostname[0] = '\0';
00595 }
00596 }
00597 }
00598 else
00599 {
00600 if (len == 1)
00601 {
00602 hostname[0] = '\0';
00603 }
00604 result = -1;
00605 }
00606
00607 return result;
00608 }
|
|
||||||||||||
|
Insure that hostname is properly null-terminated.
Definition at line 667 of file INET_Addr.cpp. References ACE_HOSTENT_DATA, ACE_TRACE, ACE_Addr::get_type, ACE_OS::gethostbyaddr, ACE_OS::gethostbyaddr_r, ACE_OS::hostname, inet_addr_, ip_addr_size, ACE_OS_String::memcmp, ACE_OS_String::memcpy, ACE_OS_String::strcpy, and ACE_OS_String::strlen. Referenced by get_host_name.
00668 {
00669 ACE_TRACE ("ACE_INET_Addr::get_host_name_i");
00670
00671 #if defined (ACE_HAS_IPV6)
00672 if ((this->get_type () == PF_INET6 &&
00673 0 == ACE_OS_String::memcmp (&this->inet_addr_.in6_.sin6_addr,
00674 &in6addr_any,
00675 sizeof (this->inet_addr_.in6_.sin6_addr)))
00676 ||
00677 (this->get_type () == PF_INET &&
00678 this->inet_addr_.in4_.sin_addr.s_addr == INADDR_ANY))
00679 #else
00680 if (this->inet_addr_.in4_.sin_addr.s_addr == INADDR_ANY)
00681 #endif /* ACE_HAS_IPV6 */
00682 {
00683 if (ACE_OS::hostname (hostname, len) == -1)
00684 return -1;
00685 else
00686 return 0;
00687 }
00688 else
00689 {
00690 #if defined (VXWORKS)
00691 ACE_UNUSED_ARG (len);
00692 int error =
00693 ::hostGetByAddr ((int) this->inet_addr_.in4_.sin_addr.s_addr,
00694 hostname);
00695 if (error == OK)
00696 return 0;
00697 else
00698 {
00699 errno = error;
00700 return -1;
00701 }
00702 #else
00703 # if defined (CHORUS) || (defined (DIGITAL_UNIX) && defined (__GNUC__))
00704 hostent *hp = ACE_OS::gethostbyaddr ((char *)this->ip_addr_pointer (),
00705 this->ip_addr_size (),
00706 this->get_type ());
00707 # else
00708 int h_error; // Not the same as errno!
00709 hostent hentry;
00710 ACE_HOSTENT_DATA buf;
00711 hostent *hp =
00712 ACE_OS::gethostbyaddr_r ((char *)this->ip_addr_pointer (),
00713 this->ip_addr_size (),
00714 this->get_type (),
00715 &hentry,
00716 buf,
00717 &h_error);
00718 # endif /* CHORUS */
00719
00720 if (hp == 0 || hp->h_name == 0)
00721 return -1;
00722
00723 if (ACE_OS::strlen (hp->h_name) >= len)
00724 {
00725 // We know the length, so use memcpy
00726 if (len > 0)
00727 {
00728 ACE_OS::memcpy (hostname, hp->h_name, len - 1);
00729 hostname[len-1]= '\0';
00730 }
00731 errno = ENOSPC;
00732 return -2; // -2 Means that we have a good string
00733 // Using errno looks ok, but ENOSPC could be set on
00734 // other places.
00735 }
00736
00737 ACE_OS::strcpy (hostname, hp->h_name);
00738 return 0;
00739 #endif /* VXWORKS */
00740 }
00741 }
|
|
|
Return the 4-byte IP address, converting it into host byte order.
Definition at line 903 of file INET_Addr.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_NTOHL, ACE_TRACE, EAFNOSUPPORT, ACE_Addr::get_type, ip_addr_pointer, LM_ERROR, and ACE_OS_String::memcpy. Referenced by get_host_addr, ACE_MEM_Addr::get_ip_address, hash, ACE_SOCK_Dgram_Mcast::join, ACE_SOCK_Dgram_Mcast::make_multicast_ifaddr, operator<, ACE_MEM_Addr::same_host, ACE_SOCK_Dgram::set_nic, ACE_SOCK_Dgram_Mcast::subscribe_ifs, and ACE_SOCK_Dgram_Mcast::unsubscribe_ifs.
00904 {
00905 ACE_TRACE ("ACE_INET_Addr::get_ip_address");
00906 #if defined (ACE_HAS_IPV6)
00907 if (this->get_type () == AF_INET6)
00908 {
00909 if (IN6_IS_ADDR_V4MAPPED (&this->inet_addr_.in6_.sin6_addr) ||
00910 IN6_IS_ADDR_V4COMPAT (&this->inet_addr_.in6_.sin6_addr) )
00911 {
00912 ACE_UINT32 addr;
00913 // Return the last 32 bits of the address
00914 char *thisaddrptr = (char*)this->ip_addr_pointer ();
00915 thisaddrptr += 128/8 - 32/8;
00916 ACE_OS_String::memcpy (&addr, thisaddrptr, sizeof (addr));
00917 return ACE_NTOHL (addr);
00918 }
00919
00920 ACE_ERROR ((LM_ERROR,
00921 ACE_LIB_TEXT ("ACE_INET_Addr::get_ip_address: address is a IPv6 address not IPv4\n")));
00922 errno = EAFNOSUPPORT;
00923 return 0;
00924 }
00925 #endif /* ACE_HAS_IPV6 */
00926 return ntohl (ACE_UINT32 (this->inet_addr_.in4_.sin_addr.s_addr));
00927 }
|
|
|
Return the port number, converting it into host byte-order.
Definition at line 79 of file INET_Addr.i. References ACE_TRACE, and ACE_Addr::get_type. Referenced by ACE_MEM_Acceptor::accept, addr_to_string, ACE_MEM_Connector::connect, ACE_MEM_Acceptor::get_local_addr, ACE_MEM_Addr::get_port_number, ACE_Service_Manager::handle_input, hash, ACE_Service_Manager::info, ACE_SOCK_Dgram_Mcast::join, ACE_SOCK_Dgram_Mcast::make_multicast_ifaddr, ACE_Pipe::open, ACE_SOCK_Dgram_Mcast::open_i, operator<, and ACE_SOCK_Dgram::set_nic.
00080 {
00081 ACE_TRACE ("ACE_INET_Addr::get_port_number");
00082 #if defined (ACE_HAS_IPV6)
00083 if (this->get_type () == PF_INET)
00084 return ntohs (this->inet_addr_.in4_.sin_port);
00085 else
00086 return ntohs (this->inet_addr_.in6_.sin6_port);
00087 #else
00088 return ntohs (this->inet_addr_.in4_.sin_port);
00089 #endif /* ACE_HAS_IPV6 */
00090 }
|
|
|
Computes and returns hash value.
Reimplemented from ACE_Addr. Definition at line 117 of file INET_Addr.i. References get_ip_address, get_port_number, ACE_Addr::get_type, and ip_addr_pointer. Referenced by ACE_MEM_Addr::hash.
00118 {
00119 #if defined (ACE_HAS_IPV6)
00120 if (this->get_type () == PF_INET6)
00121 {
00122 const unsigned int *addr = (const unsigned int*)this->ip_addr_pointer();
00123 return addr[0] + addr[1] + addr[2] + addr[3] + this->get_port_number();
00124 }
00125 else
00126 #endif /* ACE_HAS_IPV6 */
00127 return this->get_ip_address () + this->get_port_number ();
00128 }
|
|
|
Definition at line 40 of file INET_Addr.i. References ACE_Addr::get_type, and inet_addr_. Referenced by get_ip_address, and hash.
00041 {
00042 #if defined (ACE_HAS_IPV6)
00043 if (this->get_type () == PF_INET)
00044 return (void*)&this->inet_addr_.in4_.sin_addr;
00045 else
00046 return (void*)&this->inet_addr_.in6_.sin6_addr;
00047 #else
00048 return (void*)&this->inet_addr_.in4_.sin_addr;
00049 #endif
00050 }
|
|
|
Definition at line 53 of file INET_Addr.i. References ACE_Addr::get_type. Referenced by get_host_name_i.
00054 {
00055 // Since this size value is used to pass to other host db-type
00056 // functions (gethostbyaddr, etc.) the length is of int type.
00057 // Thus, cast all these sizes back to int. They're all well
00058 // within the range of an int anyway.
00059 #if defined (ACE_HAS_IPV6)
00060 if (this->get_type () == PF_INET)
00061 return ACE_static_cast (int, sizeof this->inet_addr_.in4_.sin_addr);
00062 else
00063 return ACE_static_cast (int, sizeof this->inet_addr_.in6_.sin6_addr);
00064 #else
00065 // These _UNICOS changes were picked up from pre-IPv6 code in
00066 // get_host_name_i... the IPv6 section above may need something
00067 // similar, so keep an eye out for it.
00068 # if !defined(_UNICOS)
00069 return ACE_static_cast (int, sizeof this->inet_addr_.in4_.sin_addr.s_addr);
00070 # else /* _UNICOS */
00071 return ACE_static_cast (int, sizeof this->inet_addr_.in4_.sin_addr);
00072 # endif /* ! _UNICOS */
00073 #endif /* ACE_HAS_IPV6 */
00074 }
|
|
|
Compare two addresses for inequality.
Definition at line 74 of file INET_Addr.cpp. References ACE_TRACE.
00075 {
00076 ACE_TRACE ("ACE_INET_Addr::operator !=");
00077 return !((*this) == sap);
00078 }
|
|
|
Returns true if <this> is less than <rhs>. In this context, "less than" is defined in terms of IP address and TCP port number. This operator makes it possible to use <ACE_INET_Addr>s in STL maps. Definition at line 131 of file INET_Addr.i. References get_ip_address, and get_port_number.
00132 {
00133 return this->get_ip_address () < rhs.get_ip_address ()
00134 || (this->get_ip_address () == rhs.get_ip_address ()
00135 && this->get_port_number () < rhs.get_port_number ());
00136 }
|
|
|
Compare two addresses for equality. The addresses are considered equal if they contain the same IP address and port number.
Definition at line 83 of file INET_Addr.cpp. References ACE_TRACE, ACE_Addr::get_size, ACE_Addr::get_type, inet_addr_, and ACE_OS_String::memcmp.
00084 {
00085 ACE_TRACE ("ACE_INET_Addr::operator ==");
00086
00087 if (this->get_type () != sap.get_type () ||
00088 this->get_size () != sap.get_size () )
00089 return 0;
00090
00091 return (ACE_OS::memcmp (&this->inet_addr_,
00092 &sap.inet_addr_,
00093 this->get_size ()) == 0);
00094 }
|
|
|
Initialize underlying inet_addr_ to default values.
Definition at line 13 of file INET_Addr.i. References ACE_Addr::get_type, inet_addr_, and ACE_OS_String::memset. Referenced by ACE_INET_Addr.
00014 {
00015 ACE_OS::memset(&this->inet_addr_, 0, sizeof(this->inet_addr_));
00016 if (this->get_type() == AF_INET) {
00017 this->inet_addr_.in4_.sin_family = AF_INET;
00018 }
00019 #if defined (ACE_HAS_IPV6)
00020 else if (this->get_type() == AF_INET6) {
00021 this->inet_addr_.in6_.sin6_family = AF_INET6;
00022 }
00023 #endif /* ACE_HAS_IPV6 */
00024 }
|
|
|
|
|
||||||||||||||||
|
|
|
||||||||||||||||
|
|
|
||||||||||||||||||||
|
|
|
||||||||||||
|
Creates an <ACE_INET_Addr> from a sockaddr_in structure.
Definition at line 432 of file INET_Addr.cpp. References ACE_TRACE, ACE_Addr::base_set, EAFNOSUPPORT, and ACE_OS_String::memcpy.
00433 {
00434 ACE_TRACE ("ACE_INET_Addr::set");
00435
00436 if (addr->sin_family == AF_INET)
00437 {
00438 ACE_OS::memcpy (&this->inet_addr_.in4_, addr, len);
00439 this->base_set (AF_INET, len);
00440 return 0;
00441 }
00442 #if defined (ACE_HAS_IPV6)
00443 else if (addr->sin_family == AF_INET6)
00444 {
00445 ACE_OS::memcpy (&this->inet_addr_.in6_, addr, len);
00446 this->base_set (AF_INET6, len);
00447 return 0;
00448 }
00449 #endif /* ACE_HAS_IPV6 */
00450
00451 errno = EAFNOSUPPORT;
00452 return -1;
00453 }
|
|
|
Initializes an <ACE_INET_Addr> from the <addr>, which can be "ip-number:port-number" (e.g., "tango.cs.wustl.edu:1234" or "128.252.166.57:1234"). If there is no ':' in the <address> it is assumed to be a port number, with the IP address being INADDR_ANY. Definition at line 162 of file INET_Addr.cpp. References ACE_TRACE, and string_to_addr.
00163 {
00164 ACE_TRACE ("ACE_INET_Addr::set");
00165 return this->string_to_addr (address);
00166 }
|
|
||||||||||||||||
|
Uses <getservbyname> to initialize an <ACE_INET_Addr> from a <port_name>, an <ip_addr>, and the <protocol>. This assumes that <ip_addr> is already in network byte order. Definition at line 346 of file INET_Addr.cpp. References ACE_SERVENT_DATA, ACE_TRACE, ACE_OS::getservbyname_r, and set.
00349 {
00350 ACE_TRACE ("ACE_INET_Addr::set");
00351
00352 #if defined (VXWORKS) || defined (CHORUS) || defined (ACE_LACKS_GETSERVBYNAME)
00353 ACE_UNUSED_ARG (port_name);
00354 ACE_UNUSED_ARG (inet_address);
00355 ACE_UNUSED_ARG (protocol);
00356 ACE_NOTSUP_RETURN (-1);
00357 #else
00358 servent sentry;
00359 ACE_SERVENT_DATA buf;
00360
00361 servent *sp = ACE_OS::getservbyname_r (port_name,
00362 protocol,
00363 &sentry,
00364 buf);
00365 if (sp == 0)
00366 return -1;
00367 else
00368 return this->set (sp->s_port, inet_address, 0);
00369 #endif /* VXWORKS */
00370 }
|
|
||||||||||||||||
|
Uses <getservbyname> to initialize an <ACE_INET_Addr> from a <port_name>, the remote <host_name>, and the <protocol>.
Definition at line 310 of file INET_Addr.cpp. References ACE_LIB_TEXT, ACE_SERVENT_DATA, ACE_TRACE, ACE_OS::getservbyname_r, set, and ACE_OS_String::strcmp.
00313 {
00314 ACE_TRACE ("ACE_INET_Addr::set");
00315
00316 #if defined (VXWORKS) || defined (CHORUS) || defined (ACE_LACKS_GETSERVBYNAME)
00317 ACE_UNUSED_ARG (port_name);
00318 ACE_UNUSED_ARG (host_name);
00319 ACE_UNUSED_ARG (protocol);
00320 ACE_NOTSUP_RETURN (-1);
00321 #else
00322 servent sentry;
00323 ACE_SERVENT_DATA buf;
00324
00325 servent *sp = ACE_OS::getservbyname_r (port_name,
00326 protocol,
00327 &sentry,
00328 buf);
00329 if (sp == 0)
00330 return -1;
00331
00332 int address_family = PF_UNSPEC;
00333 # if defined (ACE_HAS_IPV6)
00334 if (ACE_OS_String::strcmp (protocol, ACE_LIB_TEXT ("tcp6")) == 0)
00335 address_family = AF_INET6;
00336 # endif /* ACE_HAS_IPV6 */
00337
00338 return this->set (sp->s_port, host_name, 0, address_family);
00339 #endif /* VXWORKS */
00340 }
|
|
||||||||||||||||
|
Initializes an <ACE_INET_Addr> from a port_number and an Internet ip_addr. If encode is non-zero then the port number and IP address are converted into network byte order, otherwise they are assumed to be in network byte order already and are passed straight through. Definition at line 201 of file INET_Addr.cpp. References ACE_TRACE, set_address, and set_port_number.
00204 {
00205 ACE_TRACE ("ACE_INET_Addr::set");
00206 this->set_address (ACE_reinterpret_cast (const char *, &inet_address),
00207 sizeof inet_address,
00208 encode);
00209 this->set_port_number (port_number, encode);
00210
00211 return 0;
00212 }
|
|
||||||||||||||||||||
|
Initializes an <ACE_INET_Addr> from a <port_number> and the remote <host_name>. If <encode> is non-zero then <port_number> is converted into network byte order, otherwise it is assumed to be in network byte order already and are passed straight through. address_family can be used to select IPv4/IPv6 if the OS has IPv6 capability (ACE_HAS_IPV6 is defined). To specify IPv6, use the value AF_INET6. To specify IPv4, use AF_INET. Definition at line 219 of file INET_Addr.cpp. References ACE_HOSTENT_DATA, ACE_TRACE, ACE_OS::gethostbyname, ACE_OS::gethostbyname_r, inet_addr_, ACE_OS::inet_aton, ACE_OS_String::memcpy, ACE_OS_String::memset, set, set_addr, set_port_number, and ACE_Addr::set_type.
00223 {
00224 ACE_TRACE ("ACE_INET_Addr::set");
00225
00226 // Yow, someone gave us a NULL host_name!
00227 if (host_name == 0)
00228 {
00229 errno = EINVAL;
00230 return -1;
00231 }
00232
00233 ACE_OS_String::memset ((void *) &this->inet_addr_,
00234 0,
00235 sizeof this->inet_addr_);
00236
00237 #if defined (ACE_HAS_IPV6)
00238 struct addrinfo hints, *res, *res0;
00239 int error;
00240 ACE_OS_String::memset (&hints, 0, sizeof (hints));
00241
00242 hints.ai_family = address_family;
00243
00244 error = getaddrinfo (host_name, 0, &hints, &res0);
00245 if (error)
00246 return -1;
00247
00248 int ret = -1;
00249 for (res = res0; res != 0; res = res->ai_next)
00250 {
00251 if (res->ai_family == AF_INET || res->ai_family == AF_INET6)
00252 {
00253 this->set_type (res->ai_family);
00254 this->set_addr (res->ai_addr, res->ai_addrlen);
00255 this->set_port_number (port_number, encode);
00256 ret = 0;
00257 break;
00258 }
00259 }
00260 freeaddrinfo (res0);
00261 return ret;
00262
00263 #else /* ACE_HAS_IPV6 */
00264
00265 // IPv6 not supported... insure the family is set to IPv4
00266 address_family = AF_INET;
00267 this->set_type (address_family);
00268 this->inet_addr_.in4_.sin_family = address_family;
00269 struct in_addr addrv4;
00270 if (ACE_OS::inet_aton (host_name,
00271 &addrv4) == 1)
00272 return this->set (port_number,
00273 encode ? ntohl (addrv4.s_addr) : addrv4.s_addr,
00274 encode);
00275 else
00276 {
00277 # if defined (VXWORKS) || defined (CHORUS)
00278 hostent *hp = ACE_OS::gethostbyname (host_name);
00279 # else
00280 hostent hentry;
00281 ACE_HOSTENT_DATA buf;
00282 int h_error; // Not the same as errno!
00283
00284 hostent *hp = ACE_OS::gethostbyname_r (host_name, &hentry,
00285 buf, &h_error);
00286 # endif /* VXWORKS */
00287
00288 if (hp == 0)
00289 {
00290 return -1;
00291 }
00292 else
00293 {
00294 (void) ACE_OS_String::memcpy ((void *) &addrv4.s_addr,
00295 hp->h_addr,
00296 hp->h_length);
00297 return this->set (port_number,
00298 encode ? ntohl (addrv4.s_addr) : addrv4.s_addr,
00299 encode);
00300 }
00301 }
00302 #endif /* ACE_HAS_IPV6 */
00303 }
|
|
|
||||||||||||
|
Set a pointer to the address.
Reimplemented from ACE_Addr. Definition at line 457 of file INET_Addr.cpp. References ACE_TRACE, set_address, and set_port_number. Referenced by set, and ACE_MEM_Addr::set_addr.
00458 {
00459 ACE_TRACE ("ACE_INET_Addr::set_addr");
00460 struct sockaddr_in *getfamily = ACE_static_cast (struct sockaddr_in *, addr);
00461
00462 if (getfamily->sin_family == AF_INET)
00463 {
00464 this->set_port_number (getfamily->sin_port, 0);
00465 this->set_address (ACE_reinterpret_cast (const char*, &getfamily->sin_addr),
00466 sizeof (getfamily->sin_addr),
00467 0);
00468 }
00469 #if defined ACE_HAS_IPV6
00470 else if (getfamily->sin_family == AF_INET6)
00471 {
00472 struct sockaddr_in6 *in6 = ACE_static_cast (struct sockaddr_in6*, addr);
00473 this->set_port_number (in6->sin6_port, 0);
00474 this->set_address (ACE_reinterpret_cast (const char*, &in6->sin6_addr),
00475 sizeof (in6->sin6_addr),
00476 0);
00477 }
00478 #endif // ACE_HAS_IPV6
00479 }
|
|
||||||||||||||||
|
Sets the address without affecting the port number. If <encode> is enabled then <ip_addr> is converted into network byte order, otherwise it is assumed to be in network byte order already and are passed straight through. The size of the address is specified in the <len> parameter. Definition at line 743 of file INET_Addr.cpp. References ACE_HTONL, ACE_TRACE, ACE_Addr::base_set, EAFNOSUPPORT, ACE_Addr::get_type, INADDR_LOOPBACK, inet_addr_, ACE_OS_String::memcpy, and ACE_Addr::set_size. Referenced by set, and set_addr.
00746 {
00747 ACE_TRACE ("ACE_INET_Addr::set_address");
00748 // This is really intended for IPv4. If the object is IPv4, or the type
00749 // hasn't been set but it's a 4-byte address, go ahead. If this is an
00750 // IPv6 object and <encode> is requested, refuse.
00751 if (encode && len != 4)
00752 {
00753 errno = EAFNOSUPPORT;
00754 return -1;
00755 }
00756
00757 if (len == 4)
00758 {
00759 ACE_UINT32 ip4 = *ACE_reinterpret_cast (const ACE_UINT32 *, ip_addr);
00760 if (encode)
00761 ip4 = ACE_HTONL (ip4);
00762
00763
00764 if (this->get_type () == AF_INET) {
00765 this->base_set (AF_INET, sizeof (this->inet_addr_.in4_));
00766 this->inet_addr_.in4_.sin_family = AF_INET;
00767 this->set_size (sizeof (this->inet_addr_.in4_));
00768 ACE_OS_String::memcpy (&this->inet_addr_.in4_.sin_addr,
00769 &ip4,
00770 len);
00771 }
00772 #if defined (ACE_HAS_IPV6)
00773 // If given an IPv4 address to copy to an IPv6 object, map it to
00774 // an IPv4-mapped IPv6 address.
00775 else
00776 {
00777 this->base_set (AF_INET6, sizeof (this->inet_addr_.in6_));
00778 this->inet_addr_.in6_.sin6_family = AF_INET6;
00779 this->set_size (sizeof (this->inet_addr_.in6_));
00780 if (ip4 == INADDR_ANY)
00781 {
00782 in6_addr ip6 = in6addr_any;
00783 ACE_OS_String::memcpy (&this->inet_addr_.in6_.sin6_addr,
00784 &ip6,
00785 sizeof (ip6));
00786 return 0;
00787 }
00788 if (ip4 == INADDR_LOOPBACK)
00789 {
00790 in6_addr ip6 = in6addr_loopback;
00791 ACE_OS_String::memcpy (&this->inet_addr_.in6_.sin6_addr,
00792 &ip6,
00793 sizeof (ip6));
00794 return 0;
00795 }
00796
00797 // Build up a 128 bit address. An IPv4-mapped IPv6 address
00798 // is defined as 0:0:0:0:0:ffff:IPv4_address. This is defined
00799 // in RFC 1884 */
00800 struct {
00801 ACE_UINT16 prefix[5];
00802 ACE_UINT16 ffff;
00803 ACE_UINT32 addr;
00804 } newaddress = {
00805 { 0,0,0,0,0 },
00806 0xffff,
00807 ip4
00808 };
00809
00810 ACE_OS_String::memcpy (&this->inet_addr_.in6_.sin6_addr,
00811 &newaddress,
00812 sizeof (newaddress));
00813 }
00814 #endif /* ACE_HAS_IPV6 */
00815
00816 return 0;
00817 } /* end if (len == 4) */
00818 #if defined (ACE_HAS_IPV6)
00819 else if (len == 16)
00820 {
00821 if (this->get_type () != PF_INET6)
00822 {
00823 errno = EAFNOSUPPORT;
00824 return -1;
00825 }
00826 // We protect ourselves up above so IPv6 must be possible here.
00827 this->base_set (AF_INET6, sizeof (this->inet_addr_.in6_));
00828 this->inet_addr_.in6_.sin6_family = AF_INET6;
00829 ACE_OS_String::memcpy (&this->inet_addr_.in6_.sin6_addr, ip_addr, len);
00830
00831 return 0;
00832 } /* end len == 16 */
00833 else
00834 {
00835 /* unknown or unsupported address length */
00836 errno = EAFNOSUPPORT;
00837 return -1;
00838 }
00839
00840 #endif /* ACE_HAS_IPV6 */
00841
00842 // Here with an unrecognized length.
00843 errno = EAFNOSUPPORT;
00844 return -1;
00845
00846 }
|
|
||||||||||||
|
Sets the port number without affecting the host name. If <encode> is enabled then <port_number> is converted into network byte order, otherwise it is assumed to be in network byte order already and are passed straight through. Definition at line 649 of file INET_Addr.cpp. References ACE_TRACE, ACE_Addr::get_type, and inet_addr_. Referenced by ACE_SOCK_Dgram_Mcast::join, ACE_SOCK_Dgram_Mcast::open_i, ACE_SOCK_Dgram_Bcast::send, set, ACE_MEM_Addr::set_addr, set_addr, and ACE_MEM_Addr::set_port_number.
00651 {
00652 ACE_TRACE ("ACE_INET_Addr::set_port_number");
00653
00654 if (encode)
00655 port_number = htons (port_number);
00656
00657 #if defined (ACE_HAS_IPV6)
00658 if (this->get_type () == AF_INET6)
00659 this->inet_addr_.in6_.sin6_port = port_number;
00660 else
00661 #endif /* ACE_HAS_IPV6 */
00662 this->inet_addr_.in4_.sin_port = port_number;
00663 }
|
|
|
Initializes an <ACE_INET_Addr> from the <address>, which can be "ip-addr:port-number" (e.g., "tango.cs.wustl.edu:1234"), "ip-addr:port-name" (e.g., "tango.cs.wustl.edu:telnet"), "ip-number:port-number" (e.g., "128.252.166.57:1234"), or "ip-number:port-name" (e.g., "128.252.166.57:telnet"). If there is no ':' in the <address> it is assumed to be a port number, with the IP address being INADDR_ANY. Definition at line 121 of file INET_Addr.cpp. References ACE_ALLOCATOR_RETURN, ACE_MALLOC_T, ACE_TRACE, ACE_OS::atoi, ACE_OS_Memory::free, set, ACE_OS_String::strdup, ACE_OS_String::strlen, ACE_OS_String::strrchr, and ACE_OS_String::strspn. Referenced by set.
00122 {
00123 ACE_TRACE ("ACE_INET_Addr::string_to_addr");
00124 int result;
00125 char *ip_addr;
00126
00127 // Need to make a duplicate since we'll be overwriting the string.
00128 ACE_ALLOCATOR_RETURN (ip_addr,
00129 ACE_OS::strdup (s),
00130 -1);
00131 // We use strrchr because of IPv6 addresses.
00132 char *port_p = ACE_OS::strrchr (ip_addr, ':');
00133
00134 if (port_p == 0) // Assume it's a port number.
00135 {
00136 if (ACE_OS::strspn (ip_addr, "1234567890") == ACE_OS::strlen (ip_addr))
00137 { // port number
00138 u_short port = (u_short) ACE_OS::atoi (ip_addr);
00139 result = this->set (port, ACE_UINT32 (INADDR_ANY));
00140 }
00141 else // port name
00142 result = this->set (ip_addr, ACE_UINT32 (INADDR_ANY));
00143 }
00144 else
00145 {
00146 *port_p = '\0'; ++port_p; // skip over ':'
00147
00148 if (ACE_OS::strspn (port_p, "1234567890") == ACE_OS::strlen (port_p))
00149 {
00150 u_short port = (u_short) ACE_OS::atoi (port_p);
00151 result = this->set (port, ip_addr);
00152 }
00153 else
00154 result = this->set (port_p, ip_addr);
00155 }
00156
00157 ACE_OS::free (ACE_MALLOC_T (ip_addr));
00158 return result;
00159 }
|
|
|
Declare the dynamic allocation hooks.
Reimplemented from ACE_Addr. Definition at line 296 of file INET_Addr.h. |
|
|
Definition at line 316 of file INET_Addr.h. |
|
|
Underlying representation. This union uses the knowledge that the two structures share the first member, sa_family (as all sockaddr structures do).
Referenced by get_addr, get_addr_size, get_host_name_i, ip_addr_pointer, operator==, reset, set, set_address, and set_port_number. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002