diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 21:30:46 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 21:30:46 +0000 |
commit | eba291345caec278ef7b8f2a8c73b8b6c60f7364 (patch) | |
tree | 368f0fd8b38f05fe1d1d447d390823bf4bc0b7b6 /net/base/net_util.cc | |
parent | 2455e073eb458b2ab5a7edbb337781152868b8c0 (diff) | |
download | chromium_src-eba291345caec278ef7b8f2a8c73b8b6c60f7364.zip chromium_src-eba291345caec278ef7b8f2a8c73b8b6c60f7364.tar.gz chromium_src-eba291345caec278ef7b8f2a8c73b8b6c60f7364.tar.bz2 |
Implement the PAC js-binding for "myIpAddress()".
BUG=2764
Review URL: http://codereview.chromium.org/38001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r-- | net/base/net_util.cc | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 7527b6c..b88a3bf 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -991,7 +991,7 @@ bool GetHostAndPort(std::string::const_iterator host_and_port_begin, if (!hostname_component.is_nonempty()) return false; // Failed parsing. - + int parsed_port_number = -1; if (port_component.is_nonempty()) { parsed_port_number = url_parse::ParsePort(auth_begin, port_component); @@ -1008,7 +1008,7 @@ bool GetHostAndPort(std::string::const_iterator host_and_port_begin, // Pass results back to caller. host->assign(auth_begin + hostname_component.begin, hostname_component.len); *port = parsed_port_number; - + return true; // Success. } @@ -1031,9 +1031,24 @@ std::string NetAddressToString(const struct addrinfo* net_address) { if (result != 0) { DLOG(INFO) << "getnameinfo() failed with " << result; - return std::string(); + buffer[0] = '\0'; } + return std::string(buffer); +} +std::string GetMyHostName() { +#if defined(OS_WIN) + EnsureWinsockInit(); +#endif + + // Maximum size of 256 is somewhat arbitrary. Mozilla uses a size of 100 + // so this should cover the majority of cases. + char buffer[256]; + int result = gethostname(buffer, sizeof(buffer)); + if (result != 0) { + DLOG(INFO) << "gethostname() failed with " << result; + buffer[0] = '\0'; + } return std::string(buffer); } |