Index: net/base/ip_address.h |
diff --git a/net/base/ip_address.h b/net/base/ip_address.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2ef9526f5484199c5240f60472322b680f56b2df |
--- /dev/null |
+++ b/net/base/ip_address.h |
@@ -0,0 +1,69 @@ |
+// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_BASE_IP_ADDRESS_NET_H_ |
+#define NET_BASE_IP_ADDRESS_NET_H_ |
+ |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/compiler_specific.h" |
+#include "base/strings/string_piece.h" |
+#include "net/base/net_export.h" |
+ |
+namespace net { |
+ |
+class NET_EXPORT IPAddress { |
+ public: |
+ static const size_t kIPv4AddressSize; |
+ static const size_t kIPv6AddressSize; |
+ |
+ // Creates a zero-sized, invalid address. |
+ IPAddress(); |
+ IPAddress(const uint8_t* address, size_t address_len); |
eroman
2015/11/30 22:12:33
Please add a comment explaining this creates a cop
eroman
2015/11/30 22:15:23
By "byte order" I really meant to say "network byt
martijnc
2015/12/01 22:09:34
Done.
|
+ ~IPAddress(); |
+ |
+ // Returns true if the IP has |kIPv4AddressSize| elements. |
+ bool IsIPv4() const; |
+ |
+ // Returns true if the IP has |kIPv6AddressSize| elements. |
+ bool IsIPv6() const; |
+ |
+ // Returns true if an IP address hostname is in a range reserved by the IANA. |
+ // Works with both IPv4 and IPv6 addresses, and only compares against a given |
+ // protocols's reserved ranges. |
+ bool IsReserved() const; |
+ |
+ // Returns true if |ip_address_| is an IPv4-mapped IPv6 address. |
+ bool IsIPv4Mapped() const; |
+ |
+ // The size in bytes of |ip_address_|. |
+ size_t size() const { return ip_address_.size(); } |
+ |
+ // Returns the canonical string representation of an IP address. |
+ // For example: "192.168.0.1" or "::1". |
eroman
2015/11/30 22:12:33
Please also add a mention that it is incorrect to
martijnc
2015/12/01 22:09:34
Done.
|
+ std::string ToString() const; |
+ |
+ // Parses an IP address literal (either IPv4 or IPv6) to its numeric value. |
+ // Returns true on success and fills |ip_address| with the numeric value. |
+ static bool FromIPLiteral(const base::StringPiece& ip_literal, |
+ IPAddress* ip_address) WARN_UNUSED_RESULT; |
+ |
+ // Returns the underlying byte vector. |
+ const std::vector<uint8_t>& bytes() const { return ip_address_; }; |
+ |
+ bool operator==(const IPAddress& that) const; |
+ bool operator<(const IPAddress& that) const; |
+ |
+ private: |
+ friend class IPAddressTest; |
eroman
2015/11/30 22:12:33
Delete, I don't believe this is needed anymore.
martijnc
2015/12/01 22:09:34
Done.
|
+ |
+ // IPv4 addresses will have length kIPv4AddressSize, whereas IPv6 address |
+ // will have length kIPv6AddressSize. |
+ std::vector<uint8_t> ip_address_; |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_BASE_IP_ADDRESS_NET_H_ |