summaryrefslogtreecommitdiffstats
path: root/net/base/net_util.cc
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-02 21:45:18 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-02 21:45:18 +0000
commit50d7d7283db42b531a9df9c6f5a34b8526d4d5b0 (patch)
tree6d29abd0b0a82a658a9a526e37279a26a636142e /net/base/net_util.cc
parente97cdd5e81a3f8c3bd735ab1e7d264c36c2c3870 (diff)
downloadchromium_src-50d7d7283db42b531a9df9c6f5a34b8526d4d5b0.zip
chromium_src-50d7d7283db42b531a9df9c6f5a34b8526d4d5b0.tar.gz
chromium_src-50d7d7283db42b531a9df9c6f5a34b8526d4d5b0.tar.bz2
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
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r--net/base/net_util.cc25
1 files changed, 25 insertions, 0 deletions
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 <windows.h>
#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <wspiapi.h> // Needed for Win2k compat.
#elif defined(OS_POSIX)
+#include <netdb.h>
#include <sys/socket.h>
#include <fcntl.h>
#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