mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Added Utils::interface_id.
This commit is contained in:
@@ -102,6 +102,14 @@ namespace Tins {
|
||||
*/
|
||||
bool interface_hwaddr(const std::string &iface, uint8_t *buffer);
|
||||
|
||||
/** \brief Lookup the interface identifier.
|
||||
*
|
||||
* If the lookup fails, false will be returned, true otherwise.
|
||||
* \param iface The interface from which to extract the identifier.
|
||||
* \param flag The interface id will be returned in this parameter.
|
||||
*/
|
||||
bool interface_id(const std::string &iface, uint32_t &id);
|
||||
|
||||
/** \brief Convert 32 bit integer into network byte order.
|
||||
*
|
||||
* \param data The data to convert.
|
||||
|
||||
@@ -57,6 +57,21 @@ struct IPv4Collector {
|
||||
}
|
||||
};
|
||||
|
||||
struct InterfaceIDCollector {
|
||||
uint32_t id;
|
||||
bool found;
|
||||
const char *iface;
|
||||
|
||||
InterfaceIDCollector(const char *interface) : id(0), found(false), iface(interface) { }
|
||||
|
||||
void operator() (struct ifaddrs *addr) {
|
||||
if(!found && !strcmp(addr->ifa_name, iface)) {
|
||||
id = addr->ifa_flags;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct HWAddressCollector {
|
||||
uint8_t *result;
|
||||
bool found;
|
||||
@@ -173,6 +188,13 @@ bool Tins::Utils::interface_hwaddr(const string &iface, uint8_t *buffer) {
|
||||
return collector.found;
|
||||
}
|
||||
|
||||
bool Tins::Utils::interface_id(const string &iface, uint32_t &id) {
|
||||
InterfaceIDCollector collector(iface.c_str());
|
||||
generic_iface_loop(collector);
|
||||
id = collector.id;
|
||||
return collector.found;
|
||||
}
|
||||
|
||||
uint32_t Tins::Utils::crc32(uint8_t* data, uint32_t data_size) {
|
||||
uint32_t i, crc = 0;
|
||||
static uint32_t crc_table[] = {
|
||||
|
||||
Reference in New Issue
Block a user