Task #1306
closed
Added by Junxiao Shi over 10 years ago.
Updated over 10 years ago.
Description
Develop a function to enumerate Network Interface Cards (NICs) on a system.
This function should return a collection of records each representing an NIC, which contains:
- NIC name, such as "eth0" or "en0"
- zero or more IPv4 addresses
- zero or more IPv6 addresses
- zero or one Ethernet address
- whether the NIC is multicast capable
- whether the NIC is up/active
This function must not rely on libpcap.
Junxiao Shi wrote:
- zero or one Ethernet address
zero? are you referring to the loopback interface? do you want to enumerate that one too? if so, I think there should be a flag indicating whether an interface is loopback or not.
- Category set to Faces
- Assignee set to Davide Pesavento
- Target version set to v0.1
- Start date deleted (
02/28/2014)
- Priority changed from Normal to High
Every NIC should be returned. It's FaceManager
's decision on how to use the results.
What's the method signature? something like static std::list findAllInterfaces() ?
What class does it belong to?
Sorry, I mean static std::list<NetworkInterface*> findAllInterfaces()
or do you prefer "device" instead of "interface"?
I suggest:
class NicInfo
{
public:
std::string m_name;
std::vector<boost::asio::ip::address_v4> m_ipv4Addresses;
std::vector<boost::asio::ip::address_v6> m_ipv6Addresses;
std::vector<uint8_t[6]> m_etherAddresses;
bool m_isMulticastCapable;
bool m_isUp;
};
std::list<NicInfo> listNetworkInterfaceCards();
"NIC" is a common acronym similar to "DVD" example in rule 9, and is not a violation of rule 27.
class NicInfo
is a pure data structure so it's fine to have public fields, which is an exemption permitted in rule 48.
The function listNetworkInterfaceCards
is a free function that doesn't belong to any class. "list" is a verb, so the function name doesn't violate rule 7.
@Alex should decide which type to use for addresses:
- sockaddr_in, sockaddr_in6, sockaddr_ll
- sockaddr_ll is not available on OS X but could be declared in code
- string
- boost::asio address for IP, uint8_t[6] for Ethernet
I don't like the term "card" in NIC because it somewhat implies a physical piece of hardware, while an interface could be virtual. As a matter of fact, Linux uses the term "netdev".
Btw, for MAC addresses we already have nfd::ethernet::Address.
- Status changed from New to Code review
- % Done changed from 0 to 80
- % Done changed from 80 to 100
- Status changed from Code review to Closed
Also available in: Atom
PDF