OLD | NEW |
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 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 } | 723 } |
724 } | 724 } |
725 | 725 |
726 int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) { | 726 int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) { |
727 const uint16_t* port_field = GetPortFieldFromSockaddr(address, address_len); | 727 const uint16_t* port_field = GetPortFieldFromSockaddr(address, address_len); |
728 if (!port_field) | 728 if (!port_field) |
729 return -1; | 729 return -1; |
730 return base::NetToHost16(*port_field); | 730 return base::NetToHost16(*port_field); |
731 } | 731 } |
732 | 732 |
| 733 bool IsLocalhostHostname(const std::string& host, bool* isLocalhost6) { |
| 734 std::string lowercased_host = base::StringToLowerASCII(host); |
| 735 if (lowercased_host == "localhost6" || |
| 736 lowercased_host == "localhost6.localdomain6" || |
| 737 lowercased_host == "localhost6." || |
| 738 lowercased_host == "localhost6.localdomain6.") { |
| 739 *isLocalhost6 = true; |
| 740 return true; |
| 741 } |
| 742 |
| 743 if (lowercased_host == "localhost" || |
| 744 lowercased_host == "localhost.localdomain" || |
| 745 lowercased_host == "localhost." || |
| 746 lowercased_host == "localhost.localdomain." || |
| 747 IsLocalhostTLD(lowercased_host)) { |
| 748 *isLocalhost6 = false; |
| 749 return true; |
| 750 } |
| 751 |
| 752 return false; |
| 753 } |
| 754 |
733 bool IsLocalhost(const std::string& host) { | 755 bool IsLocalhost(const std::string& host) { |
734 if (host == "localhost" || host == "localhost.localdomain" || | 756 bool isIPv6; |
735 host == "localhost6" || host == "localhost6.localdomain6" || | 757 if (IsLocalhostHostname(host, &isIPv6)) |
736 IsLocalhostTLD(host)) | |
737 return true; | 758 return true; |
738 | 759 |
739 IPAddressNumber ip_number; | 760 IPAddressNumber ip_number; |
740 if (ParseIPLiteralToNumber(host, &ip_number)) { | 761 if (ParseIPLiteralToNumber(host, &ip_number)) { |
741 size_t size = ip_number.size(); | 762 size_t size = ip_number.size(); |
742 switch (size) { | 763 switch (size) { |
743 case kIPv4AddressSize: { | 764 case kIPv4AddressSize: { |
744 IPAddressNumber localhost_prefix; | 765 IPAddressNumber localhost_prefix; |
745 localhost_prefix.push_back(127); | 766 localhost_prefix.push_back(127); |
746 for (int i = 0; i < 3; ++i) { | 767 for (int i = 0; i < 3; ++i) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 }; | 819 }; |
799 const std::string& host = url.host(); | 820 const std::string& host = url.host(); |
800 for (const char* suffix : kGoogleHostSuffixes) { | 821 for (const char* suffix : kGoogleHostSuffixes) { |
801 if (EndsWith(host, suffix, false)) | 822 if (EndsWith(host, suffix, false)) |
802 return true; | 823 return true; |
803 } | 824 } |
804 return false; | 825 return false; |
805 } | 826 } |
806 | 827 |
807 } // namespace net | 828 } // namespace net |
OLD | NEW |