ACE_INET_Addr Class Reference

Defines a C++ wrapper facade for the Internet domain address family format. More...

#include <INET_Addr.h>

Inheritance diagram for ACE_INET_Addr:
Inheritance graph
[legend]
Collaboration diagram for ACE_INET_Addr:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ACE_INET_Addr (void)
 Default constructor.
 ACE_INET_Addr (const ACE_INET_Addr &)
 Copy constructor.
 ACE_INET_Addr (const sockaddr_in *addr, int len)
 Creates an ACE_INET_Addr from a sockaddr_in structure.
 ACE_INET_Addr (u_short port_number, const char host_name[], int address_family=AF_UNSPEC)
 ACE_INET_Addr (const char address[], int address_family=AF_UNSPEC)
 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")
 ACE_INET_Addr (const char port_name[], ACE_UINT32 ip_addr, const char protocol[]="tcp")
 ~ACE_INET_Addr (void)
 Default dtor.
int set (const ACE_INET_Addr &)
 Initializes from another ACE_INET_Addr.
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 map=0)
int set (const char port_name[], const char host_name[], const char protocol[]="tcp")
int set (const char port_name[], ACE_UINT32 ip_addr, const char protocol[]="tcp")
int set (const char addr[], int address_family=AF_UNSPEC)
int set (const sockaddr_in *, int len)
 Creates an ACE_INET_Addr from a sockaddr_in structure.
virtual void * get_addr (void) const
 Return a pointer to the underlying network address.
int get_addr_size (void) const
virtual void set_addr (void *, int len)
 Set a pointer to the address.
virtual void set_addr (void *, int len, int map)
 Set a pointer to the address.
virtual int addr_to_string (ACE_TCHAR buffer[], size_t size, int ipaddr_format=1) const
virtual int string_to_addr (const char address[], int address_family=AF_UNSPEC)
void set_port_number (u_short, int encode=1)
int set_address (const char *ip_addr, int len, int encode=1, int map=0)
u_short get_port_number (void) const
 Return the port number, converting it into host byte-order.
int get_host_name (char hostname[], size_t hostnamelen) const
const char * get_host_name (void) const
const char * get_host_addr (char *addr, int addr_size) const
const char * get_host_addr (void) const
ACE_UINT32 get_ip_address (void) const
bool is_any (void) const
 Return true if the IP address is INADDR_ANY or IN6ADDR_ANY.
bool is_loopback (void) const
 Return true if the IP address is IPv4/IPv6 loopback address.
bool is_multicast (void) const
 Return true if the IP address is IPv4/IPv6 multicast address.
bool operator< (const ACE_INET_Addr &rhs) const
bool operator== (const ACE_INET_Addr &SAP) const
bool operator!= (const ACE_INET_Addr &SAP) const
 Compare two addresses for inequality.
bool is_ip_equal (const ACE_INET_Addr &SAP) const
virtual u_long hash (void) const
 Computes and returns hash value.
void dump (void) const
 Dump the state of an object.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.
sockaddr_in in4_

Private Member Functions

int get_host_name_i (char hostname[], size_t hostnamelen) const
 Insure that hostname is properly null-terminated.
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.

Private Attributes

