mirror of
https://github.com/mfontanini/libtins
synced 2026-01-29 04:54:28 +01:00
Add NetworkInterface::is_up and NetworkInterface::info.
This commit is contained in:
@@ -130,11 +130,20 @@ public:
|
||||
/**
|
||||
* \brief Retrieve this interface's addresses.
|
||||
*
|
||||
* This method is deprecated. You should use NetworkInterface::info (this
|
||||
* is just a naming deprecation, NetworkInterface::info is equivalent).
|
||||
* \deprecated
|
||||
*/
|
||||
Info addresses() const;
|
||||
|
||||
/**
|
||||
* \brief Retrieve this interface's information.
|
||||
*
|
||||
* This method iterates through all the interface's until the
|
||||
* correct one is found. Therefore it's O(N), being N the amount
|
||||
* of interfaces in the system.
|
||||
*/
|
||||
Info addresses() const;
|
||||
Info info() const;
|
||||
|
||||
/**
|
||||
* \brief Tests whether this is a valid interface;
|
||||
@@ -151,7 +160,15 @@ public:
|
||||
* @return true iff this is a loopback device.
|
||||
*/
|
||||
bool is_loopback() const;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Indicates whether this interface is up.
|
||||
*
|
||||
* This is equivalent to getting the interface info and checking for the is_up
|
||||
* attribute.
|
||||
*/
|
||||
bool is_up() const;
|
||||
|
||||
/**
|
||||
* \brief Compares this interface for equality.
|
||||
*
|
||||
|
||||
@@ -120,7 +120,7 @@ struct InterfaceInfoCollector {
|
||||
info->ip_addr = IPv4Address(((const struct sockaddr_in *)unicast->Address.lpSockaddr)->sin_addr.s_addr);
|
||||
info->netmask = IPv4Address(host_to_be<uint32_t>(0xffffffff << (32 - unicast->OnLinkPrefixLength)));
|
||||
info->bcast_addr = IPv4Address((info->ip_addr & info->netmask) | ~info->netmask);
|
||||
info->is_up = (iface->Flags & IP_ADAPTER_IPV4_ENABLED);
|
||||
info->is_up = (iface->Flags & IP_ADAPTER_IPV4_ENABLED) != 0;
|
||||
found_ip = true;
|
||||
found_hw = true;
|
||||
}
|
||||
@@ -215,6 +215,10 @@ std::string NetworkInterface::name() const {
|
||||
}
|
||||
|
||||
NetworkInterface::Info NetworkInterface::addresses() const {
|
||||
return info();
|
||||
}
|
||||
|
||||
NetworkInterface::Info NetworkInterface::info() const {
|
||||
const std::string &iface_name = name();
|
||||
Info info;
|
||||
InterfaceInfoCollector collector(&info, iface_id, iface_name.c_str());
|
||||
@@ -231,6 +235,10 @@ bool NetworkInterface::is_loopback() const {
|
||||
return addresses().ip_addr.is_loopback();
|
||||
}
|
||||
|
||||
bool NetworkInterface::is_up() const {
|
||||
return addresses().is_up;
|
||||
}
|
||||
|
||||
NetworkInterface::id_type NetworkInterface::resolve_index(const char *name) {
|
||||
#ifndef WIN32
|
||||
id_type id = if_nametoindex(name);
|
||||
|
||||
Reference in New Issue
Block a user