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

Side by Side Diff: net/base/net_util_posix.cc

Issue 100703002: Added net::NetworkInterface::interface_index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/net_util.cc ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <sys/types.h> 7 #include <sys/types.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 std::string name = network_tokenizer.token(); 74 std::string name = network_tokenizer.token();
75 75
76 CHECK(network_tokenizer.GetNext()); 76 CHECK(network_tokenizer.GetNext());
77 std::string interface_address = network_tokenizer.token(); 77 std::string interface_address = network_tokenizer.token();
78 IPAddressNumber address; 78 IPAddressNumber address;
79 size_t network_prefix = 0; 79 size_t network_prefix = 0;
80 CHECK(ParseCIDRBlock(network_tokenizer.token(), 80 CHECK(ParseCIDRBlock(network_tokenizer.token(),
81 &address, 81 &address,
82 &network_prefix)); 82 &network_prefix));
83 83
84 CHECK(network_tokenizer.GetNext());
85 uint32 index = 0;
86 CHECK(base::StringToUint(network_tokenizer.token(), &index));
87
84 networks->push_back( 88 networks->push_back(
85 NetworkInterface(name, address, network_prefix)); 89 NetworkInterface(name, index, address, network_prefix));
86 } 90 }
87 return true; 91 return true;
88 #else 92 #else
89 // getifaddrs() may require IO operations. 93 // getifaddrs() may require IO operations.
90 base::ThreadRestrictions::AssertIOAllowed(); 94 base::ThreadRestrictions::AssertIOAllowed();
91 95
92 ifaddrs *interfaces; 96 ifaddrs *interfaces;
93 if (getifaddrs(&interfaces) < 0) { 97 if (getifaddrs(&interfaces) < 0) {
94 PLOG(ERROR) << "getifaddrs"; 98 PLOG(ERROR) << "getifaddrs";
95 return false; 99 return false;
96 } 100 }
97 101
98 // Enumerate the addresses assigned to network interfaces which are up. 102 // Enumerate the addresses assigned to network interfaces which are up.
99 for (ifaddrs *interface = interfaces; 103 for (ifaddrs *interface = interfaces;
100 interface != NULL; 104 interface != NULL;
101 interface = interface->ifa_next) { 105 interface = interface->ifa_next) {
102 // Skip loopback interfaces, and ones which are down. 106 // Skip loopback interfaces, and ones which are down.
103 if (!(IFF_UP & interface->ifa_flags)) 107 if (!(IFF_UP & interface->ifa_flags))
104 continue; 108 continue;
105 if (IFF_LOOPBACK & interface->ifa_flags) 109 if (IFF_LOOPBACK & interface->ifa_flags)
106 continue; 110 continue;
107 // Skip interfaces with no address configured. 111 // Skip interfaces with no address configured.
108 struct sockaddr* addr = interface->ifa_addr; 112 struct sockaddr* addr = interface->ifa_addr;
109 if (!addr) 113 if (!addr)
110 continue; 114 continue;
115
111 // Skip unspecified addresses (i.e. made of zeroes) and loopback addresses 116 // Skip unspecified addresses (i.e. made of zeroes) and loopback addresses
112 // configured on non-loopback interfaces. 117 // configured on non-loopback interfaces.
113 int addr_size = 0; 118 int addr_size = 0;
114 if (addr->sa_family == AF_INET6) { 119 if (addr->sa_family == AF_INET6) {
115 struct sockaddr_in6* addr_in6 = 120 struct sockaddr_in6* addr_in6 =
116 reinterpret_cast<struct sockaddr_in6*>(addr); 121 reinterpret_cast<struct sockaddr_in6*>(addr);
117 struct in6_addr* sin6_addr = &addr_in6->sin6_addr; 122 struct in6_addr* sin6_addr = &addr_in6->sin6_addr;
118 addr_size = sizeof(*addr_in6); 123 addr_size = sizeof(*addr_in6);
119 if (IN6_IS_ADDR_LOOPBACK(sin6_addr) || 124 if (IN6_IS_ADDR_LOOPBACK(sin6_addr) ||
120 IN6_IS_ADDR_UNSPECIFIED(sin6_addr)) { 125 IN6_IS_ADDR_UNSPECIFIED(sin6_addr)) {
(...skipping 16 matching lines...) Expand all
137 std::string name = interface->ifa_name; 142 std::string name = interface->ifa_name;
138 if (address.FromSockAddr(addr, addr_size)) { 143 if (address.FromSockAddr(addr, addr_size)) {
139 uint8 net_mask = 0; 144 uint8 net_mask = 0;
140 if (interface->ifa_netmask) { 145 if (interface->ifa_netmask) {
141 IPEndPoint netmask; 146 IPEndPoint netmask;
142 if (netmask.FromSockAddr(interface->ifa_netmask, addr_size)) { 147 if (netmask.FromSockAddr(interface->ifa_netmask, addr_size)) {
143 net_mask = MaskPrefixLength(netmask.address()); 148 net_mask = MaskPrefixLength(netmask.address());
144 } 149 }
145 } 150 }
146 151
147 networks->push_back(NetworkInterface(name, address.address(), net_mask)); 152 networks->push_back(
153 NetworkInterface(name, if_nametoindex(name.c_str()),
154 address.address(), net_mask));
148 } 155 }
149 } 156 }
150 157
151 freeifaddrs(interfaces); 158 freeifaddrs(interfaces);
152 159
153 return true; 160 return true;
154 #endif 161 #endif
155 } 162 }
156 163
157 WifiPHYLayerProtocol GetWifiPHYLayerProtocol() { 164 WifiPHYLayerProtocol GetWifiPHYLayerProtocol() {
158 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; 165 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN;
159 } 166 }
160 167
161 } // namespace net 168 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util.cc ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698