union {
   sockaddr_in   in4_
inet_addr_

Detailed Description

Defines a C++ wrapper facade for the Internet domain address family format.

Definition at line 33 of file INET_Addr.h.


Constructor & Destructor Documentation

ACE_INET_Addr::ACE_INET_Addr ( void   ) 

Default constructor.

Definition at line 160 of file INET_Addr.cpp.

00161   : ACE_Addr (determine_type (), sizeof (inet_addr_))
00162 {
00163   // ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
00164   this->reset ();
00165 }

ACE_INET_Addr::ACE_INET_Addr ( const ACE_INET_Addr sa  ) 

Copy constructor.

Definition at line 291 of file INET_Addr.cpp.

00292   : ACE_Addr (sa.get_type (), sa.get_size())
00293 {
00294   ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
00295   this->reset ();
00296   this->set (sa);
00297 }

ACE_INET_Addr::ACE_INET_Addr ( const sockaddr_in addr,
int  len 
)

Creates an ACE_INET_Addr from a sockaddr_in structure.

Definition at line 642 of file INET_Addr.cpp.

00643   : ACE_Addr (determine_type (), sizeof (inet_addr_))
00644 {
00645   ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
00646   this->reset ();
00647   this->set (addr, len);
00648 }

ACE_INET_Addr::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

See also:
set(). Use address_family to select IPv6 (PF_INET6) vs. IPv4 (PF_INET).

Definition at line 523 of file INET_Addr.cpp.

00526   : ACE_Addr (determine_type (), sizeof (inet_addr_))
00527 {
00528   ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
00529   ACE_OS::memset (&this->inet_addr_, 0, sizeof (this->inet_addr_));
00530   if (this->set (port_number,
00531                  host_name,
00532                  1,
00533                  address_family) == -1)
00534     ACE_ERROR ((LM_ERROR,
00535                 ACE_TEXT ("ACE_INET_Addr::ACE_INET_Addr: %p\n"),
00536                 ACE_TEXT_CHAR_TO_TCHAR ((host_name == 0) ?
00537                                         "<unknown>" : host_name)));
00538 }

ACE_INET_Addr::ACE_INET_Addr ( const char  address[],
int  address_family = AF_UNSPEC 
) [explicit]

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 270 of file INET_Addr.cpp.

00271   : ACE_Addr (determine_type (), sizeof (inet_addr_))
00272 {
00273   ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
00274   this->reset ();
00275   this->set (address, address_family);
00276 }

ACE_INET_Addr::ACE_INET_Addr ( u_short  port_number,
ACE_UINT32  ip_addr = INADDR_ANY 
) [explicit]

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,

See also:
set().

Definition at line 652 of file INET_Addr.cpp.

00654   : ACE_Addr (determine_type (), sizeof (inet_addr_))
00655 {
00656   ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
00657   this->reset ();
00658   if (this->set (port_number, inet_address) == -1)
00659     ACE_ERROR ((LM_ERROR,
00660                 ACE_TEXT ("%p\n"),
00661                 ACE_TEXT ("ACE_INET_Addr::ACE_INET_Addr")));
00662 }

ACE_INET_Addr::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.

Definition at line 667 of file INET_Addr.cpp.

00670   : ACE_Addr (determine_type (), sizeof (inet_addr_))
00671 {
00672   ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
00673   this->reset ();
00674   if (this->set (port_name,
00675                  host_name,
00676                  protocol) == -1)
00677     ACE_ERROR ((LM_ERROR,
00678                 ACE_TEXT ("ACE_INET_Addr::ACE_INET_Addr")));
00679 }

ACE_INET_Addr::ACE_INET_Addr ( const char  port_name[],
ACE_UINT32  ip_addr,
const char  protocol[] = "tcp" 
)

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 699 of file INET_Addr.cpp.

00702   : ACE_Addr (determine_type (), sizeof (inet_addr_))
00703 {
00704   ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
00705   this->reset ();
00706   if (this->set (port_name,
00707                  ACE_HTONL (inet_address),
00708                  protocol) == -1)
00709     ACE_ERROR ((LM_ERROR,
00710                 ACE_TEXT ("ACE_INET_Addr::ACE_INET_Addr")));
00711 }

ACE_INET_Addr::~ACE_INET_Addr ( void   ) 

Default dtor.

Definition at line 729 of file INET_Addr.cpp.

00730 {
00731 }


Member Function Documentation

virtual int ACE_INET_Addr::addr_to_string ( ACE_TCHAR  buffer[],
size_t  size,
int  ipaddr_format = 1 
) const [virtual]

Transform the current ACE_INET_Addr address into string format. If ipaddr_format is ttrue this produces "ip-number:port-number" (e.g., "128.252.166.57:1234"), whereas if ipaddr_format is false 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.

int ACE_INET_Addr::determine_type ( void   )  const [private]

Definition at line 35 of file INET_Addr.inl.

00036 {
00037 #if defined (ACE_HAS_IPV6)
00038 #  if defined (ACE_USES_IPV4_IPV6_MIGRATION)
00039   return ACE::ipv6_enabled () ? AF_INET6 : AF_INET;
00040 #  else
00041   return AF_INET6;
00042 #  endif /* ACE_USES_IPV4_IPV6_MIGRATION */
00043 #else
00044   return AF_INET;
00045 #endif /* ACE_HAS_IPV6 */
00046 }

void ACE_INET_Addr::dump ( void   )  const

Dump the state of an object.

Reimplemented from ACE_Addr.

Definition at line 82 of file INET_Addr.cpp.

00083 {
00084 #if defined (ACE_HAS_DUMP)
00085   ACE_TRACE ("ACE_INET_Addr::dump");
00086 
00087   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00088 
00089   ACE_TCHAR s[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 16];
00090   this->addr_to_string(s, ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 16);
00091   ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s"), s));
00092   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00093 #endif /* ACE_HAS_DUMP */
00094 }

void * ACE_INET_Addr::get_addr ( void   )  const [virtual]

Return a pointer to the underlying network address.

Reimplemented from ACE_Addr.

Definition at line 595 of file INET_Addr.cpp.

00596 {
00597   ACE_TRACE ("ACE_INET_Addr::get_addr");
00598   return (void*)&this->inet_addr_;
00599 }

int ACE_INET_Addr::get_addr_size ( void   )  const

Definition at line 102 of file INET_Addr.inl.

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 }

const char * ACE_INET_Addr::get_host_addr ( void   )  const

Return the "dotted decimal" Internet address representation of the hostname. This version is non-reentrant since it returns a pointer to a static data area. You should therefore either (1) do a "deep copy" of the address returned by get_host_addr(), e.g., using strdup() or (2) use the "reentrant" version of get_host_addr() described above.

Definition at line 1108 of file INET_Addr.cpp.

01109 {
01110   ACE_TRACE ("ACE_INET_Addr::get_host_addr");
01111 #if defined (ACE_HAS_IPV6)
01112   static char buf[INET6_ADDRSTRLEN];
01113   return this->get_host_addr (buf, INET6_ADDRSTRLEN);
01114 #else /* ACE_HAS_IPV6 */
01115   static char buf[INET_ADDRSTRLEN];
01116   return this->get_host_addr (buf, INET_ADDRSTRLEN);
01117 #endif /* !ACE_HAS_IPV6 */
01118 }

const char * ACE_INET_Addr::get_host_addr ( char *  addr,
int  addr_size 
) const

Return the "dotted decimal" Internet address representation of the hostname storing it in the addr (which is assumed to be addr_size bytes long). This version is reentrant.

Definition at line 1048 of file INET_Addr.cpp.

01049 {
01050 #if defined (ACE_HAS_IPV6)
01051   if (this->get_type () == AF_INET6)
01052     {
01053       // mcorino@remedy.nl - Aug-26, 2005
01054       // I don't think this should be done because it results in a decimal address
01055       // representation which is not distinguishable from the IPv4 form which makes
01056       // it impossible to resolve back to an IPv6 INET_Addr without prior knowledge
01057       // that this was such an address to begin with.
01058 
01059       //if (IN6_IS_ADDR_V4MAPPED (&this->inet_addr_.in6_.sin6_addr))
01060       //{
01061       //  ACE_UINT32 addr;
01062       //  addr = this->get_ip_address();
01063       //  addr = ACE_HTONL (addr);
01064       //  return ACE_OS::inet_ntop (AF_INET, &addr, dst, size);
01065       //}
01066 
01067 #  if defined (ACE_WIN32)
01068       if (0 == ::getnameinfo (reinterpret_cast<const sockaddr*> (&this->inet_addr_.in6_),
01069                               this->get_size (),
01070                               dst,
01071                               size,
01072                               0, 0,    // Don't want service name
01073                               NI_NUMERICHOST))
01074         return dst;
01075       ACE_OS::set_errno_to_wsa_last_error ();
01076       return 0;
01077 #  else
01078       const char *ch = ACE_OS::inet_ntop (AF_INET6,
01079                                           &this->inet_addr_.in6_.sin6_addr,
01080                                           dst,
01081                                           size);
01082 #if defined (__linux__)
01083       if ((IN6_IS_ADDR_LINKLOCAL (&this->inet_addr_.in6_.sin6_addr) ||
01084            IN6_IS_ADDR_MC_LINKLOCAL (&this->inet_addr_.in6_.sin6_addr)) &&
01085           this->inet_addr_.in6_.sin6_scope_id != 0)
01086         {
01087           char scope_buf[32];
01088           ACE_OS::sprintf (scope_buf, "%%%u", this->inet_addr_.in6_.sin6_scope_id);
01089           if ((ACE_OS::strlen (ch)+ACE_OS::strlen (scope_buf)) < (size_t)size)
01090             {
01091               ACE_OS::strcat (dst, scope_buf);
01092             }
01093         }
01094 #endif
01095       return ch;
01096 #  endif /* ACE_WIN32 */
01097     }
01098 #endif /* ACE_HAS_IPV6 */
01099 
01100   return ACE_OS::inet_ntop (AF_INET,
01101           &this->inet_addr_.in4_.sin_addr,
01102           dst,
01103           size);
01104 }

