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 <iphlpapi.h> | 7 #include <iphlpapi.h> |
8 #include <wlanapi.h> | 8 #include <wlanapi.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 110 } |
111 | 111 |
112 for (IP_ADAPTER_UNICAST_ADDRESS* address = adapter->FirstUnicastAddress; | 112 for (IP_ADAPTER_UNICAST_ADDRESS* address = adapter->FirstUnicastAddress; |
113 address; address = address->Next) { | 113 address; address = address->Next) { |
114 int family = address->Address.lpSockaddr->sa_family; | 114 int family = address->Address.lpSockaddr->sa_family; |
115 if (family == AF_INET || family == AF_INET6) { | 115 if (family == AF_INET || family == AF_INET6) { |
116 IPEndPoint endpoint; | 116 IPEndPoint endpoint; |
117 if (endpoint.FromSockAddr(address->Address.lpSockaddr, | 117 if (endpoint.FromSockAddr(address->Address.lpSockaddr, |
118 address->Address.iSockaddrLength)) { | 118 address->Address.iSockaddrLength)) { |
119 // XP has no OnLinkPrefixLength field. | 119 // XP has no OnLinkPrefixLength field. |
120 size_t net_prefix = is_xp ? 0 : address->OnLinkPrefixLength; | 120 size_t prefix_length = is_xp ? 0 : address->OnLinkPrefixLength; |
121 if (is_xp) { | 121 if (is_xp) { |
122 // Prior to Windows Vista the FirstPrefix pointed to the list with | 122 // Prior to Windows Vista the FirstPrefix pointed to the list with |
123 // single prefix for each IP address assigned to the adapter. | 123 // single prefix for each IP address assigned to the adapter. |
124 // Order of FirstPrefix does not match order of FirstUnicastAddress, | 124 // Order of FirstPrefix does not match order of FirstUnicastAddress, |
125 // so we need to find corresponding prefix. | 125 // so we need to find corresponding prefix. |
126 for (IP_ADAPTER_PREFIX* prefix = adapter->FirstPrefix; prefix; | 126 for (IP_ADAPTER_PREFIX* prefix = adapter->FirstPrefix; prefix; |
127 prefix = prefix->Next) { | 127 prefix = prefix->Next) { |
128 int prefix_family = prefix->Address.lpSockaddr->sa_family; | 128 int prefix_family = prefix->Address.lpSockaddr->sa_family; |
129 IPEndPoint network_endpoint; | 129 IPEndPoint network_endpoint; |
130 if (prefix_family == family && | 130 if (prefix_family == family && |
131 network_endpoint.FromSockAddr(prefix->Address.lpSockaddr, | 131 network_endpoint.FromSockAddr(prefix->Address.lpSockaddr, |
132 prefix->Address.iSockaddrLength) && | 132 prefix->Address.iSockaddrLength) && |
133 IPNumberMatchesPrefix(endpoint.address(), | 133 IPNumberMatchesPrefix(endpoint.address(), |
134 network_endpoint.address(), | 134 network_endpoint.address(), |
135 prefix->PrefixLength)) { | 135 prefix->PrefixLength)) { |
136 net_prefix = std::max<size_t>(net_prefix, prefix->PrefixLength); | 136 prefix_length = |
| 137 std::max<size_t>(prefix_length, prefix->PrefixLength); |
137 } | 138 } |
138 } | 139 } |
139 } | 140 } |
140 | 141 |
141 // If the duplicate address detection (DAD) state is not changed to | 142 // If the duplicate address detection (DAD) state is not changed to |
142 // Preferred, skip this address. | 143 // Preferred, skip this address. |
143 if (address->DadState != IpDadStatePreferred) { | 144 if (address->DadState != IpDadStatePreferred) { |
144 continue; | 145 continue; |
145 } | 146 } |
146 | 147 |
(...skipping 11 matching lines...) Expand all Loading... |
158 ip_address_attributes |= IP_ADDRESS_ATTRIBUTE_TEMPORARY; | 159 ip_address_attributes |= IP_ADDRESS_ATTRIBUTE_TEMPORARY; |
159 } | 160 } |
160 if (address->PreferredLifetime == 0) { | 161 if (address->PreferredLifetime == 0) { |
161 ip_address_attributes |= IP_ADDRESS_ATTRIBUTE_DEPRECATED; | 162 ip_address_attributes |= IP_ADDRESS_ATTRIBUTE_DEPRECATED; |
162 } | 163 } |
163 } | 164 } |
164 networks->push_back(NetworkInterface( | 165 networks->push_back(NetworkInterface( |
165 adapter->AdapterName, | 166 adapter->AdapterName, |
166 base::SysWideToNativeMB(adapter->FriendlyName), index, | 167 base::SysWideToNativeMB(adapter->FriendlyName), index, |
167 GetNetworkInterfaceType(adapter->IfType), endpoint.address(), | 168 GetNetworkInterfaceType(adapter->IfType), endpoint.address(), |
168 net_prefix, ip_address_attributes)); | 169 prefix_length, ip_address_attributes)); |
169 } | 170 } |
170 } | 171 } |
171 } | 172 } |
172 } | 173 } |
173 return true; | 174 return true; |
174 } | 175 } |
175 | 176 |
176 } // namespace internal | 177 } // namespace internal |
177 | 178 |
178 bool GetNetworkList(NetworkInterfaceList* networks, int policy) { | 179 bool GetNetworkList(NetworkInterfaceList* networks, int policy) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 314 |
314 private: | 315 private: |
315 internal::WlanHandle client_; | 316 internal::WlanHandle client_; |
316 }; | 317 }; |
317 | 318 |
318 scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { | 319 scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options) { |
319 return scoped_ptr<ScopedWifiOptions>(new WifiOptionSetter(options)); | 320 return scoped_ptr<ScopedWifiOptions>(new WifiOptionSetter(options)); |
320 } | 321 } |
321 | 322 |
322 } // namespace net | 323 } // namespace net |
OLD | NEW |