diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-19 00:36:39 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-19 00:36:39 +0000 |
commit | 611cc90419870d40c0048c01ce72def49b8b5dd3 (patch) | |
tree | 264a4f257f9d2906f1d7d75e47154b014312af7f /net/base/net_util.h | |
parent | 35d94587215848ac4ec0dbeceaa4e86a7657f7ae (diff) | |
download | chromium_src-611cc90419870d40c0048c01ce72def49b8b5dd3.zip chromium_src-611cc90419870d40c0048c01ce72def49b8b5dd3.tar.gz chromium_src-611cc90419870d40c0048c01ce72def49b8b5dd3.tar.bz2 |
Add GetNetworkList() in net_utils.
BUG=None
TEST=Unittests.
Review URL: http://codereview.chromium.org/6676027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78780 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.h')
-rw-r--r-- | net/base/net_util.h | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/net/base/net_util.h b/net/base/net_util.h index 935eab6..9e30d2b 100644 --- a/net/base/net_util.h +++ b/net/base/net_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,6 +15,7 @@ #include <sys/socket.h> #endif +#include <list> #include <string> #include <set> #include <vector> @@ -372,6 +373,9 @@ bool HaveOnlyLoopbackAddresses(); // IPv4 addresses will have length 4, whereas IPv6 address will have length 16. typedef std::vector<unsigned char> IPAddressNumber; +static const size_t kIPv4AddressSize = 4; +static const size_t kIPv6AddressSize = 16; + // Parses an IP address literal (either IPv4 or IPv6) to its numeric value. // Returns true on success and fills |ip_number| with the numeric value. bool ParseIPLiteralToNumber(const std::string& ip_literal, @@ -423,6 +427,25 @@ const uint16* GetPortFieldFromSockaddr(const struct sockaddr* address, int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len); +// struct that is used by GetNetworkList() to represent a network +// interface. +struct NetworkInterface { + NetworkInterface(); + NetworkInterface(const std::string& name, const IPAddressNumber& address); + ~NetworkInterface(); + + std::string name; + IPAddressNumber address; +}; + +typedef std::list<NetworkInterface> NetworkInterfaceList; + +// Returns list of network interfaces except loopback interface. If an +// interface has more than one address, a separate entry is added to +// the list for each address. +// Can be called only on a thread that allows IO. +bool GetNetworkList(NetworkInterfaceList* networks); + } // namespace net #endif // NET_BASE_NET_UTIL_H_ |