const char * ACE_INET_Addr::get_host_name ( void   )  const

Return the character representation of the hostname. This version is non-reentrant since it returns a pointer to a static data area. You should therefore either (1) do a "deep copy" of the address returned by get_host_name(), e.g., using strdup() or (2) use the "reentrant" version of get_host_name() described above.

Definition at line 794 of file INET_Addr.cpp.

00795 {
00796   ACE_TRACE ("ACE_INET_Addr::get_host_name");
00797 
00798   static char name[MAXHOSTNAMELEN + 1];
00799   if (this->get_host_name (name, MAXHOSTNAMELEN + 1) == -1)
00800     ACE_OS::strcpy (name, "<unknown>");
00801   return name;
00802 }

int ACE_INET_Addr::get_host_name ( char  hostname[],
size_t  hostnamelen 
) const

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 734 of file INET_Addr.cpp.

00736 {
00737   ACE_TRACE ("ACE_INET_Addr::get_host_name");
00738 
00739   int result;
00740   if (len > 1)
00741     {
00742       result = this->get_host_name_i (hostname,len);
00743       if (result < 0)
00744         {
00745           if (result == -2)
00746             // We know that hostname is nul-terminated
00747             result = -1;
00748           else
00749             {
00750               //result == -1;
00751               // This could be worse than hostname[len -1] = '\0'?
00752               hostname[0] = '\0';
00753             }
00754         }
00755     }
00756   else
00757     {
00758       if (len == 1)
00759         hostname[0] = '\0';
00760       result = -1;
00761     }
00762 
00763   return result;
00764 }

int ACE_INET_Addr::get_host_name_i ( char  hostname[],
size_t  hostnamelen 
) const [private]

Insure that hostname is properly null-terminated.

Definition at line 823 of file INET_Addr.cpp.

00824 {
00825   ACE_TRACE ("ACE_INET_Addr::get_host_name_i");
00826 
00827 #if defined (ACE_HAS_IPV6)
00828   if ((this->get_type () == PF_INET6 &&
00829        0 == ACE_OS::memcmp (&this->inet_addr_.in6_.sin6_addr,
00830                             &in6addr_any,
00831                             sizeof (this->inet_addr_.in6_.sin6_addr)))
00832       ||
00833       (this->get_type () == PF_INET &&
00834        this->inet_addr_.in4_.sin_addr.s_addr == INADDR_ANY))
00835 #else
00836   if (this->inet_addr_.in4_.sin_addr.s_addr == INADDR_ANY)
00837 #endif /* ACE_HAS_IPV6 */
00838     {
00839       if (ACE_OS::hostname (hostname, len) == -1)
00840         return -1;
00841       else
00842         return 0;
00843     }
00844   else
00845     {
00846 #if defined (ACE_VXWORKS) && defined (ACE_LACKS_GETHOSTBYADDR)
00847       ACE_UNUSED_ARG (len);
00848       int error =
00849         ::hostGetByAddr ((int) this->inet_addr_.in4_.sin_addr.s_addr,
00850                          hostname);
00851       if (error == OK)
00852         return 0;
00853       else
00854         {
00855           errno = error;
00856           return -1;
00857         }
00858 #else
00859       void* addr = this->ip_addr_pointer ();
00860       int   size = this->ip_addr_size ();
00861       int   type = this->get_type ();
00862 
00863 #  if defined (ACE_HAS_IPV6) && defined (ACE_HAS_BROKEN_GETHOSTBYADDR_V4MAPPED)
00864       // Most OS can not handle IPv6-mapped-IPv4 addresses (even
00865       // though they are meant to) so map them back to IPv4 addresses
00866       // before trying to resolve them
00867       in_addr demapped_addr;
00868       if (type == PF_INET6 &&
00869           (this->is_ipv4_mapped_ipv6 () || this->is_ipv4_compat_ipv6 ()))
00870         {
00871           ACE_OS::memcpy (&demapped_addr.s_addr, &this->inet_addr_.in6_.sin6_addr.s6_addr[12], 4);
00872           addr = &demapped_addr;
00873           size = sizeof(demapped_addr);
00874           type = PF_INET;
00875         }
00876 #  endif /* ACE_HAS_IPV6 */
00877 
00878 #  if defined (DIGITAL_UNIX) && defined (__GNUC__)
00879       hostent * const hp =
00880         ACE_OS::gethostbyaddr (static_cast <char *> (addr), size, type);
00881 #  else
00882       int h_error;  // Not the same as errno!
00883       hostent hentry;
00884       ACE_HOSTENT_DATA buf;
00885       hostent * const hp =
00886         ACE_OS::gethostbyaddr_r (static_cast <char *> (addr),
00887                                  size,
00888                                  type,
00889                                  &hentry,
00890                                  buf,
00891                                  &h_error);
00892 #  endif /* DIGITAL_UNIX */
00893 
00894       if (hp == 0 || hp->h_name == 0)
00895         return -1;
00896 
00897       if (ACE_OS::strlen (hp->h_name) >= len)
00898         {
00899           // We know the length, so use memcpy
00900           if (len > 0)
00901             {
00902               ACE_OS::memcpy (hostname, hp->h_name, len - 1);
00903               hostname[len-1]= '\0';
00904             }
00905           errno = ENOSPC;
00906           return -2;  // -2 Means that we have a good string
00907           // Using errno looks ok, but ENOSPC could be set on
00908           // other places.
00909         }
00910 
00911       ACE_OS::strcpy (hostname, hp->h_name);
00912       return 0;
00913 #endif /* ACE_VXWORKS */
00914     }
00915 }

