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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <unicode/ucnv.h> 6 #include <unicode/ucnv.h>
7 #include <unicode/uidna.h> 7 #include <unicode/uidna.h>
8 #include <unicode/ulocdata.h> 8 #include <unicode/ulocdata.h>
9 #include <unicode/uniset.h> 9 #include <unicode/uniset.h>
10 #include <unicode/uscript.h> 10 #include <unicode/uscript.h>
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 984
985 url_parse::ParseAuthority(auth_begin, auth_component, &username_component, 985 url_parse::ParseAuthority(auth_begin, auth_component, &username_component,
986 &password_component, &hostname_component, &port_component); 986 &password_component, &hostname_component, &port_component);
987 987
988 // There shouldn't be a username/password. 988 // There shouldn't be a username/password.
989 if (username_component.is_valid() || password_component.is_valid()) 989 if (username_component.is_valid() || password_component.is_valid())
990 return false; 990 return false;
991 991
992 if (!hostname_component.is_nonempty()) 992 if (!hostname_component.is_nonempty())
993 return false; // Failed parsing. 993 return false; // Failed parsing.
994 994
995 int parsed_port_number = -1; 995 int parsed_port_number = -1;
996 if (port_component.is_nonempty()) { 996 if (port_component.is_nonempty()) {
997 parsed_port_number = url_parse::ParsePort(auth_begin, port_component); 997 parsed_port_number = url_parse::ParsePort(auth_begin, port_component);
998 998
999 // If parsing failed, port_number will be either PORT_INVALID or 999 // If parsing failed, port_number will be either PORT_INVALID or
1000 // PORT_UNSPECIFIED, both of which are negative. 1000 // PORT_UNSPECIFIED, both of which are negative.
1001 if (parsed_port_number < 0) 1001 if (parsed_port_number < 0)
1002 return false; // Failed parsing the port number. 1002 return false; // Failed parsing the port number.
1003 } 1003 }
1004 1004
1005 if (port_component.len == 0) 1005 if (port_component.len == 0)
1006 return false; // Reject inputs like "foo:" 1006 return false; // Reject inputs like "foo:"
1007 1007
1008 // Pass results back to caller. 1008 // Pass results back to caller.
1009 host->assign(auth_begin + hostname_component.begin, hostname_component.len); 1009 host->assign(auth_begin + hostname_component.begin, hostname_component.len);
1010 *port = parsed_port_number; 1010 *port = parsed_port_number;
1011 1011
1012 return true; // Success. 1012 return true; // Success.
1013 } 1013 }
1014 1014
1015 bool GetHostAndPort(const std::string& host_and_port, 1015 bool GetHostAndPort(const std::string& host_and_port,
1016 std::string* host, 1016 std::string* host,
1017 int* port) { 1017 int* port) {
1018 return GetHostAndPort(host_and_port.begin(), host_and_port.end(), host, port); 1018 return GetHostAndPort(host_and_port.begin(), host_and_port.end(), host, port);
1019 } 1019 }
1020 1020
1021 std::string NetAddressToString(const struct addrinfo* net_address) { 1021 std::string NetAddressToString(const struct addrinfo* net_address) {
1022 #if defined(OS_WIN) 1022 #if defined(OS_WIN)
1023 EnsureWinsockInit(); 1023 EnsureWinsockInit();
1024 #endif 1024 #endif
1025 1025
1026 // This buffer is large enough to fit the biggest IPv6 string. 1026 // This buffer is large enough to fit the biggest IPv6 string.
1027 char buffer[INET6_ADDRSTRLEN]; 1027 char buffer[INET6_ADDRSTRLEN];
1028 1028
1029 int result = getnameinfo(net_address->ai_addr, 1029 int result = getnameinfo(net_address->ai_addr,
1030 net_address->ai_addrlen, buffer, sizeof(buffer), NULL, 0, NI_NUMERICHOST); 1030 net_address->ai_addrlen, buffer, sizeof(buffer), NULL, 0, NI_NUMERICHOST);
1031 1031
1032 if (result != 0) { 1032 if (result != 0) {
1033 DLOG(INFO) << "getnameinfo() failed with " << result; 1033 DLOG(INFO) << "getnameinfo() failed with " << result;
1034 return std::string(); 1034 buffer[0] = '\0';
1035 } 1035 }
1036
1037 return std::string(buffer); 1036 return std::string(buffer);
1038 } 1037 }
1039 1038
1039 std::string GetMyHostName() {
1040 #if defined(OS_WIN)
1041 EnsureWinsockInit();
1042 #endif
1043
1044 // Maximum size of 256 is somewhat arbitrary. Mozilla uses a size of 100
1045 // so this should cover the majority of cases.
1046 char buffer[256];
1047 int result = gethostname(buffer, sizeof(buffer));
1048 if (result != 0) {
1049 DLOG(INFO) << "gethostname() failed with " << result;
1050 buffer[0] = '\0';
1051 }
1052 return std::string(buffer);
1053 }
1054
1040 } // namespace net 1055 } // namespace net
OLDNEW
« 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