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 <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 NetworkInterface::NetworkInterface() | 997 NetworkInterface::NetworkInterface() |
998 : type(NetworkChangeNotifier::CONNECTION_UNKNOWN), | 998 : type(NetworkChangeNotifier::CONNECTION_UNKNOWN), |
999 network_prefix(0) { | 999 network_prefix(0) { |
1000 } | 1000 } |
1001 | 1001 |
1002 NetworkInterface::NetworkInterface(const std::string& name, | 1002 NetworkInterface::NetworkInterface(const std::string& name, |
1003 const std::string& friendly_name, | 1003 const std::string& friendly_name, |
1004 uint32 interface_index, | 1004 uint32 interface_index, |
1005 NetworkChangeNotifier::ConnectionType type, | 1005 NetworkChangeNotifier::ConnectionType type, |
1006 const IPAddressNumber& address, | 1006 const IPAddressNumber& address, |
1007 uint32 network_prefix) | 1007 uint32 network_prefix, |
| 1008 int ip_address_attributes) |
1008 : name(name), | 1009 : name(name), |
1009 friendly_name(friendly_name), | 1010 friendly_name(friendly_name), |
1010 interface_index(interface_index), | 1011 interface_index(interface_index), |
1011 type(type), | 1012 type(type), |
1012 address(address), | 1013 address(address), |
1013 network_prefix(network_prefix) { | 1014 network_prefix(network_prefix), |
| 1015 ip_address_attributes(ip_address_attributes) { |
1014 } | 1016 } |
1015 | 1017 |
1016 NetworkInterface::~NetworkInterface() { | 1018 NetworkInterface::~NetworkInterface() { |
1017 } | 1019 } |
1018 | 1020 |
1019 unsigned CommonPrefixLength(const IPAddressNumber& a1, | 1021 unsigned CommonPrefixLength(const IPAddressNumber& a1, |
1020 const IPAddressNumber& a2) { | 1022 const IPAddressNumber& a2) { |
1021 DCHECK_EQ(a1.size(), a2.size()); | 1023 DCHECK_EQ(a1.size(), a2.size()); |
1022 for (size_t i = 0; i < a1.size(); ++i) { | 1024 for (size_t i = 0; i < a1.size(); ++i) { |
1023 unsigned diff = a1[i] ^ a2[i]; | 1025 unsigned diff = a1[i] ^ a2[i]; |
1024 if (!diff) | 1026 if (!diff) |
1025 continue; | 1027 continue; |
1026 for (unsigned j = 0; j < CHAR_BIT; ++j) { | 1028 for (unsigned j = 0; j < CHAR_BIT; ++j) { |
1027 if (diff & (1 << (CHAR_BIT - 1))) | 1029 if (diff & (1 << (CHAR_BIT - 1))) |
1028 return i * CHAR_BIT + j; | 1030 return i * CHAR_BIT + j; |
1029 diff <<= 1; | 1031 diff <<= 1; |
1030 } | 1032 } |
1031 NOTREACHED(); | 1033 NOTREACHED(); |
1032 } | 1034 } |
1033 return a1.size() * CHAR_BIT; | 1035 return a1.size() * CHAR_BIT; |
1034 } | 1036 } |
1035 | 1037 |
1036 unsigned MaskPrefixLength(const IPAddressNumber& mask) { | 1038 unsigned MaskPrefixLength(const IPAddressNumber& mask) { |
1037 IPAddressNumber all_ones(mask.size(), 0xFF); | 1039 IPAddressNumber all_ones(mask.size(), 0xFF); |
1038 return CommonPrefixLength(mask, all_ones); | 1040 return CommonPrefixLength(mask, all_ones); |
1039 } | 1041 } |
1040 | 1042 |
1041 } // namespace net | 1043 } // namespace net |
OLD | NEW |