ACE_UINT32 ACE_INET_Addr::get_ip_address ( void   )  const

Return the 4-byte IP address, converting it into host byte order.

Definition at line 1122 of file INET_Addr.cpp.

01123 {
01124   ACE_TRACE ("ACE_INET_Addr::get_ip_address");
01125 #if defined (ACE_HAS_IPV6)
01126   if (this->get_type () == AF_INET6)
01127     {
01128       if (IN6_IS_ADDR_V4MAPPED (&this->inet_addr_.in6_.sin6_addr) ||
01129           IN6_IS_ADDR_V4COMPAT (&this->inet_addr_.in6_.sin6_addr)    )
01130         {
01131           ACE_UINT32 addr;
01132           // Return the last 32 bits of the address
01133           char *thisaddrptr = (char*)this->ip_addr_pointer ();
01134           thisaddrptr += 128/8 - 32/8;
01135           ACE_OS::memcpy (&addr, thisaddrptr, sizeof (addr));
01136           return ACE_NTOHL (addr);
01137         }
01138 
01139       ACE_ERROR ((LM_ERROR,
01140                   ACE_TEXT ("ACE_INET_Addr::get_ip_address: address is a IPv6 address not IPv4\n")));
01141       errno = EAFNOSUPPORT;
01142       return 0;
01143     }
01144 #endif /* ACE_HAS_IPV6 */
01145   return ACE_NTOHL (ACE_UINT32 (this->inet_addr_.in4_.sin_addr.s_addr));
01146 }

u_short ACE_INET_Addr::get_port_number ( void   )  const

Return the port number, converting it into host byte-order.

Definition at line 88 of file INET_Addr.inl.

00089 {
00090   ACE_TRACE ("ACE_INET_Addr::get_port_number");
00091 #if defined (ACE_HAS_IPV6)
00092   if (this->get_type () == PF_INET)
00093     return ACE_NTOHS (this->inet_addr_.in4_.sin_port);
00094   else
00095     return ACE_NTOHS (this->inet_addr_.in6_.sin6_port);
00096 #else
00097   return ACE_NTOHS (this->inet_addr_.in4_.sin_port);
00098 #endif /* ACE_HAS_IPV6 */
00099 }

u_long ACE_INET_Addr::hash ( void   )  const [virtual]

Computes and returns hash value.

Reimplemented from ACE_Addr.

Definition at line 147 of file INET_Addr.cpp.

00148 {
00149 #if defined (ACE_HAS_IPV6)
00150   if (this->get_type () == PF_INET6)
00151     {
00152       const unsigned int *addr = (const unsigned int*)this->ip_addr_pointer();
00153       return addr[0] + addr[1] + addr[2] + addr[3] + this->get_port_number();
00154     }
00155   else
00156 #endif /* ACE_HAS_IPV6 */
00157   return this->get_ip_address () + this->get_port_number ();
00158 }

void * ACE_INET_Addr::ip_addr_pointer ( void   )  const [private]

Definition at line 49 of file INET_Addr.inl.

00050 {
00051 #if defined (ACE_HAS_IPV6)
00052   if (this->get_type () == PF_INET)
00053     return (void*)&this->inet_addr_.in4_.sin_addr;
00054   else
00055     return (void*)&this->inet_addr_.in6_.sin6_addr;
00056 #else
00057   return (void*)&this->inet_addr_.in4_.sin_addr;
00058 #endif
00059 }

int ACE_INET_Addr::ip_addr_size ( void   )  const [private]

Definition at line 62 of file INET_Addr.inl.

00063 {
00064   // Since this size value is used to pass to other host db-type
00065   // functions (gethostbyaddr, etc.) the length is of int type.
00066   // Thus, cast all these sizes back to int. They're all well
00067   // within the range of an int anyway.
00068 #if defined (ACE_HAS_IPV6)
00069   if (this->get_type () == PF_INET)
00070     return static_cast<int> (sizeof this->inet_addr_.in4_.sin_addr);
00071   else
00072     return static_cast<int> (sizeof this->inet_addr_.in6_.sin6_addr);
00073 #else
00074   // These _UNICOS changes were picked up from pre-IPv6 code in
00075   // get_host_name_i... the IPv6 section above may need something
00076   // similar, so keep an eye out for it.
00077 #  if !defined(_UNICOS)
00078   return static_cast<int> (sizeof this->inet_addr_.in4_.sin_addr.s_addr);
00079 #  else /* _UNICOS */
00080   return static_cast<int> (sizeof this->inet_addr_.in4_.sin_addr);
00081 #  endif /* ! _UNICOS */
00082 #endif /* ACE_HAS_IPV6 */
00083 }

bool ACE_INET_Addr::is_any ( void   )  const

Return true if the IP address is INADDR_ANY or IN6ADDR_ANY.

Definition at line 187 of file INET_Addr.inl.

00188 {
00189 #if defined (ACE_HAS_IPV6)
00190   if (this->get_type () == AF_INET6)
00191       return IN6_IS_ADDR_UNSPECIFIED (&this->inet_addr_.in6_.sin6_addr);
00192 #endif /* ACE_HAS_IPV6 */
00193 
00194   return (this->inet_addr_.in4_.sin_addr.s_addr == INADDR_ANY);
00195 }

bool ACE_INET_Addr::is_ip_equal ( const ACE_INET_Addr SAP  )  const

A variation of the equality operator, this method only compares the IP address and ignores the port number.

Definition at line 122 of file INET_Addr.cpp.

