1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 10:45:57 +01:00

Move Utils::gateway_from_ip into routing utils files

This commit is contained in:
Matias Fontanini
2017-04-30 13:12:39 -07:00
parent f764f68e9c
commit 1c2ac61bb0
4 changed files with 26 additions and 27 deletions

View File

@@ -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