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

Side by Side Diff: net/base/ip_address_number.cc

Issue 1708483002: Revert of 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: 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 | « net/base/ip_address_number.h ('k') | net/base/ip_address_number_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "net/base/ip_address_number.h" 5 #include "net/base/ip_address_number.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 std::string IPAddressToString(const uint8_t* address, size_t address_len) { 97 std::string IPAddressToString(const uint8_t* address, size_t address_len) {
98 std::string str; 98 std::string str;
99 url::StdStringCanonOutput output(&str); 99 url::StdStringCanonOutput output(&str);
100 100
101 if (address_len == kIPv4AddressSize) { 101 if (address_len == kIPv4AddressSize) {
102 url::AppendIPv4Address(address, &output); 102 url::AppendIPv4Address(address, &output);
103 } else if (address_len == kIPv6AddressSize) { 103 } else if (address_len == kIPv6AddressSize) {
104 url::AppendIPv6Address(address, &output); 104 url::AppendIPv6Address(address, &output);
105 } else { 105 } else {
106 return std::string(); 106 CHECK(false) << "Invalid IP address with length: " << address_len;
107 } 107 }
108 108
109 output.Complete(); 109 output.Complete();
110 return str; 110 return str;
111 } 111 }
112 112
113 std::string IPAddressToStringWithPort(const uint8_t* address, 113 std::string IPAddressToStringWithPort(const uint8_t* address,
114 size_t address_len, 114 size_t address_len,
115 uint16_t port) { 115 uint16_t port) {
116 std::string address_str = IPAddressToString(address, address_len); 116 std::string address_str = IPAddressToString(address, address_len);
117 if (address_str.empty())
118 return address_str;
119 117
120 if (address_len == kIPv6AddressSize) { 118 if (address_len == kIPv6AddressSize) {
121 // Need to bracket IPv6 addresses since they contain colons. 119 // Need to bracket IPv6 addresses since they contain colons.
122 return base::StringPrintf("[%s]:%d", address_str.c_str(), port); 120 return base::StringPrintf("[%s]:%d", address_str.c_str(), port);
123 } 121 }
124 return base::StringPrintf("%s:%d", address_str.c_str(), port); 122 return base::StringPrintf("%s:%d", address_str.c_str(), port);
125 } 123 }
126 124
127 std::string IPAddressToString(const IPAddressNumber& addr) { 125 std::string IPAddressToString(const IPAddressNumber& addr) {
128 return IPAddressToString(&addr.front(), addr.size()); 126 return IPAddressToString(&addr.front(), addr.size());
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 290 }
293 return a1.size() * CHAR_BIT; 291 return a1.size() * CHAR_BIT;
294 } 292 }
295 293
296 unsigned MaskPrefixLength(const IPAddressNumber& mask) { 294 unsigned MaskPrefixLength(const IPAddressNumber& mask) {
297 IPAddressNumber all_ones(mask.size(), 0xFF); 295 IPAddressNumber all_ones(mask.size(), 0xFF);
298 return CommonPrefixLength(mask, all_ones); 296 return CommonPrefixLength(mask, all_ones);
299 } 297 }
300 298
301 } // namespace net 299 } // namespace net
OLDNEW
« no previous file with comments | « net/base/ip_address_number.h ('k') | net/base/ip_address_number_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698