00123 {
00124     if (this->get_type () != sap.get_type ()
00125       || this->get_size () != sap.get_size ())
00126     return false;
00127 
00128 #if defined (ACE_HAS_IPV6)
00129   if (this->get_type () == PF_INET6)
00130     {
00131       const unsigned int *addr =
00132         reinterpret_cast<const unsigned int*>(this->ip_addr_pointer());
00133       const unsigned int *saddr =
00134         reinterpret_cast<const unsigned int*>(sap.ip_addr_pointer());
00135       return (addr[0] == saddr[0] &&
00136               addr[1] == saddr[1] &&
00137               addr[2] == saddr[2] &&
00138               addr[3] == saddr[3]);
00139     }
00140   else
00141 #endif /* ACE_HAS_IPV6 */
00142   return this->get_ip_address () == sap.get_ip_address();
00143 }

bool ACE_INET_Addr::is_loopback ( void   )  const

Return true if the IP address is IPv4/IPv6 loopback address.

Definition at line 199 of file INET_Addr.inl.

00200 {
00201 #if defined (ACE_HAS_IPV6)
00202   if (this->get_type () == AF_INET6)
00203       return IN6_IS_ADDR_LOOPBACK (&this->inet_addr_.in6_.sin6_addr);
00204 #endif /* ACE_HAS_IPV6 */
00205 
00206   // RFC 3330 defines loopback as any address with 127.x.x.x
00207   return ((this->get_ip_address () & 0XFF000000) == (INADDR_LOOPBACK & 0XFF000000));
00208 }

bool ACE_INET_Addr::is_multicast ( void   )  const

Return true if the IP address is IPv4/IPv6 multicast address.

Definition at line 212 of file INET_Addr.inl.

00213 {
00214 #if defined (ACE_HAS_IPV6)
00215   if (this->get_type() == AF_INET6)
00216     return this->inet_addr_.in6_.sin6_addr.s6_addr[0] == 0xFF;
00217 #endif /* ACE_HAS_IPV6 */
00218   return
00219     this->inet_addr_.in4_.sin_addr.s_addr >= 0xE0000000 &&  // 224.0.0.0
00220     this->inet_addr_.in4_.sin_addr.s_addr <= 0xEFFFFFFF; // 239.255.255.255
00221 }

bool ACE_INET_Addr::operator!= ( const ACE_INET_Addr SAP  )  const

Compare two addresses for inequality.

Reimplemented from ACE_Addr.

Definition at line 99 of file INET_Addr.cpp.

00100 {
00101   ACE_TRACE ("ACE_INET_Addr::operator !=");
00102   return !((*this) == sap);
00103 }

bool ACE_INET_Addr::operator< ( const ACE_INET_Addr rhs  )  const

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_Addrs in STL maps.

Definition at line 116 of file INET_Addr.inl.

00117 {
00118 #if defined (ACE_HAS_IPV6)
00119   if (this->get_type() != rhs.get_type())
00120   {
00121     return this->get_type() < rhs.get_type();
00122   }
00123 
00124   if (this->get_type() == PF_INET6)
00125   {
00126     int memval = ACE_OS::memcmp (this->ip_addr_pointer(),
00127                                  rhs.ip_addr_pointer(),
00128                                  this->ip_addr_size());
00129 
00130     return memval < 0
00131             || (memval == 0
00132                 && (this->get_port_number() < rhs.get_port_number()
00133                     || (this->get_port_number() == rhs.get_port_number()
00134                         && this->inet_addr_.in6_.sin6_scope_id <
00135                             rhs.inet_addr_.in6_.sin6_scope_id)));
00136   }
00137 #endif
00138 
00139   return this->get_ip_address () < rhs.get_ip_address ()
00140     || (this->get_ip_address () == rhs.get_ip_address ()
00141         && this->get_port_number () < rhs.get_port_number ());
00142 }

bool ACE_INET_Addr::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.

Reimplemented from ACE_Addr.

Definition at line 108 of file INET_Addr.cpp.

00109 {
00110   ACE_TRACE ("ACE_INET_Addr::operator ==");
00111 
00112   if (this->get_type () != sap.get_type ()
00113       || this->get_size () != sap.get_size ())
00114     return false;
00115 
00116   return (ACE_OS::memcmp (&this->inet_addr_,
00117                           &sap.inet_addr_,
00118                           this->get_size ()) == 0);
00119 }

void ACE_INET_Addr::reset ( void   )  [private]

Initialize underlying inet_addr_ to default values.

Definition at line 13 of file INET_Addr.inl.

00014 {
00015   ACE_OS::memset (&this->inet_addr_, 0, sizeof (this->inet_addr_));
00016   if (this->get_type() == AF_INET)
00017     {
00018 #ifdef ACE_HAS_SOCKADDR_IN_SIN_LEN
00019       this->inet_addr_.in4_.sin_len = sizeof (this->inet_addr_.in4_);
00020 #endif
00021       this->inet_addr_.in4_.sin_family = AF_INET;
00022     }
00023 #if defined (ACE_HAS_IPV6)
00024   else if (this->get_type() == AF_INET6)
00025     {
00026 #ifdef ACE_HAS_SOCKADDR_IN6_SIN6_LEN
00027       this->inet_addr_.in6_.sin6_len = sizeof (this->inet_addr_.in6_);
00028 #endif
00029       this->inet_addr_.in6_.sin6_family = AF_INET6;
00030     }
00031 #endif  /* ACE_HAS_IPV6 */
00032 }

int ACE_INET_Addr::set ( const sockaddr_in addr,
int  len 
)

Creates an ACE_INET_Addr from a sockaddr_in structure.

Definition at line 563 of file INET_Addr.cpp.

00564 {
00565   ACE_TRACE ("ACE_INET_Addr::set");
00566 
00567   if (addr->sin_family == AF_INET)
00568     {
00569       int maxlen = static_cast<int> (sizeof (this->inet_addr_.in4_));
00570       if (len > maxlen)
00571         len = maxlen;
00572       ACE_OS::memcpy (&this->inet_addr_.in4_, addr, len);
00573       this->base_set (AF_INET, len);
00574       return 0;
00575     }
00576 #if defined (ACE_HAS_IPV6)
00577   else if (addr->sin_family == AF_INET6)
00578     {
00579       int maxlen = static_cast<int> (sizeof (this->inet_addr_.in6_));
00580       if (len > maxlen)
00581         len = maxlen;
00582       ACE_OS::memcpy (&this->inet_addr_.in6_, addr, len);
00583       this->base_set (AF_INET6, len);
00584       return 0;
00585     }
00586 #endif /* ACE_HAS_IPV6 */
00587 
00588   errno = EAFNOSUPPORT;
00589   return -1;
00590 }

