From 4235feb43e59ded0690b1273efd5b58f2f03e54e Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Fri, 23 Mar 2012 00:59:58 -0300 Subject: [PATCH] Utils::gateway_from_ip is now working. --- src/utils.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index e5cd733..866823a 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -245,18 +245,19 @@ bool Tins::Utils::gateway_from_ip(uint32_t ip, uint32_t &gw_addr) { ifstream input("/proc/net/route"); bool match(false); string iface; - string destination, mask; + string destination, mask, gw; uint32_t destination_int, mask_int; ip = Utils::net_to_host_l(ip); skip_line(input); while(!match) { - input >> iface >> destination; - for(unsigned i(0); i < 6; ++i) + input >> iface >> destination >> gw; + for(unsigned i(0); i < 5; ++i) input >> mask; from_hex(destination, destination_int); from_hex(mask, mask_int); if((ip & mask_int) == destination_int) { - gw_addr = destination_int; + from_hex(gw, gw_addr); + gw_addr = net_to_host_l(gw_addr); return true; } skip_line(input);