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

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

Issue 23726043: Added NetworkInterface::network_prefix (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
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/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
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 NetworkInterface::NetworkInterface() { 2145 NetworkInterface::NetworkInterface() : network_prefix(0) {
2146 } 2146 }
2147 2147
2148 NetworkInterface::NetworkInterface(const std::string& name, 2148 NetworkInterface::NetworkInterface(const std::string& name,
2149 const IPAddressNumber& address) 2149 const IPAddressNumber& address,
2150 : name(name), address(address) { 2150 uint8 network_prefix)
2151 : name(name), address(address), network_prefix(network_prefix) {
2151 } 2152 }
2152 2153
2153 NetworkInterface::~NetworkInterface() { 2154 NetworkInterface::~NetworkInterface() {
2154 } 2155 }
2155 2156
2157 unsigned CommonPrefixLength(const IPAddressNumber& a1,
2158 const IPAddressNumber& a2) {
2159 DCHECK_EQ(a1.size(), a2.size());
2160 for (size_t i = 0; i < a1.size(); ++i) {
2161 unsigned diff = a1[i] ^ a2[i];
2162 if (!diff)
2163 continue;
2164 for (unsigned j = 0; j < CHAR_BIT; ++j) {
2165 if (diff & (1 << (CHAR_BIT - 1)))
2166 return i * CHAR_BIT + j;
2167 diff <<= 1;
2168 }
2169 NOTREACHED();
2170 }
2171 return a1.size() * CHAR_BIT;
2172 }
2173
2174 unsigned MaskPrefixLength(const IPAddressNumber& mask) {
2175 IPAddressNumber all_ones(mask.size(), 0xFF);
2176 return CommonPrefixLength(mask, all_ones);
2177 }
2178
2156 } // namespace net 2179 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_posix.cc » ('j') | net/base/net_util_posix.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698