int ACE_INET_Addr::set ( const char  addr[],
int  address_family = AF_UNSPEC 
)

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 264 of file INET_Addr.cpp.

00265 {
00266   ACE_TRACE ("ACE_INET_Addr::set");
00267   return this->string_to_addr (address, address_family);
00268 }

int ACE_INET_Addr::set ( const char  port_name[],
ACE_UINT32  ip_addr,
const char  protocol[] = "tcp" 
)

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 504 of file INET_Addr.cpp.

00507 {
00508   ACE_TRACE ("ACE_INET_Addr::set");
00509 
00510   int const port_number = get_port_number_from_name (port_name, protocol);
00511   if (port_number == -1)
00512     {
00513       ACE_NOTSUP_RETURN (-1);
00514     }
00515 
00516   return this->set (static_cast<u_short> (port_number),
00517                     inet_address, 0);
00518 }

int ACE_INET_Addr::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.

Definition at line 478 of file INET_Addr.cpp.

00481 {
00482   ACE_TRACE ("ACE_INET_Addr::set");
00483 
00484   int const port_number = get_port_number_from_name (port_name, protocol);
00485   if (port_number == -1)
00486     {
00487       ACE_NOTSUP_RETURN (-1);
00488     }
00489 
00490   int address_family = PF_UNSPEC;
00491 #  if defined (ACE_HAS_IPV6)
00492   if (ACE_OS::strcmp (protocol, "tcp6") == 0)
00493     address_family = AF_INET6;
00494 #  endif /* ACE_HAS_IPV6 */
00495 
00496   return this->set (static_cast<u_short> (port_number),
00497                     host_name, 0, address_family);
00498 }

int ACE_INET_Addr::set ( u_short  port_number,
ACE_UINT32  ip_addr = INADDR_ANY,
int  encode = 1,
int  map = 0 
)

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.

If <map> is non-zero and IPv6 support has been compiled in, then this address will be set to the IPv4-mapped IPv6 address of it.

Definition at line 303 of file INET_Addr.cpp.

00307 {
00308   ACE_TRACE ("ACE_INET_Addr::set");
00309   this->set_address (reinterpret_cast<const char *> (&inet_address),
00310                      sizeof inet_address,
00311                      encode, map);
00312   this->set_port_number (port_number, encode);
00313 
00314   return 0;
00315 }

int ACE_INET_Addr::set ( u_short  port_number,
const char  host_name[],
int  encode = 1,
int  address_family = AF_UNSPEC 
)

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 322 of file INET_Addr.cpp.

00326 {
00327   ACE_TRACE ("ACE_INET_Addr::set");
00328 
00329   // Yow, someone gave us a NULL host_name!
00330   if (host_name == 0)
00331     {
00332       errno = EINVAL;
00333       return -1;
00334     }
00335 
00336   ACE_OS::memset ((void *) &this->inet_addr_,
00337                   0,
00338                   sizeof this->inet_addr_);
00339 
00340 #if defined (ACE_HAS_IPV6)
00341   struct addrinfo hints;
00342   struct addrinfo *res = 0;
00343   int error = 0;
00344   ACE_OS::memset (&hints, 0, sizeof (hints));
00345 # if defined (ACE_USES_IPV4_IPV6_MIGRATION)
00346   if (address_family == AF_UNSPEC && !ACE::ipv6_enabled())
00347     address_family = AF_INET;
00348 # endif /* ACE_USES_IPV4_IPV6_MIGRATION */
00349   if (address_family == AF_UNSPEC || address_family == AF_INET6)
00350     {
00351       hints.ai_family = AF_INET6;
00352       error = ::getaddrinfo (host_name, 0, &hints, &res);
00353       if (error)
00354         {
00355           if (address_family == AF_INET6)
00356             {
00357               if (res)
00358                 ::freeaddrinfo(res);
00359               errno = error;
00360               return -1;
00361             }
00362           address_family = AF_INET;
00363         }
00364     }
00365   if (address_family == AF_INET)
00366     {
00367       hints.ai_family = AF_INET;
00368       error = ::getaddrinfo (host_name, 0, &hints, &res);
00369       if (error)
00370         {
00371           if (res)
00372             ::freeaddrinfo(res);
00373           errno = error;
00374           return -1;
00375         }
00376     }
00377   this->set_type (res->ai_family);
00378   this->set_addr (res->ai_addr, res->ai_addrlen);
00379   this->set_port_number (port_number, encode);
00380   ::freeaddrinfo (res);
00381   return 0;
00382 #else /* ACE_HAS_IPV6 */
00383 
00384   // IPv6 not supported... insure the family is set to IPv4
00385   address_family = AF_INET;
00386   this->set_type (address_family);
00387   this->inet_addr_.in4_.sin_family = static_cast<short> (address_family);
00388 #ifdef ACE_HAS_SOCKADDR_IN_SIN_LEN
00389   this->inet_addr_.in4_.sin_len = sizeof (this->inet_addr_.in4_);
00390 #endif
00391   struct in_addr addrv4;
00392   if (ACE_OS::inet_aton (host_name,
00393                          &addrv4) == 1)
00394     return this->set (port_number,
00395                       encode ? ACE_NTOHL (addrv4.s_addr) : addrv4.s_addr,
00396                       encode);
00397   else
00398     {
00399 #  if defined (ACE_VXWORKS) && defined (ACE_LACKS_GETHOSTBYNAME)
00400       hostent *hp = ACE_OS::gethostbyname (host_name);
00401 #  else
00402       hostent hentry;
00403       ACE_HOSTENT_DATA buf;
00404       int h_error = 0;  // Not the same as errno!
00405 
00406       hostent *hp = ACE_OS::gethostbyname_r (host_name, &hentry,
00407                                              buf, &h_error);
00408       if (hp == 0)
00409         errno = h_error;
00410 #  endif /* ACE_VXWORKS */
00411 
00412       if (hp == 0)
00413         {
00414           return -1;
00415         }
00416       else
00417         {
00418           (void) ACE_OS::memcpy ((void *) &addrv4.s_addr,
00419                                  hp->h_addr,
00420                                  hp->h_length);
00421           return this->set (port_number,
00422                             encode ? ACE_NTOHL (addrv4.s_addr) : addrv4.s_addr,
00423                             encode);
00424         }
00425     }
00426 #endif /* ACE_HAS_IPV6 */
00427 }

