| OLD | NEW |
| 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/net_util.h" | 5 #include "net/base/net_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 2168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2179 } | 2179 } |
| 2180 } | 2180 } |
| 2181 | 2181 |
| 2182 return false; | 2182 return false; |
| 2183 } | 2183 } |
| 2184 | 2184 |
| 2185 NetworkInterface::NetworkInterface() : network_prefix(0) { | 2185 NetworkInterface::NetworkInterface() : network_prefix(0) { |
| 2186 } | 2186 } |
| 2187 | 2187 |
| 2188 NetworkInterface::NetworkInterface(const std::string& name, | 2188 NetworkInterface::NetworkInterface(const std::string& name, |
| 2189 uint32 interface_index, |
| 2189 const IPAddressNumber& address, | 2190 const IPAddressNumber& address, |
| 2190 size_t network_prefix) | 2191 size_t network_prefix) |
| 2191 : name(name), address(address), network_prefix(network_prefix) { | 2192 : name(name), |
| 2193 interface_index(interface_index), |
| 2194 address(address), |
| 2195 network_prefix(network_prefix) { |
| 2192 } | 2196 } |
| 2193 | 2197 |
| 2194 NetworkInterface::~NetworkInterface() { | 2198 NetworkInterface::~NetworkInterface() { |
| 2195 } | 2199 } |
| 2196 | 2200 |
| 2197 unsigned CommonPrefixLength(const IPAddressNumber& a1, | 2201 unsigned CommonPrefixLength(const IPAddressNumber& a1, |
| 2198 const IPAddressNumber& a2) { | 2202 const IPAddressNumber& a2) { |
| 2199 DCHECK_EQ(a1.size(), a2.size()); | 2203 DCHECK_EQ(a1.size(), a2.size()); |
| 2200 for (size_t i = 0; i < a1.size(); ++i) { | 2204 for (size_t i = 0; i < a1.size(); ++i) { |
| 2201 unsigned diff = a1[i] ^ a2[i]; | 2205 unsigned diff = a1[i] ^ a2[i]; |
| 2202 if (!diff) | 2206 if (!diff) |
| 2203 continue; | 2207 continue; |
| 2204 for (unsigned j = 0; j < CHAR_BIT; ++j) { | 2208 for (unsigned j = 0; j < CHAR_BIT; ++j) { |
| 2205 if (diff & (1 << (CHAR_BIT - 1))) | 2209 if (diff & (1 << (CHAR_BIT - 1))) |
| 2206 return i * CHAR_BIT + j; | 2210 return i * CHAR_BIT + j; |
| 2207 diff <<= 1; | 2211 diff <<= 1; |
| 2208 } | 2212 } |
| 2209 NOTREACHED(); | 2213 NOTREACHED(); |
| 2210 } | 2214 } |
| 2211 return a1.size() * CHAR_BIT; | 2215 return a1.size() * CHAR_BIT; |
| 2212 } | 2216 } |
| 2213 | 2217 |
| 2214 unsigned MaskPrefixLength(const IPAddressNumber& mask) { | 2218 unsigned MaskPrefixLength(const IPAddressNumber& mask) { |
| 2215 IPAddressNumber all_ones(mask.size(), 0xFF); | 2219 IPAddressNumber all_ones(mask.size(), 0xFF); |
| 2216 return CommonPrefixLength(mask, all_ones); | 2220 return CommonPrefixLength(mask, all_ones); |
| 2217 } | 2221 } |
| 2218 | 2222 |
| 2219 } // namespace net | 2223 } // namespace net |
| OLD | NEW |