From 50d7d7283db42b531a9df9c6f5a34b8526d4d5b0 Mon Sep 17 00:00:00 2001 From: "ericroman@google.com" Date: Mon, 2 Mar 2009 21:45:18 +0000 Subject: Add js bindings layer for ProxyResolverV8 {"alert()", "dnsResolve()", "myIpAddress" <-- [partial]}. Also adds a utility function to net_util for turning a addrinfo into an IP address string. BUG=2764 Review URL: http://codereview.chromium.org/31009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10730 0039d316-1c4b-4281-b951-d872f2087c98 --- net/base/net_util.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'net/base/net_util.cc') diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 7cee8f1..7527b6c 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -15,7 +15,10 @@ #if defined(OS_WIN) #include #include +#include +#include // Needed for Win2k compat. #elif defined(OS_POSIX) +#include #include #include #endif @@ -40,6 +43,9 @@ #include "googleurl/src/url_parse.h" #include "net/base/escape.h" #include "net/base/net_module.h" +#if defined(OS_WIN) +#include "net/base/winsock_init.h" +#endif #include "net/base/base64.h" #include "unicode/datefmt.h" @@ -1012,4 +1018,23 @@ bool GetHostAndPort(const std::string& host_and_port, return GetHostAndPort(host_and_port.begin(), host_and_port.end(), host, port); } +std::string NetAddressToString(const struct addrinfo* net_address) { +#if defined(OS_WIN) + EnsureWinsockInit(); +#endif + + // This buffer is large enough to fit the biggest IPv6 string. + char buffer[INET6_ADDRSTRLEN]; + + int result = getnameinfo(net_address->ai_addr, + net_address->ai_addrlen, buffer, sizeof(buffer), NULL, 0, NI_NUMERICHOST); + + if (result != 0) { + DLOG(INFO) << "getnameinfo() failed with " << result; + return std::string(); + } + + return std::string(buffer); +} + } // namespace net -- cgit v1.1