diff options
Diffstat (limited to 'ACE/ace/INET_Addr.cpp')
-rw-r--r-- | ACE/ace/INET_Addr.cpp | 156 |
1 files changed, 50 insertions, 106 deletions
diff --git a/ACE/ace/INET_Addr.cpp b/ACE/ace/INET_Addr.cpp index b9186da8c2c..1c422fdb899 100644 --- a/ACE/ace/INET_Addr.cpp +++ b/ACE/ace/INET_Addr.cpp @@ -152,31 +152,11 @@ ACE_INET_Addr::hash (void) const return this->get_ip_address () + this->get_port_number (); } -bool -ACE_INET_Addr::next (void) -{ - if (this->inet_addrs_.empty () || - this->inet_addrs_iter_ == this->inet_addrs_.end ()) - return false; - - union ip46 next_a = *this->inet_addrs_iter_++; - this->set_addr (&next_a, sizeof (next_a)); - return true; -} - -void -ACE_INET_Addr::reset (void) -{ - this->inet_addrs_iter_ = this->inet_addrs_.begin (); - this->next (); - return; -} - ACE_INET_Addr::ACE_INET_Addr (void) : ACE_Addr (determine_type (), sizeof (inet_addr_)) { // ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); - this->reset_i (); + this->reset (); } int @@ -196,8 +176,6 @@ ACE_INET_Addr::set (const ACE_INET_Addr &sa) this->set_type (sa.get_type()); this->set_size (sa.get_size()); - this->inet_addrs_ = sa.inet_addrs_; - this->reset (); } return 0; @@ -288,7 +266,7 @@ ACE_INET_Addr::ACE_INET_Addr (const char address[], int address_family) : ACE_Addr (determine_type (), sizeof (inet_addr_)) { ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); - this->reset_i (); + this->reset (); this->set (address, address_family); } @@ -297,7 +275,7 @@ ACE_INET_Addr::ACE_INET_Addr (const wchar_t address[], int address_family) : ACE_Addr (determine_type (), sizeof (inet_addr_)) { ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); - this->reset_i (); + this->reset (); this->set (address, address_family); } @@ -309,7 +287,7 @@ ACE_INET_Addr::ACE_INET_Addr (const ACE_INET_Addr &sa) : ACE_Addr (sa.get_type (), sa.get_size()) { ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); - this->reset_i (); + this->reset (); this->set (sa); } @@ -376,22 +354,15 @@ ACE_INET_Addr::set (u_short port_number, { if (hp != 0) { + struct sockaddr_in6 v6; + ACE_OS::memset (&v6, 0, sizeof (v6)); + v6.sin6_family = AF_INET6; + (void) ACE_OS::memcpy ((void *) &v6.sin6_addr, + hp->h_addr, + hp->h_length); this->set_type (hp->h_addrtype); - for (size_t i = 0; hp->h_addr_list[i]; ++i) - { - union ip46 next_addr; - struct sockaddr_in6 *next_addr_in6 = (struct sockaddr_in6 *)&next_addr.in6_; - (void) ACE_OS::memset (&next_addr, sizeof (next_addr), 0); - next_addr_in6->sin6_family = AF_INET6; - next_addr_in6->sin6_port = - encode ? ACE_NTOHS (port_number) : port_number; - (void) ACE_OS::memcpy ((void *) &next_addr_in6->sin6_addr, - hp->h_addr_list[i], - hp->h_length); - this->inet_addrs_.push_back (next_addr); - } - this->reset (); - + this->set_addr (&v6, hp->h_length); + this->set_port_number (port_number, encode); return 0; } } @@ -400,35 +371,16 @@ ACE_INET_Addr::set (u_short port_number, return -1; # else struct addrinfo hints; - struct addrinfo *res = 0, *curr = 0; + struct addrinfo *res = 0; int error = 0; ACE_OS::memset (&hints, 0, sizeof (hints)); hints.ai_family = AF_INET6; if ((error = ::getaddrinfo (host_name, 0, &hints, &res)) == 0) { this->set_type (res->ai_family); - for (curr = res; curr; curr = curr->ai_next) - { - union ip46 next_addr; - if (curr->ai_family == AF_INET6) - { - ACE_OS::memcpy (&next_addr.in6_, - curr->ai_addr, - curr->ai_addrlen); - next_addr.in6_.sin6_port = - encode ? ACE_NTOHS (port_number) : port_number; - } - else - { - ACE_OS::memcpy (&next_addr.in4_, - curr->ai_addr, - curr->ai_addrlen); - next_addr.in4_.sin_port = - encode ? ACE_NTOHS (port_number) : port_number; - } - this->inet_addrs_.push_back (next_addr); - } - this->reset (); + this->set_addr (res->ai_addr, + ACE_Utils::truncate_cast<int>(res->ai_addrlen)); + this->set_port_number (port_number, encode); ::freeaddrinfo (res); return 0; } @@ -454,40 +406,34 @@ ACE_INET_Addr::set (u_short port_number, struct in_addr addrv4; if (ACE_OS::inet_aton (host_name, &addrv4) == 1) + return this->set (port_number, + encode ? ACE_NTOHL (addrv4.s_addr) : addrv4.s_addr, + encode); + else { - this->inet_addrs_iter_ = this->inet_addrs_.end (); - return this->set (port_number, - encode ? ACE_NTOHL (addrv4.s_addr) : addrv4.s_addr, - encode); - } - - hostent hentry; - ACE_HOSTENT_DATA buf; - int h_error = 0; // Not the same as errno! + hostent hentry; + ACE_HOSTENT_DATA buf; + int h_error = 0; // Not the same as errno! - hostent *hp = ACE_OS::gethostbyname_r (host_name, &hentry, - buf, &h_error); - if (hp == 0) - { - errno = h_error; - return -1; - } + hostent *hp = ACE_OS::gethostbyname_r (host_name, &hentry, + buf, &h_error); + if (hp == 0) + errno = h_error; - this->set_type (hp->h_addrtype); - for (size_t i = 0; hp->h_addr_list[i]; ++i) - { - union ip46 next_addr; - struct sockaddr_in *next_addr_in = (struct sockaddr_in *)&next_addr.in4_; - (void) ACE_OS::memset (&next_addr, sizeof (next_addr), 0); - next_addr_in->sin_family = AF_INET; - next_addr_in->sin_port = encode ? ACE_NTOHS (port_number) : port_number; - (void) ACE_OS::memcpy ((void *) &next_addr_in->sin_addr, - hp->h_addr_list[i], - hp->h_length); - this->inet_addrs_.push_back (next_addr); + if (hp == 0) + { + return -1; + } + else + { + (void) ACE_OS::memcpy ((void *) &addrv4.s_addr, + hp->h_addr, + hp->h_length); + return this->set (port_number, + encode ? ACE_NTOHL (addrv4.s_addr) : addrv4.s_addr, + encode); + } } - this->reset (); - return 0; } // Helper function to get a port number from a port name. @@ -663,18 +609,17 @@ ACE_INET_Addr::get_addr (void) const } void -ACE_INET_Addr::set_addr (const void *addr, int len) +ACE_INET_Addr::set_addr (void *addr, int len) { this->set_addr (addr, len, 0); } // Set a pointer to the address. void -ACE_INET_Addr::set_addr (const void *addr, int /* len */, int map) +ACE_INET_Addr::set_addr (void *addr, int /* len */, int map) { ACE_TRACE ("ACE_INET_Addr::set_addr"); - const struct sockaddr_in *getfamily = - static_cast<const struct sockaddr_in *> (addr); + struct sockaddr_in *getfamily = static_cast<struct sockaddr_in *> (addr); if (getfamily->sin_family == AF_INET) { @@ -692,8 +637,7 @@ ACE_INET_Addr::set_addr (const void *addr, int /* len */, int map) #if defined (ACE_HAS_IPV6) else if (getfamily->sin_family == AF_INET6) { - const struct sockaddr_in6 *in6 = - static_cast<const struct sockaddr_in6*> (addr); + struct sockaddr_in6 *in6 = static_cast<struct sockaddr_in6*> (addr); this->set_port_number (in6->sin6_port, 0); this->set_address (reinterpret_cast<const char*> (&in6->sin6_addr), sizeof (in6->sin6_addr), @@ -709,7 +653,7 @@ ACE_INET_Addr::ACE_INET_Addr (const sockaddr_in *addr, int len) : ACE_Addr (determine_type (), sizeof (inet_addr_)) { ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); - this->reset_i (); + this->reset (); this->set (addr, len); } @@ -720,7 +664,7 @@ ACE_INET_Addr::ACE_INET_Addr (u_short port_number, : ACE_Addr (determine_type (), sizeof (inet_addr_)) { ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); - this->reset_i (); + this->reset (); if (this->set (port_number, inet_address) == -1) ACELIB_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), @@ -736,7 +680,7 @@ ACE_INET_Addr::ACE_INET_Addr (const char port_name[], : ACE_Addr (determine_type (), sizeof (inet_addr_)) { ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); - this->reset_i (); + this->reset (); if (this->set (port_name, host_name, protocol) == -1) @@ -751,7 +695,7 @@ ACE_INET_Addr::ACE_INET_Addr (const wchar_t port_name[], : ACE_Addr (determine_type (), sizeof (inet_addr_)) { ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); - this->reset_i (); + this->reset (); if (this->set (port_name, host_name, protocol) == -1) @@ -768,7 +712,7 @@ ACE_INET_Addr::ACE_INET_Addr (const char port_name[], : ACE_Addr (determine_type (), sizeof (inet_addr_)) { ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); - this->reset_i (); + this->reset (); if (this->set (port_name, ACE_HTONL (inet_address), protocol) == -1) @@ -783,7 +727,7 @@ ACE_INET_Addr::ACE_INET_Addr (const wchar_t port_name[], : ACE_Addr (determine_type (), sizeof (inet_addr_)) { ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr"); - this->reset_i (); + this->reset (); if (this->set (port_name, ACE_HTONL (inet_address), protocol) == -1) |