url_canon_ip.h 2.3 KB

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