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

Side by Side Diff: net/base/net_util.cc

Issue 430193002: Wire 'blink::Platform::isHostnameReservedIPAddress()' to 'net::IsReservedIPAddress()'. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 6 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 return AF_UNSPEC; 792 return AF_UNSPEC;
793 case ADDRESS_FAMILY_IPV4: 793 case ADDRESS_FAMILY_IPV4:
794 return AF_INET; 794 return AF_INET;
795 case ADDRESS_FAMILY_IPV6: 795 case ADDRESS_FAMILY_IPV6:
796 return AF_INET6; 796 return AF_INET6;
797 } 797 }
798 NOTREACHED(); 798 NOTREACHED();
799 return AF_UNSPEC; 799 return AF_UNSPEC;
800 } 800 }
801 801
802 bool ParseURLHostnameToNumber(const std::string& hostname,
803 IPAddressNumber* ip_number) {
804 // |hostname| is an already canoncalized hostname, conforming to RFC 3986.
805 // For an IP address, this is defined in Section 3.2.2 of RFC 3986, with
806 // the canonical form for IPv6 addresses defined in Section 4 of RFC 5952.
807 url::Component host_comp(0, hostname.size());
808
809 // If it has a bracket, try parsing it as an IPv6 address.
810 if (hostname[0] == '[') {
811 ip_number->resize(16); // 128 bits.
812 return url::IPv6AddressToNumber(
813 hostname.data(), host_comp, &(*ip_number)[0]);
814 }
815
816 // Otherwise, try IPv4.
817 ip_number->resize(4); // 32 bits.
818 int num_components;
819 url::CanonHostInfo::Family family = url::IPv4AddressToNumber(
820 hostname.data(), host_comp, &(*ip_number)[0], &num_components);
821 return family == url::CanonHostInfo::IPV4;
822 }
823
802 bool ParseIPLiteralToNumber(const std::string& ip_literal, 824 bool ParseIPLiteralToNumber(const std::string& ip_literal,
803 IPAddressNumber* ip_number) { 825 IPAddressNumber* ip_number) {
804 // |ip_literal| could be either a IPv4 or an IPv6 literal. If it contains 826 // |ip_literal| could be either a IPv4 or an IPv6 literal. If it contains
805 // a colon however, it must be an IPv6 address. 827 // a colon however, it must be an IPv6 address.
806 if (ip_literal.find(':') != std::string::npos) { 828 if (ip_literal.find(':') != std::string::npos) {
807 // GURL expects IPv6 hostnames to be surrounded with brackets. 829 // GURL expects IPv6 hostnames to be surrounded with brackets.
808 std::string host_brackets = "[" + ip_literal + "]"; 830 std::string host_brackets = "[" + ip_literal + "]";
809 url::Component host_comp(0, host_brackets.size()); 831 url::Component host_comp(0, host_brackets.size());
810 832
811 // Try parsing the hostname as an IPv6 literal. 833 // Try parsing the hostname as an IPv6 literal.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 } 1032 }
1011 return a1.size() * CHAR_BIT; 1033 return a1.size() * CHAR_BIT;
1012 } 1034 }
1013 1035
1014 unsigned MaskPrefixLength(const IPAddressNumber& mask) { 1036 unsigned MaskPrefixLength(const IPAddressNumber& mask) {
1015 IPAddressNumber all_ones(mask.size(), 0xFF); 1037 IPAddressNumber all_ones(mask.size(), 0xFF);
1016 return CommonPrefixLength(mask, all_ones); 1038 return CommonPrefixLength(mask, all_ones);
1017 } 1039 }
1018 1040
1019 } // namespace net 1041 } // 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