OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 return false; | 98 return false; |
99 } | 99 } |
100 | 100 |
101 for (IP_ADAPTER_ADDRESSES *adapter = adapters; adapter != NULL; | 101 for (IP_ADAPTER_ADDRESSES *adapter = adapters; adapter != NULL; |
102 adapter = adapter->Next) { | 102 adapter = adapter->Next) { |
103 // Ignore the loopback device. | 103 // Ignore the loopback device. |
104 if (adapter->IfType == IF_TYPE_SOFTWARE_LOOPBACK) { | 104 if (adapter->IfType == IF_TYPE_SOFTWARE_LOOPBACK) { |
105 continue; | 105 continue; |
106 } | 106 } |
107 | 107 |
108 if (adapter->OperStatus != IfOperStatusUp) { | |
109 continue; | |
110 } | |
111 | |
108 IP_ADAPTER_UNICAST_ADDRESS* address; | 112 IP_ADAPTER_UNICAST_ADDRESS* address; |
109 for (address = adapter->FirstUnicastAddress; address != NULL; | 113 for (address = adapter->FirstUnicastAddress; address != NULL; |
110 address = address->Next) { | 114 address = address->Next) { |
wtc
2012/02/17 19:36:23
Comparing this code with the GetNetworkList functi
| |
111 int family = address->Address.lpSockaddr->sa_family; | 115 int family = address->Address.lpSockaddr->sa_family; |
112 if (family == AF_INET || family == AF_INET6) { | 116 if (family == AF_INET || family == AF_INET6) { |
113 IPEndPoint endpoint; | 117 IPEndPoint endpoint; |
114 if (endpoint.FromSockAddr(address->Address.lpSockaddr, | 118 if (endpoint.FromSockAddr(address->Address.lpSockaddr, |
115 address->Address.iSockaddrLength)) { | 119 address->Address.iSockaddrLength)) { |
116 std::string name = adapter->AdapterName; | 120 std::string name = adapter->AdapterName; |
117 networks->push_back(NetworkInterface(name, endpoint.address())); | 121 networks->push_back(NetworkInterface(name, endpoint.address())); |
118 } | 122 } |
119 } | 123 } |
120 } | 124 } |
121 } | 125 } |
122 | 126 |
123 return true; | 127 return true; |
124 } | 128 } |
125 | 129 |
126 } // namespace net | 130 } // namespace net |
OLD | NEW |