| 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 #ifndef NET_BASE_IP_ADDRESS_NUMBER_H_ | 5 #ifndef NET_BASE_IP_ADDRESS_NUMBER_H_ |
| 6 #define NET_BASE_IP_ADDRESS_NUMBER_H_ | 6 #define NET_BASE_IP_ADDRESS_NUMBER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/strings/string_piece.h" |
| 12 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 | 16 |
| 16 // IPAddressNumber is used to represent an IP address's numeric value as an | 17 // IPAddressNumber is used to represent an IP address's numeric value as an |
| 17 // array of bytes, from most significant to least significant. This is the | 18 // array of bytes, from most significant to least significant. This is the |
| 18 // network byte ordering. | 19 // network byte ordering. |
| 19 // | 20 // |
| 20 // IPv4 addresses will have length 4, whereas IPv6 address will have length 16. | 21 // IPv4 addresses will have length 4, whereas IPv6 address will have length 16. |
| 21 typedef std::vector<unsigned char> | 22 typedef std::vector<unsigned char> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 51 // Returns the address as a sequence of bytes in network-byte-order. | 52 // Returns the address as a sequence of bytes in network-byte-order. |
| 52 NET_EXPORT std::string IPAddressToPackedString(const IPAddressNumber& addr); | 53 NET_EXPORT std::string IPAddressToPackedString(const IPAddressNumber& addr); |
| 53 | 54 |
| 54 // Parses a URL-safe IP literal (see RFC 3986, Sec 3.2.2) to its numeric value. | 55 // Parses a URL-safe IP literal (see RFC 3986, Sec 3.2.2) to its numeric value. |
| 55 // Returns true on success, and fills |ip_number| with the numeric value | 56 // Returns true on success, and fills |ip_number| with the numeric value |
| 56 NET_EXPORT bool ParseURLHostnameToNumber(const std::string& hostname, | 57 NET_EXPORT bool ParseURLHostnameToNumber(const std::string& hostname, |
| 57 IPAddressNumber* ip_number); | 58 IPAddressNumber* ip_number); |
| 58 | 59 |
| 59 // Parses an IP address literal (either IPv4 or IPv6) to its numeric value. | 60 // Parses an IP address literal (either IPv4 or IPv6) to its numeric value. |
| 60 // Returns true on success and fills |ip_number| with the numeric value. | 61 // Returns true on success and fills |ip_number| with the numeric value. |
| 61 NET_EXPORT bool ParseIPLiteralToNumber(const std::string& ip_literal, | 62 NET_EXPORT bool ParseIPLiteralToNumber(const base::StringPiece& ip_literal, |
| 62 IPAddressNumber* ip_number); | 63 IPAddressNumber* ip_number); |
| 63 | 64 |
| 64 // Converts an IPv4 address to an IPv4-mapped IPv6 address. | 65 // Converts an IPv4 address to an IPv4-mapped IPv6 address. |
| 65 // For example 192.168.0.1 would be converted to ::ffff:192.168.0.1. | 66 // For example 192.168.0.1 would be converted to ::ffff:192.168.0.1. |
| 66 NET_EXPORT_PRIVATE IPAddressNumber ConvertIPv4NumberToIPv6Number( | 67 NET_EXPORT_PRIVATE IPAddressNumber ConvertIPv4NumberToIPv6Number( |
| 67 const IPAddressNumber& ipv4_number); | 68 const IPAddressNumber& ipv4_number); |
| 68 | 69 |
| 69 // Returns true iff |address| is an IPv4-mapped IPv6 address. | 70 // Returns true iff |address| is an IPv4-mapped IPv6 address. |
| 70 NET_EXPORT_PRIVATE bool IsIPv4Mapped(const IPAddressNumber& address); | 71 NET_EXPORT_PRIVATE bool IsIPv4Mapped(const IPAddressNumber& address); |
| 71 | 72 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // Returns number of matching initial bits between the addresses |a1| and |a2|. | 106 // Returns number of matching initial bits between the addresses |a1| and |a2|. |
| 106 unsigned CommonPrefixLength(const IPAddressNumber& a1, | 107 unsigned CommonPrefixLength(const IPAddressNumber& a1, |
| 107 const IPAddressNumber& a2); | 108 const IPAddressNumber& a2); |
| 108 | 109 |
| 109 // Computes the number of leading 1-bits in |mask|. | 110 // Computes the number of leading 1-bits in |mask|. |
| 110 unsigned MaskPrefixLength(const IPAddressNumber& mask); | 111 unsigned MaskPrefixLength(const IPAddressNumber& mask); |
| 111 | 112 |
| 112 } // namespace net | 113 } // namespace net |
| 113 | 114 |
| 114 #endif // NET_BASE_IP_ADDRESS_NUMBER_H_ | 115 #endif // NET_BASE_IP_ADDRESS_NUMBER_H_ |
| OLD | NEW |