From 4e4f7a239073f7f338d5fe5023d3671230c21581 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 30 Apr 2017 13:12:39 -0700 Subject: [PATCH] Move Utils::gateway_from_ip into routing utils files --- include/tins/utils.h | 13 ------------- include/tins/utils/routing_utils.h | 13 +++++++++++++ src/utils.cpp | 14 -------------- src/utils/routing_utils.cpp | 13 +++++++++++++ 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/include/tins/utils.h b/include/tins/utils.h index 27d2128..d4665cb 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -112,19 +112,6 @@ TINS_API HWAddress<6> resolve_hwaddr(const NetworkInterface& iface, */ TINS_API HWAddress<6> resolve_hwaddr(IPv4Address ip, PacketSender& sender); -/** - * \brief Finds the gateway's IP address for the given IP - * address. - * - * \param ip The IP address for which the default gateway will - * be searched. - * \param gw_addr This parameter will contain the gateway's IP - * address in case it is found. - * - * \return bool indicating whether the lookup was successfull. - */ -TINS_API bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr); - /** * \brief Converts a PDUType to a string. * \param pduType The PDUType to be converted. diff --git a/include/tins/utils/routing_utils.h b/include/tins/utils/routing_utils.h index 71a5863..a162841 100644 --- a/include/tins/utils/routing_utils.h +++ b/include/tins/utils/routing_utils.h @@ -133,6 +133,19 @@ TINS_API std::vector route6_entries(); */ TINS_API std::set network_interfaces(); +/** + * \brief Finds the gateway's IP address for the given IP + * address. + * + * \param ip The IP address for which the default gateway will + * be searched. + * \param gw_addr This parameter will contain the gateway's IP + * address in case it is found. + * + * \return bool indicating whether the lookup was successfull. + */ +TINS_API bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr); + } // Utils } // Tins diff --git a/src/utils.cpp b/src/utils.cpp index 9940c91..8d91f8b 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -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 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; diff --git a/src/utils/routing_utils.cpp b/src/utils/routing_utils.cpp index 31fca0d..c2d3229 100644 --- a/src/utils/routing_utils.cpp +++ b/src/utils/routing_utils.cpp @@ -425,5 +425,18 @@ set network_interfaces() { } #endif // _WIN32 +bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr) { + typedef vector 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