Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1778)

Unified Diff: net/base/net_util.cc

Issue 38001: Implement the PAC js-binding for "myIpAddress()". (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: update unittest for DnsResolve based on new empty string Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util.cc
===================================================================
--- net/base/net_util.cc (revision 10746)
+++ net/base/net_util.cc (working copy)
@@ -991,7 +991,7 @@
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 @@
// 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 @@
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);
}
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698