mirror of
https://github.com/mfontanini/libtins
synced 2026-01-29 04:54:28 +01:00
Move Utils::gateway_from_ip into routing utils files
This commit is contained in:
@@ -142,20 +142,6 @@ HWAddress<6> resolve_hwaddr(const NetworkInterface& iface,
|
||||
HWAddress<6> resolve_hwaddr(IPv4Address ip, PacketSender& sender) {
|
||||
return resolve_hwaddr(sender.default_interface(), ip, sender);
|
||||
}
|
||||
|
||||
bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr) {
|
||||
typedef vector<RouteEntry> entries_type;
|
||||
entries_type entries;
|
||||
uint32_t ip_int = ip;
|
||||
route_entries(back_inserter(entries));
|
||||
for (entries_type::const_iterator it(entries.begin()); it != entries.end(); ++it) {
|
||||
if ((ip_int & it->mask) == it->destination) {
|
||||
gw_addr = it->gateway;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
string to_string(PDU::PDUType pduType) {
|
||||
#define ENUM_TEXT(p) case(PDU::p): return #p;
|
||||
|
||||
@@ -425,5 +425,18 @@ set<string> network_interfaces() {
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr) {
|
||||
typedef vector<RouteEntry> entries_type;
|
||||
entries_type entries = route_entries();
|
||||
uint32_t ip_int = ip;
|
||||
for (entries_type::const_iterator it(entries.begin()); it != entries.end(); ++it) {
|
||||
if ((ip_int & it->mask) == it->destination) {
|
||||
gw_addr = it->gateway;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // Utils
|
||||
} // Tins
|
||||
|
||||
Reference in New Issue
Block a user