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 2124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 } | 2135 } |
2136 | 2136 |
2137 default: | 2137 default: |
2138 NOTREACHED(); | 2138 NOTREACHED(); |
2139 } | 2139 } |
2140 } | 2140 } |
2141 | 2141 |
2142 return false; | 2142 return false; |
2143 } | 2143 } |
2144 | 2144 |
| 2145 #if defined(OS_ANDROID) |
| 2146 |
2145 NetworkInterface::NetworkInterface() { | 2147 NetworkInterface::NetworkInterface() { |
2146 } | 2148 } |
2147 | 2149 |
2148 NetworkInterface::NetworkInterface(const std::string& name, | 2150 NetworkInterface::NetworkInterface(const std::string& name, |
2149 const IPAddressNumber& address) | 2151 const IPAddressNumber& address) |
2150 : name(name), address(address) { | 2152 : name(name), address(address) { |
2151 } | 2153 } |
2152 | 2154 |
| 2155 #else // OS_ANDROID |
| 2156 |
| 2157 NetworkInterface::NetworkInterface() : network_prefix(0) { |
| 2158 } |
| 2159 |
| 2160 NetworkInterface::NetworkInterface(const std::string& name, |
| 2161 const IPAddressNumber& address, |
| 2162 uint8 network_prefix) |
| 2163 : name(name), address(address), network_prefix(network_prefix) { |
| 2164 } |
| 2165 |
| 2166 #endif // OS_ANDROID |
| 2167 |
2153 NetworkInterface::~NetworkInterface() { | 2168 NetworkInterface::~NetworkInterface() { |
2154 } | 2169 } |
2155 | 2170 |
| 2171 unsigned CommonPrefixLength(const IPAddressNumber& a1, |
| 2172 const IPAddressNumber& a2) { |
| 2173 DCHECK_EQ(a1.size(), a2.size()); |
| 2174 for (size_t i = 0; i < a1.size(); ++i) { |
| 2175 unsigned diff = a1[i] ^ a2[i]; |
| 2176 if (!diff) |
| 2177 continue; |
| 2178 for (unsigned j = 0; j < CHAR_BIT; ++j) { |
| 2179 if (diff & (1 << (CHAR_BIT - 1))) |
| 2180 return i * CHAR_BIT + j; |
| 2181 diff <<= 1; |
| 2182 } |
| 2183 NOTREACHED(); |
| 2184 } |
| 2185 return a1.size() * CHAR_BIT; |
| 2186 } |
| 2187 |
| 2188 unsigned MaskPrefixLength(const IPAddressNumber& mask) { |
| 2189 IPAddressNumber all_ones(mask.size(), 0xFF); |
| 2190 return CommonPrefixLength(mask, all_ones); |
| 2191 } |
| 2192 |
2156 } // namespace net | 2193 } // namespace net |
OLD | NEW |