1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef URL_URL_CANON_IP_H_ 6 #define URL_URL_CANON_IP_H_ 7 8 #include "base/component_export.h" 9 #include "url/third_party/mozilla/url_parse.h" 10 #include "url/url_canon.h" 11 12 namespace url { 13 14 // Writes the given IPv4 address to |output|. 15 COMPONENT_EXPORT(URL) 16 void AppendIPv4Address(const unsigned char address[4], CanonOutput* output); 17 18 // Writes the given IPv6 address to |output|. 19 COMPONENT_EXPORT(URL) 20 void AppendIPv6Address(const unsigned char address[16], CanonOutput* output); 21 22 // Converts an IPv4 address to a 32-bit number (network byte order). 23 // 24 // Possible return values: 25 // IPV4 - IPv4 address was successfully parsed. 26 // BROKEN - Input was formatted like an IPv4 address, but overflow occurred 27 // during parsing. 28 // NEUTRAL - Input couldn't possibly be interpreted as an IPv4 address. 29 // It might be an IPv6 address, or a hostname. 30 // 31 // On success, |num_ipv4_components| will be populated with the number of 32 // components in the IPv4 address. 33 COMPONENT_EXPORT(URL) 34 CanonHostInfo::Family IPv4AddressToNumber(const char* spec, 35 const Component& host, 36 unsigned char address[4], 37 int* num_ipv4_components); 38 COMPONENT_EXPORT(URL) 39 CanonHostInfo::Family IPv4AddressToNumber(const char16_t* spec, 40 const Component& host, 41 unsigned char address[4], 42 int* num_ipv4_components); 43 44 // Converts an IPv6 address to a 128-bit number (network byte order), returning 45 // true on success. False means that the input was not a valid IPv6 address. 46 // 47 // NOTE that |host| is expected to be surrounded by square brackets. 48 // i.e. "[::1]" rather than "::1". 49 COMPONENT_EXPORT(URL) 50 bool IPv6AddressToNumber(const char* spec, 51 const Component& host, 52 unsigned char address[16]); 53 COMPONENT_EXPORT(URL) 54 bool IPv6AddressToNumber(const char16_t* spec, 55 const Component& host, 56 unsigned char address[16]); 57 58 } // namespace url 59 60 #endif // URL_URL_CANON_IP_H_ 61