| 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
|
|
|