From dce5c8f6f8e90506f7a4d47f279f496e1450b5ad Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Wed, 31 Aug 2011 06:31:23 +0000 Subject: fix get_routes() which depends on order of entry in /proc/net/route --- NEWS | 2 ++ lib/network/tools.pm | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index ce6d322..e95ecfe 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +- Make get_routes() more robust when parsing /proc/net/route + 0.93: - Make draknetcenter.desktop XDG compliant - Move autostart desktop files to /etc/xdg/autostart diff --git a/lib/network/tools.pm b/lib/network/tools.pm index 0a1d840..9636450 100644 --- a/lib/network/tools.pm +++ b/lib/network/tools.pm @@ -265,7 +265,16 @@ sub get_routes() { my %routes; foreach (cat_("/proc/net/route")) { if (/^(\S+)\s+([0-9A-F]+)\s+([0-9A-F]+)\s+[0-9A-F]+\s+\d+\s+\d+\s+(\d+)\s+([0-9A-F]+)/) { - if (defined $3) { $routes{$1}{gateway} = hex($3) ? host_hex_to_dotted($3) : $routes{$1}{network} } + next if (defined $routes{$1}{has_gateway}); + + if (defined $3) { + if (hex($3)) { + $routes{$1}{gateway} = host_hex_to_dotted($3); + $routes{$1}{has_gateway} = "yes"; + } else { + $routes{$1}{gateway} = $routes{$1}{network}; + } + } if (defined $2) { $routes{$1}{network} = host_hex_to_dotted($2) } if (defined $4) { $routes{$1}{metric} = $4 } } -- cgit v1.2.1