int ACE_INET_Addr::set ( const ACE_INET_Addr sa  ) 

Initializes from another ACE_INET_Addr.

Definition at line 168 of file INET_Addr.cpp.

00169 {
00170   ACE_TRACE ("ACE_INET_Addr::set");
00171 
00172   if (sa.get_type () == AF_ANY)
00173     // Ugh, this is really a base class, so don't copy it.
00174     ACE_OS::memset (&this->inet_addr_, 0, sizeof (this->inet_addr_));
00175   else
00176     {
00177       // It's ok to make the copy.
00178       ACE_OS::memcpy (&this->inet_addr_,
00179                       &sa.inet_addr_,
00180                       sa.get_size ());
00181 
00182       this->set_type (sa.get_type());
00183       this->set_size (sa.get_size());
00184     }
00185 
00186   return 0;
00187 }

void ACE_INET_Addr::set_addr ( void *  addr,
int  len,
int  map 
) [virtual]

Set a pointer to the address.

Definition at line 609 of file INET_Addr.cpp.

00610 {
00611   ACE_TRACE ("ACE_INET_Addr::set_addr");
00612   struct sockaddr_in *getfamily = static_cast<struct sockaddr_in *> (addr);
00613 
00614   if (getfamily->sin_family == AF_INET)
00615     {
00616 #if defined (ACE_HAS_IPV6)
00617       if (map)
00618         this->set_type (AF_INET6);
00619       else
00620 #endif /* ACE_HAS_IPV6 */
00621         this->set_type (AF_INET);
00622       this->set_port_number (getfamily->sin_port, 0);
00623       this->set_address (reinterpret_cast<const char*> (&getfamily->sin_addr),
00624                          sizeof (getfamily->sin_addr),
00625                          0, map);
00626     }
00627 #if defined (ACE_HAS_IPV6)
00628   else if (getfamily->sin_family == AF_INET6)
00629     {
00630       struct sockaddr_in6 *in6 = static_cast<struct sockaddr_in6*> (addr);
00631       this->set_port_number (in6->sin6_port, 0);
00632       this->set_address (reinterpret_cast<const char*> (&in6->sin6_addr),
00633                          sizeof (in6->sin6_addr),
00634                          0);
00635       this->inet_addr_.in6_.sin6_scope_id = in6->sin6_scope_id;
00636     }
00637 #endif // ACE_HAS_IPV6
00638 }

void ACE_INET_Addr::set_addr ( void *  addr,
int  len 
) [virtual]

Set a pointer to the address.

Reimplemented from ACE_Addr.

Definition at line 602 of file INET_Addr.cpp.

00603 {
00604   this->set_addr (addr, len, 0);
00605 }

int ACE_INET_Addr::set_address ( const char *  ip_addr,
int  len,
int  encode = 1,
int  map = 0 
)

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. If map is non-zero, IPv6 support has been compiled in, and ip_addr is an IPv4 address, then this address is set to the IPv4-mapped IPv6 address of it.

Definition at line 917 of file INET_Addr.cpp.

00921 {
00922   ACE_TRACE ("ACE_INET_Addr::set_address");
00923   // This is really intended for IPv4. If the object is IPv4, or the type
00924   // hasn't been set but it's a 4-byte address, go ahead. If this is an
00925   // IPv6 object and <encode> is requested, refuse.
00926   if (encode && len != 4)
00927     {
00928       errno = EAFNOSUPPORT;
00929       return -1;
00930     }
00931 
00932   if (len == 4)
00933     {
00934       ACE_UINT32 ip4 = *reinterpret_cast<const ACE_UINT32 *> (ip_addr);
00935       if (encode)
00936         ip4 = ACE_HTONL (ip4);
00937 
00938 
00939       if (this->get_type () == AF_INET && map == 0) {
00940         this->base_set (AF_INET, sizeof (this->inet_addr_.in4_));
00941 #ifdef ACE_HAS_SOCKADDR_IN_SIN_LEN
00942         this->inet_addr_.in4_.sin_len = sizeof (this->inet_addr_.in4_);
00943 #endif
00944         this->inet_addr_.in4_.sin_family = AF_INET;
00945         this->set_size (sizeof (this->inet_addr_.in4_));
00946         ACE_OS::memcpy (&this->inet_addr_.in4_.sin_addr,
00947                         &ip4,
00948                         len);
00949       }
00950 #if defined (ACE_HAS_IPV6)
00951       else if (map == 0)
00952         {
00953           // this->set_type (AF_INET);
00954           this->base_set (AF_INET, sizeof (this->inet_addr_.in4_));
00955 #ifdef ACE_HAS_SOCKADDR_IN_SIN_LEN
00956           this->inet_addr_.in4_.sin_len = sizeof (this->inet_addr_.in4_);
00957 #endif
00958           this->inet_addr_.in4_.sin_family = AF_INET;
00959           this->set_size (sizeof (this->inet_addr_.in4_));
00960           ACE_OS::memcpy (&this->inet_addr_.in4_.sin_addr,
00961                           &ip4, len);
00962         }
00963       // If given an IPv4 address to copy to an IPv6 object, map it to
00964       // an IPv4-mapped IPv6 address.
00965       else
00966         {
00967           this->base_set (AF_INET6, sizeof (this->inet_addr_.in6_));
00968 #ifdef ACE_HAS_SOCKADDR_IN6_SIN6_LEN
00969           this->inet_addr_.in6_.sin6_len = sizeof (this->inet_addr_.in6_);
00970 #endif
00971           this->inet_addr_.in6_.sin6_family = AF_INET6;
00972           this->set_size (sizeof (this->inet_addr_.in6_));
00973           if (ip4 == ACE_HTONL (INADDR_ANY))
00974             {
00975               in6_addr const ip6 = in6addr_any;
00976               ACE_OS::memcpy (&this->inet_addr_.in6_.sin6_addr,
00977                               &ip6,
00978                               sizeof (ip6));
00979               return 0;
00980             }
00981 
00982           // Build up a 128 bit address.  An IPv4-mapped IPv6 address
00983           // is defined as 0:0:0:0:0:ffff:IPv4_address.  This is defined
00984           // in RFC 1884 */
00985           ACE_OS::memset (&this->inet_addr_.in6_.sin6_addr, 0, 16);
00986           this->inet_addr_.in6_.sin6_addr.s6_addr[10] =
00987             this->inet_addr_.in6_.sin6_addr.s6_addr[11] = 0xff;
00988           ACE_OS::memcpy
00989             (&this->inet_addr_.in6_.sin6_addr.s6_addr[12], &ip4, 4);
00990         }
00991 #endif /* ACE_HAS_IPV6 */
00992       return 0;
00993     }   /* end if (len == 4) */
00994 #if defined (ACE_HAS_IPV6)
00995   else if (len == 16)
00996     {
00997       if (this->get_type () != PF_INET6)
00998         {
00999           errno = EAFNOSUPPORT;
01000           return -1;
01001         }
01002       // We protect ourselves up above so IPv6 must be possible here.
01003       this->base_set (AF_INET6, sizeof (this->inet_addr_.in6_));
01004       this->inet_addr_.in6_.sin6_family = AF_INET6;
01005 #ifdef ACE_HAS_SOCKADDR_IN6_SIN6_LEN
01006       this->inet_addr_.in6_.sin6_len = sizeof (this->inet_addr_.in6_);
01007 #endif
01008       ACE_OS::memcpy (&this->inet_addr_.in6_.sin6_addr, ip_addr, len);
01009 
01010       return 0;
01011     } /* end len == 16 */
01012 #endif /* ACE_HAS_IPV6 */
01013 
01014   // Here with an unrecognized length.
01015   errno = EAFNOSUPPORT;
01016   return -1;
01017 
01018 }

