/usr/share/doc/libnet-frame-device-perl/examples/nfd-print-routes6.pl is in libnet-frame-device-perl 1.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #!/usr/bin/perl
#
# $Id: nfd-print-routes6.pl 354 2012-11-16 15:28:51Z gomor $
#
use strict;
use warnings;
require Net::IPv6Addr;
sub _getIp6 {
my ($dev) = @_;
my $buf = `/sbin/ifconfig $dev 2> /dev/null`;
my $ip6;
if ($buf) {
for (split('\n', $buf)) {
for (split(/\s+/)) {
s/(?:%[a-z0-9]+)$//; # This removes %lnc0 on BSD systems
$ip6 = $_ if Net::IPv6Addr::is_ipv6($_);
last if $ip6;
}
last if $ip6;
}
}
$ip6 =~ s/\/[0-9]+$// if $ip6;
($ip6 && lc($ip6)) || '::1';
}
sub _getRoutesLinux {
my %ifRoutes;
my $buf = `netstat -rnA inet6`;
my %devIps;
if ($buf) {
my @lines = split('\n', $buf);
for (@lines) {
my @elts = split(/\s+/);
if (Net::IPv6Addr::is_ipv6($elts[0])) {
unless (exists $devIps{interface}) {
$devIps{$elts[-1]} = _getIp6($elts[-1]);
}
my $route = {
destination => $elts[0],
nextHop => $elts[1],
interface => $elts[-1],
ip6 => $devIps{$elts[-1]},
};
push @{$ifRoutes{$elts[-1]}}, $route;
}
}
}
else {
carp("Unable to get routes\n");
return undef;
}
\%ifRoutes;
}
my $h = _getRoutesLinux();
use Data::Dumper;
print Dumper($h)."\n";
|