Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: net/base/ip_address.h

Issue 1692353002: Make IP Address related functions return the empty string when used on an invalid address. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/base/ip_address_number.h » ('j') | net/base/ip_address_number.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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_NET_H_ 5 #ifndef NET_BASE_IP_ADDRESS_NET_H_
6 #define NET_BASE_IP_ADDRESS_NET_H_ 6 #define NET_BASE_IP_ADDRESS_NET_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // Returns true if |ip_address_| is an IPv4-mapped IPv6 address. 62 // Returns true if |ip_address_| is an IPv4-mapped IPv6 address.
63 bool IsIPv4MappedIPv6() const; 63 bool IsIPv4MappedIPv6() const;
64 64
65 // The size in bytes of |ip_address_|. 65 // The size in bytes of |ip_address_|.
66 size_t size() const { return ip_address_.size(); } 66 size_t size() const { return ip_address_.size(); }
67 67
68 // Returns true if the IP is an empty, zero-sized (invalid) address. 68 // Returns true if the IP is an empty, zero-sized (invalid) address.
69 bool empty() const { return ip_address_.empty(); } 69 bool empty() const { return ip_address_.empty(); }
70 70
71 // Returns the canonical string representation of an IP address. 71 // Returns the canonical string representation of an IP address.
72 // For example: "192.168.0.1" or "::1". The IP address must be 72 // For example: "192.168.0.1" or "::1". Returns the empty string when
73 // valid, calling this on an invalid address will result in a crash. 73 // |ip_address_| is invalid.
74 std::string ToString() const; 74 std::string ToString() const;
75 75
76 // Parses an IP address literal (either IPv4 or IPv6) to its numeric value. 76 // Parses an IP address literal (either IPv4 or IPv6) to its numeric value.
77 // Returns true on success and fills |ip_address_| with the numeric value. 77 // Returns true on success and fills |ip_address_| with the numeric value.
78 bool AssignFromIPLiteral(const base::StringPiece& ip_literal) 78 bool AssignFromIPLiteral(const base::StringPiece& ip_literal)
79 WARN_UNUSED_RESULT; 79 WARN_UNUSED_RESULT;
80 80
81 // Returns the underlying byte vector. 81 // Returns the underlying byte vector.
82 const std::vector<uint8_t>& bytes() const { return ip_address_; }; 82 const std::vector<uint8_t>& bytes() const { return ip_address_; };
83 83
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // In cases when an IPv4 address is being compared to an IPv6 address prefix 123 // In cases when an IPv4 address is being compared to an IPv6 address prefix
124 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped 124 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped
125 // (IPv6) addresses. 125 // (IPv6) addresses.
126 NET_EXPORT bool IPAddressMatchesPrefix(const IPAddress& ip_address, 126 NET_EXPORT bool IPAddressMatchesPrefix(const IPAddress& ip_address,
127 const IPAddress& ip_prefix, 127 const IPAddress& ip_prefix,
128 size_t prefix_length_in_bits); 128 size_t prefix_length_in_bits);
129 129
130 } // namespace net 130 } // namespace net
131 131
132 #endif // NET_BASE_IP_ADDRESS_NET_H_ 132 #endif // NET_BASE_IP_ADDRESS_NET_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/ip_address_number.h » ('j') | net/base/ip_address_number.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698