void ACE_INET_Addr::set_port_number ( u_short  port_number,
int  encode = 1 
)

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.

Reimplemented in ACE_Multihomed_INET_Addr.

Definition at line 805 of file INET_Addr.cpp.

00807 {
00808   ACE_TRACE ("ACE_INET_Addr::set_port_number");
00809 
00810   if (encode)
00811     port_number = ACE_HTONS (port_number);
00812 
00813 #if defined (ACE_HAS_IPV6)
00814   if (this->get_type () == AF_INET6)
00815     this->inet_addr_.in6_.sin6_port = port_number;
00816   else
00817 #endif /* ACE_HAS_IPV6 */
00818   this->inet_addr_.in4_.sin_port = port_number;
00819 }

int ACE_INET_Addr::string_to_addr ( const char  address[],
int  address_family = AF_UNSPEC 
) [virtual]

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 192 of file INET_Addr.cpp.

00193 {
00194   ACE_TRACE ("ACE_INET_Addr::string_to_addr");
00195   int result;
00196   char *ip_buf = 0;
00197   char *ip_addr = 0;
00198 
00199   // Need to make a duplicate since we'll be overwriting the string.
00200   ACE_ALLOCATOR_RETURN (ip_buf,
00201                         ACE_OS::strdup (s),
00202                         -1);
00203   ip_addr = ip_buf;
00204   // We use strrchr because of IPv6 addresses.
00205   char *port_p = ACE_OS::strrchr (ip_addr, ':');
00206 #if defined (ACE_HAS_IPV6)
00207   // Check for extended IPv6 format : '[' <ipv6 address> ']' ':' <port>
00208   if (ip_addr[0] == '[')
00209     {
00210       // find closing bracket
00211       char *cp_pos = ACE_OS::strchr (ip_addr, ']');
00212       // check for port separator after closing bracket
00213       // if not found leave it, error will come later
00214       if (cp_pos)
00215         {
00216           *cp_pos = '\0'; // blank out ']'
00217           ++ip_addr; // skip over '['
00218           if (cp_pos[1] == ':')
00219             port_p = cp_pos + 1;
00220           else
00221             port_p = cp_pos; // leads to error on missing port
00222         }
00223     }
00224 #endif /* ACE_HAS_IPV6 */
00225 
00226   if (port_p == 0) // Assume it's a port number.
00227     {
00228       char *endp = 0;
00229       long const port = ACE_OS::strtol (ip_addr, &endp, 10);
00230 
00231       if (*endp == '\0')    // strtol scanned the entire string - all digits
00232         {
00233           if (port < 0 || port > ACE_MAX_DEFAULT_PORT)
00234             result = -1;
00235           else
00236             result = this->set (u_short (port), ACE_UINT32 (INADDR_ANY));
00237         }
00238       else // port name
00239         result = this->set (ip_addr, ACE_UINT32 (INADDR_ANY));
00240     }
00241   else
00242     {
00243       *port_p = '\0'; ++port_p; // skip over ':'
00244 
00245       char *endp = 0;
00246       long port = ACE_OS::strtol (port_p, &endp, 10);
00247 
00248       if (*endp == '\0')    // strtol scanned the entire string - all digits
00249         {
00250           if (port < 0 || port > ACE_MAX_DEFAULT_PORT)
00251             result = -1;
00252           else
00253             result = this->set (u_short (port), ip_addr, 1, address_family);
00254         }
00255       else
00256         result = this->set (port_p, ip_addr);
00257     }
00258 
00259   ACE_OS::free (ACE_MALLOC_T (ip_buf));
00260   return result;
00261 }


Member Data Documentation

Declare the dynamic allocation hooks.

Reimplemented from ACE_Addr.

Definition at line 356 of file INET_Addr.h.

Definition at line 376 of file INET_Addr.h.

union { ... } ACE_INET_Addr::inet_addr_ [private]

Underlying representation. This union uses the knowledge that the two structures share the first member, sa_family (as all sockaddr structures do).


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Sat Nov 21 23:16:49 2009 for ACE by  doxygen 1.6.1