]> git.proxmox.com Git - pve-common.git/commitdiff
new helper read_proc_net_route
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 19 May 2014 10:59:08 +0000 (12:59 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 19 May 2014 10:59:08 +0000 (12:59 +0200)
data/PVE/ProcFSTools.pm

index e0a882854d72dd8a9dd6c765e17e81bf9b3d95c3..8bb0d729b50b8ab974cdbc5d3b2ac57d5fe24e70 100644 (file)
@@ -256,4 +256,32 @@ sub write_proc_entry {
     $fh->close();
 }
 
     $fh->close();
 }
 
+sub read_proc_net_route {
+    my $filename = "/proc/net/route";
+
+    my $res = [];
+
+    my $fh = IO::File->new ($filename, "r");
+    return $res if !$fh;
+
+    my $int_to_quad = sub {
+       return join '.' => map { ($_[0] >> 8*(3-$_)) % 256 } (3, 2, 1, 0);
+    };
+
+    while (defined(my $line = <$fh>)) {
+       next if $line =~/^Iface\s+Destination/; # skip head
+       my ($iface, $dest, $gateway, $metric, $mask, $mtu) = (split(/\s+/, $line))[0,1,2,6,7,8];
+       push @$res, {
+           dest => &$int_to_quad(hex($dest)),
+           gateway => &$int_to_quad(hex($gateway)),
+           mask => &$int_to_quad(hex($mask)),
+           metric => $metric,
+           mtu => $mtu,
+          iface => $iface,
+       };
+    }
+
+    return $res;
+}
+
 1;
 1;