diff options
author | Phil Mesnier <mesnier_p@ociweb.com> | 2007-01-05 03:48:26 +0000 |
---|---|---|
committer | Phil Mesnier <mesnier_p@ociweb.com> | 2007-01-05 03:48:26 +0000 |
commit | 1dcc308d0e22b1286a1056b4d85b06ddd9b6b55f (patch) | |
tree | 9da8dbbbc1d6b06f57091cbd35a7c52334739816 | |
parent | 6e82a1e15b10ce5903c90cd09c688f7fef210bdd (diff) | |
download | ATCD-1dcc308d0e22b1286a1056b4d85b06ddd9b6b55f.tar.gz |
Fri Jan 5 03:34:00 UTC 2007 Phil Mesnier <mesnier_p@ociweb.com>
-rw-r--r-- | ACE/ChangeLog | 9 | ||||
-rw-r--r-- | ACE/ace/INET_Addr.cpp | 42 |
2 files changed, 35 insertions, 16 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 60d5102c1b6..0bee7d1bc87 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,12 @@ +Fri Jan 5 03:34:00 UTC 2007 Phil Mesnier <mesnier_p@ociweb.com> + + * ace/INET_Addr.cpp: + + Refactored the addr_to_string() method to format numeric IPv6 + addresses using [addr]:port to disambiguate addresses such as + [fe80::1:2:3]:12345. This should be benign as string_to_addr() + already parses [ipv6addr]:port formatted strings. + Fri Jan 5 00:51:22 UTC 2007 Phil Mesnier <mesnier_p@ociweb.com> * ace/INET_Addr.h: diff --git a/ACE/ace/INET_Addr.cpp b/ACE/ace/INET_Addr.cpp index cced1b9b47b..45b7738dbe9 100644 --- a/ACE/ace/INET_Addr.cpp +++ b/ACE/ace/INET_Addr.cpp @@ -36,27 +36,37 @@ ACE_INET_Addr::addr_to_string (ACE_TCHAR s[], ACE_TRACE ("ACE_INET_Addr::addr_to_string"); // XXX Can we (should we) include the scope id for IPv6 addresses? + char hoststr[MAXHOSTNAMELEN+1]; - size_t const 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'. + bool result = false; + if (ipaddr_format == 0) + result = (this->get_host_name (hoststr,MAXHOSTNAMELEN+1) == 0); + else + result = (this->get_host_addr (hoststr,MAXHOSTNAMELEN+1) != 0); - if (size < total_len) + if (!result) return -1; - else + + size_t total_len = + ACE_OS::strlen (hoststr) + + 5 // ACE_OS::strlen ("65535"), Assuming the max port number. + + 1 // sizeof (':'), addr/port sep + + 1; // sizeof ('\0'), terminating NUL + ACE_TCHAR const *format = ACE_LIB_TEXT("%s:%d"); +#if ACE_HAS_IPV6 + if (ACE_OS::strchr(hoststr,':') != 0) { - ACE_OS::sprintf (s, - ACE_LIB_TEXT ("%s:%d"), - ACE_TEXT_CHAR_TO_TCHAR (ipaddr_format == 0 - ? this->get_host_name () - : this->get_host_addr ()), - this->get_port_number ()); - return 0; + total_len += 2; // ACE_OS::strlen ("[]") IPv6 addr frames + format = ACE_LIB_TEXT("[%s]:%d"); } +#endif // ACE_HAS_IPV6 + + if (size < total_len) + return -1; + else + ACE_OS::sprintf (s, format, + ACE_TEXT_CHAR_TO_TCHAR (hoststr), this->get_port_number ()); + return 0; } void |