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

Unified Diff: net/base/net_util_posix.cc

Issue 23726043: Added NetworkInterface::network_prefix (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove LOG before commit Created 7 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: net/base/net_util_posix.cc
diff --git a/net/base/net_util_posix.cc b/net/base/net_util_posix.cc
index 904d8028bc26e22d76bc05bda11705838d010326..ad003f73765865c682c5130c70c631c318fdd7c4 100644
--- a/net/base/net_util_posix.cc
+++ b/net/base/net_util_posix.cc
@@ -9,6 +9,7 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
@@ -80,10 +81,21 @@ bool GetNetworkList(NetworkInterfaceList* networks) {
continue;
szym 2013/09/23 17:26:55 I don't quite understand why the code here silentl
literal_address = network_tokenizer.token();
+ uint8 net_mask = 0;
+ if (network_tokenizer.GetNext()) {
+ unsigned int_token = 0;
+ if (base::StringToUint(network_tokenizer.token(), &int_token) &&
+ int_token <= 255) {
+ net_mask = int_token;
+ } else {
+ NOTREACHED();
szym 2013/09/23 17:26:55 This should be consistent with the rest of the cod
+ }
+ }
+
IPAddressNumber address;
if (!ParseIPLiteralToNumber(literal_address, &address))
continue;
- networks->push_back(NetworkInterface(name, address));
+ networks->push_back(NetworkInterface(name, address, net_mask));
}
return true;
#else
@@ -133,10 +145,19 @@ bool GetNetworkList(NetworkInterfaceList* networks) {
// Skip non-IP addresses.
continue;
}
+
IPEndPoint address;
std::string name = interface->ifa_name;
if (address.FromSockAddr(addr, addr_size)) {
- networks->push_back(NetworkInterface(name, address.address()));
+ uint8 net_mask = 0;
+ if (interface->ifa_netmask) {
+ IPEndPoint netmask;
+ if (netmask.FromSockAddr(interface->ifa_netmask, addr_size)) {
+ net_mask = MaskPrefixLength(netmask.address());
+ }
+ }
+
+ networks->push_back(NetworkInterface(name, address.address(), net_mask));
}
}

Powered by Google App Engine
This is Rietveld 408576698