mirror of
https://github.com/mfontanini/libtins
synced 2026-01-30 05:24:26 +01:00
Utils::route_entries now works on BSD.
This commit is contained in:
@@ -146,18 +146,20 @@ NetworkInterface::NetworkInterface(IPv4Address ip) : iface_id(0) {
|
||||
iface_id = resolve_index("lo");
|
||||
#endif
|
||||
else {
|
||||
Utils::RouteEntry *best_match = 0;
|
||||
const Utils::RouteEntry *best_match = 0;
|
||||
entries_type entries;
|
||||
uint32_t ip_int = ip;
|
||||
Utils::route_entries(std::back_inserter(entries));
|
||||
for(entries_type::const_iterator it(entries.begin()); it != entries.end(); ++it) {
|
||||
if((ip_int & it->mask) == it->destination) {
|
||||
if(!best_match || it->mask > best_match->mask)
|
||||
iface_id = resolve_index(it->interface.c_str());
|
||||
if(!best_match || it->mask > best_match->mask) {
|
||||
best_match = &*it;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(best_match)
|
||||
if(!best_match)
|
||||
throw std::runtime_error("Error looking up interface");
|
||||
iface_id = resolve_index(best_match->interface.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include "arch.h"
|
||||
#include "utils.h"
|
||||
#ifndef WIN32
|
||||
#ifdef BSD
|
||||
#include <sys/socket.h>
|
||||
@@ -44,7 +44,6 @@
|
||||
#include <netdb.h>
|
||||
#include <net/if.h>
|
||||
#endif
|
||||
#include "utils.h"
|
||||
#include "pdu.h"
|
||||
#include "arp.h"
|
||||
#include "ethernetII.h"
|
||||
|
||||
Reference in New Issue
Block a user