summaryrefslogtreecommitdiff
path: root/ace/INET_Addr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ace/INET_Addr.cpp')
-rw-r--r--ace/INET_Addr.cpp68
1 files changed, 21 insertions, 47 deletions
diff --git a/ace/INET_Addr.cpp b/ace/INET_Addr.cpp
index 78e0557c9a5..420172707af 100644
--- a/ace/INET_Addr.cpp
+++ b/ace/INET_Addr.cpp
@@ -22,8 +22,6 @@ ACE_RCSID (ace,
INET_Addr,
"$Id$")
-ACE_BEGIN_VERSIONED_NAMESPACE_DECL
-
ACE_ALLOC_HOOK_DEFINE(ACE_INET_Addr)
// Transform the current address into string format.
@@ -37,10 +35,9 @@ ACE_INET_Addr::addr_to_string (ACE_TCHAR s[],
// XXX Can we (should we) include the scope id for IPv6 addresses?
- size_t const total_len =
- (ipaddr_format == 0
- ? ACE_OS::strlen (this->get_host_name ())
- : ACE_OS::strlen (this->get_host_addr ()))
+ size_t total_len = (ipaddr_format == 0 ?
+ ACE_OS::strlen (this->get_host_name ()) :
+ ACE_OS::strlen (this->get_host_addr ()))
+ ACE_OS::strlen ("65536") // Assume the max port number.
+ sizeof (':')
+ sizeof ('\0'); // For trailing '\0'.
@@ -51,7 +48,7 @@ ACE_INET_Addr::addr_to_string (ACE_TCHAR s[],
{
ACE_OS::sprintf (s,
ACE_LIB_TEXT ("%s:%d"),
- ACE_TEXT_CHAR_TO_TCHAR (ipaddr_format == 0
+ ACE_TEXT_TO_TCHAR_IN (ipaddr_format == 0
? this->get_host_name ()
: this->get_host_addr ()),
this->get_port_number ());
@@ -114,7 +111,7 @@ ACE_INET_Addr::hash (void) const
}
ACE_INET_Addr::ACE_INET_Addr (void)
- : ACE_Addr (this->determine_type (), sizeof (inet_addr_))
+ : ACE_Addr (this->determine_type(), sizeof (inet_addr_))
{
// ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
this->reset ();
@@ -184,7 +181,7 @@ ACE_INET_Addr::string_to_addr (const char s[])
char *endp = 0;
u_short port =
static_cast<u_short> (ACE_OS::strtol (ip_addr, &endp, 10));
- if (*endp == '\0') // strtol scanned the entire string - all digits
+ if (port > 0 && *endp == '\0')
result = this->set (port, ACE_UINT32 (INADDR_ANY));
else // port name
result = this->set (ip_addr, ACE_UINT32 (INADDR_ANY));
@@ -195,7 +192,7 @@ ACE_INET_Addr::string_to_addr (const char s[])
char *endp = 0;
u_short port = static_cast<u_short> (ACE_OS::strtol (port_p, &endp, 10));
- if (*endp == '\0') // strtol scanned the entire string - all digits
+ if (port > 0 && *endp == '\0')
result = this->set (port, ip_addr);
else
result = this->set (port_p, ip_addr);
@@ -220,7 +217,6 @@ ACE_INET_Addr::ACE_INET_Addr (const char address[])
this->set (address);
}
-#if defined (ACE_HAS_WCHAR)
ACE_INET_Addr::ACE_INET_Addr (const wchar_t address[])
: ACE_Addr (this->determine_type(), sizeof (inet_addr_))
{
@@ -229,8 +225,6 @@ ACE_INET_Addr::ACE_INET_Addr (const wchar_t address[])
this->set (address);
}
-#endif /* ACE_HAS_WCHAR */
-
// Copy constructor.
ACE_INET_Addr::ACE_INET_Addr (const ACE_INET_Addr &sa)
@@ -313,7 +307,7 @@ ACE_INET_Addr::set (u_short port_number,
// IPv6 not supported... insure the family is set to IPv4
address_family = AF_INET;
this->set_type (address_family);
- this->inet_addr_.in4_.sin_family = static_cast<short> (address_family);
+ this->inet_addr_.in4_.sin_family = address_family;
struct in_addr addrv4;
if (ACE_OS::inet_aton (host_name,
&addrv4) == 1)
@@ -322,7 +316,7 @@ ACE_INET_Addr::set (u_short port_number,
encode);
else
{
-# if (defined (ACE_VXWORKS) && defined (ACE_LACKS_GETHOSTBYNAME)) || defined (CHORUS)
+# if defined (VXWORKS) || defined (CHORUS)
hostent *hp = ACE_OS::gethostbyname (host_name);
# else
hostent hentry;
@@ -331,7 +325,7 @@ ACE_INET_Addr::set (u_short port_number,
hostent *hp = ACE_OS::gethostbyname_r (host_name, &hentry,
buf, &h_error);
-# endif /* ACE_VXWORKS */
+# endif /* VXWORKS */
if (hp == 0)
{
@@ -411,7 +405,7 @@ ACE_INET_Addr::set (const char port_name[],
int address_family = PF_UNSPEC;
# if defined (ACE_HAS_IPV6)
- if (ACE_OS::strcmp (ACE_TEXT_CHAR_TO_TCHAR(protocol), ACE_LIB_TEXT ("tcp6")) == 0)
+ if (ACE_OS::strcmp (ACE_TEXT_TO_TCHAR_IN(protocol), ACE_LIB_TEXT ("tcp6")) == 0)
address_family = AF_INET6;
# endif /* ACE_HAS_IPV6 */
@@ -463,12 +457,11 @@ ACE_INET_Addr::ACE_INET_Addr (u_short port_number,
#else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr: %p\n"),
- ACE_TEXT_CHAR_TO_TCHAR ((host_name == 0) ?
+ ACE_TEXT_TO_TCHAR_IN ((host_name == 0) ?
"<unknown>" : host_name)));
#endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */
}
-#if defined (ACE_HAS_WCHAR)
ACE_INET_Addr::ACE_INET_Addr (u_short port_number,
const wchar_t host_name[],
int address_family)
@@ -489,12 +482,11 @@ ACE_INET_Addr::ACE_INET_Addr (u_short port_number,
#else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr: %p\n"),
- ACE_TEXT_WCHAR_TO_TCHAR ((host_name == 0) ?
+ ACE_TEXT_TO_TCHAR_IN ((host_name == 0) ?
ACE_TEXT_WIDE ("<unknown>") :
host_name)));
#endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */
}
-#endif /* ACE_HAS_WCHAR */
// Creates a ACE_INET_Addr from a sockaddr_in structure.
@@ -617,7 +609,6 @@ ACE_INET_Addr::ACE_INET_Addr (const char port_name[],
ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr")));
}
-#if defined (ACE_HAS_WCHAR)
ACE_INET_Addr::ACE_INET_Addr (const wchar_t port_name[],
const wchar_t host_name[],
const wchar_t protocol[])
@@ -631,7 +622,6 @@ ACE_INET_Addr::ACE_INET_Addr (const wchar_t port_name[],
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr")));
}
-#endif /* ACE_HAS_WCHAR */
// Creates a ACE_INET_Addr from a PORT_NAME and an Internet address.
@@ -649,7 +639,6 @@ ACE_INET_Addr::ACE_INET_Addr (const char port_name[],
ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr")));
}
-#if defined (ACE_HAS_WCHAR)
ACE_INET_Addr::ACE_INET_Addr (const wchar_t port_name[],
ACE_UINT32 inet_address,
const wchar_t protocol[])
@@ -663,7 +652,6 @@ ACE_INET_Addr::ACE_INET_Addr (const wchar_t port_name[],
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr")));
}
-#endif /* ACE_HAS_WCHAR */
ACE_INET_Addr::~ACE_INET_Addr (void)
{
@@ -702,7 +690,6 @@ ACE_INET_Addr::get_host_name (char hostname[],
return result;
}
-#if defined (ACE_HAS_WCHAR)
int
ACE_INET_Addr::get_host_name (wchar_t hostname[],
size_t len) const
@@ -720,12 +707,10 @@ ACE_INET_Addr::get_host_name (wchar_t hostname[],
// And copy it over, if successful
if (result == 0)
- ACE_OS::strcpy (hostname,
- ACE_Ascii_To_Wide (char_hostname).wchar_rep ());
+ ACE_OS::string_copy( hostname, char_hostname, MAXHOSTNAMELEN + 1 );
return result;
}
-#endif /* ACE_HAS_WCHAR */
// Return the character representation of the hostname.
@@ -782,7 +767,7 @@ ACE_INET_Addr::get_host_name_i (char hostname[], size_t len) const
}
else
{
-#if defined (ACE_VXWORKS) && defined (ACE_LACKS_GETHOSTBYADDR)
+#if defined (VXWORKS)
ACE_UNUSED_ARG (len);
int error =
::hostGetByAddr ((int) this->inet_addr_.in4_.sin_addr.s_addr,
@@ -831,7 +816,7 @@ ACE_INET_Addr::get_host_name_i (char hostname[], size_t len) const
ACE_OS::strcpy (hostname, hp->h_name);
return 0;
-#endif /* ACE_VXWORKS */
+#endif /* VXWORKS */
}
}
@@ -859,9 +844,6 @@ int ACE_INET_Addr::set_address (const char *ip_addr,
if (this->get_type () == AF_INET && map == 0) {
this->base_set (AF_INET, sizeof (this->inet_addr_.in4_));
-#ifdef ACE_HAS_SOCKADDR_IN_SIN_LEN
- this->inet_addr_.in4_.sin_len = sizeof (this->inet_addr_.in4_);
-#endif
this->inet_addr_.in4_.sin_family = AF_INET;
this->set_size (sizeof (this->inet_addr_.in4_));
ACE_OS::memcpy (&this->inet_addr_.in4_.sin_addr,
@@ -873,9 +855,6 @@ int ACE_INET_Addr::set_address (const char *ip_addr,
{
// this->set_type (AF_INET);
this->base_set (AF_INET, sizeof (this->inet_addr_.in4_));
-#ifdef ACE_HAS_SOCKADDR_IN_SIN_LEN
- this->inet_addr_.in4_.sin_len = sizeof (this->inet_addr_.in4_);
-#endif
this->inet_addr_.in4_.sin_family = AF_INET;
this->set_size (sizeof (this->inet_addr_.in4_));
ACE_OS::memcpy (&this->inet_addr_.in4_.sin_addr,
@@ -886,9 +865,6 @@ int ACE_INET_Addr::set_address (const char *ip_addr,
else
{
this->base_set (AF_INET6, sizeof (this->inet_addr_.in6_));
-#ifdef ACE_HAS_SOCKADDR_IN6_SIN6_LEN
- this->inet_addr_.in6_.sin6_len = sizeof (this->inet_addr_.in6_);
-#endif
this->inet_addr_.in6_.sin6_family = AF_INET6;
this->set_size (sizeof (this->inet_addr_.in6_));
if (ip4 == INADDR_ANY)
@@ -1030,7 +1006,7 @@ ACE_INET_Addr::get_host_addr (char *dst, int size) const
}
#endif /* ACE_HAS_IPV6 */
-#if defined (ACE_VXWORKS)
+#if defined (VXWORKS)
ACE_UNUSED_ARG (dst);
ACE_UNUSED_ARG (size);
@@ -1043,7 +1019,7 @@ ACE_INET_Addr::get_host_addr (char *dst, int size) const
inet_ntoa_b(this->inet_addr_.in4_.sin_addr, ncthis->buf_);
ACE_OS::strsncpy (dst, &buf_[0], size);
return &buf_[0];
-#else /* ACE_VXWORKS */
+#else /* VXWORKS */
char *ch = ACE_OS::inet_ntoa (this->inet_addr_.in4_.sin_addr);
ACE_OS::strsncpy (dst, ch, size);
return ch;
@@ -1059,7 +1035,7 @@ ACE_INET_Addr::get_host_addr (void) const
static char buf[INET6_ADDRSTRLEN];
return this->get_host_addr (buf, INET6_ADDRSTRLEN);
#else /* ACE_HAS_IPV6 */
-# if defined (ACE_VXWORKS)
+# if defined (VXWORKS)
// It would be nice to be able to encapsulate this into
// ACE_OS::inet_ntoa(), but that would lead to either inefficiencies
// on vxworks or lack of thread safety.
@@ -1068,9 +1044,9 @@ ACE_INET_Addr::get_host_addr (void) const
ACE_INET_Addr *ncthis = const_cast<ACE_INET_Addr *> (this);
inet_ntoa_b (this->inet_addr_.in4_.sin_addr, ncthis->buf_);
return &buf_[0];
-# else /* ACE_VXWORKS */
+# else /* VXWORKS */
return ACE_OS::inet_ntoa (this->inet_addr_.in4_.sin_addr);
-# endif /* !ACE_VXWORKS */
+# endif /* !VXWORKS */
#endif /* !ACE_HAS_IPV6 */
}
@@ -1101,5 +1077,3 @@ ACE_INET_Addr::get_ip_address (void) const
#endif /* ACE_HAS_IPV6 */
return ntohl (ACE_UINT32 (this->inet_addr_.in4_.sin_addr.s_addr));
}
-
-ACE_END_VERSIONED_NAMESPACE_DECL