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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util.cc
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index dd0826c6a5405945e381368f4eed8a8f49a5f01e..20f69f8f61294a2728a33026301dffb0197675c1 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -2142,15 +2142,38 @@ bool IsLocalhost(const std::string& host) {
return false;
}
-NetworkInterface::NetworkInterface() {
+NetworkInterface::NetworkInterface() : network_prefix(0) {
}
NetworkInterface::NetworkInterface(const std::string& name,
- const IPAddressNumber& address)
- : name(name), address(address) {
+ const IPAddressNumber& address,
+ uint8 network_prefix)
+ : name(name), address(address), network_prefix(network_prefix) {
}
NetworkInterface::~NetworkInterface() {
}
+unsigned CommonPrefixLength(const IPAddressNumber& a1,
+ const IPAddressNumber& a2) {
+ DCHECK_EQ(a1.size(), a2.size());
+ for (size_t i = 0; i < a1.size(); ++i) {
+ unsigned diff = a1[i] ^ a2[i];
+ if (!diff)
+ continue;
+ for (unsigned j = 0; j < CHAR_BIT; ++j) {
+ if (diff & (1 << (CHAR_BIT - 1)))
+ return i * CHAR_BIT + j;
+ diff <<= 1;
+ }
+ NOTREACHED();
+ }
+ return a1.size() * CHAR_BIT;
+}
+
+unsigned MaskPrefixLength(const IPAddressNumber& mask) {
+ IPAddressNumber all_ones(mask.size(), 0xFF);
+ return CommonPrefixLength(mask, all_ones);
+}
+
} // namespace net
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698