1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-24 03:05:57 +01:00

EthernetII, IEEE802_3 and Dot11(and subclasses) now use NetworkInterface and HWAddress.

This commit is contained in:
Matias Fontanini
2012-08-09 12:00:29 -03:00
parent 29c5a696e5
commit 91af0f9cc2
17 changed files with 278 additions and 600 deletions

View File

@@ -61,17 +61,23 @@ struct InterfaceInfoCollector {
/** \endcond */
namespace Tins {
NetworkInterface::NetworkInterface() : iface_id(0) {
}
NetworkInterface::NetworkInterface(const std::string &name) {
iface_id = if_nametoindex(name.c_str());
if(!iface_id)
throw std::runtime_error("Invalid interface error");
iface_id = resolve_index(name.c_str());
}
NetworkInterface::NetworkInterface(const char *name) {
iface_id = resolve_index(name);
}
NetworkInterface::NetworkInterface(IPv4Address ip) : iface_id(0) {
typedef std::vector<Utils::RouteEntry> entries_type;
if(ip == "127.0.0.1")
iface_id = if_nametoindex("lo");
iface_id = resolve_index("lo");
else {
entries_type entries;
uint32_t ip_int = ip;
@@ -103,5 +109,12 @@ NetworkInterface::Info NetworkInterface::addresses() const {
throw std::runtime_error("Error looking up interface address");
return info;
}
NetworkInterface::id_type NetworkInterface::resolve_index(const char *name) {
id_type id = if_nametoindex(name);
if(!id)
throw std::runtime_error("Invalid interface error");
return id;
}
}