X-Git-Url: https://git.distorted.org.uk/~mdw/secnet/blobdiff_plain/e61a41a48cdc15d9743731deed717961fdcf4da2..af7201526cf9637ca59c48f3844da165c51d71c0:/polypath-interface-monitor-linux diff --git a/polypath-interface-monitor-linux b/polypath-interface-monitor-linux index 1b02bfa..0393382 100755 --- a/polypath-interface-monitor-linux +++ b/polypath-interface-monitor-linux @@ -5,6 +5,13 @@ use IO::Handle; my $us = $0; $us =~ s{.*/}{}; +open DEBUG, ">/dev/null" or die $!; + +if (@ARGV && $ARGV[0] eq '-D') { + shift @ARGV; + open DEBUG, ">&STDERR" or die $!; +} + die "$us: no arguments permitted\n" if @ARGV; our ($monh,$monchild); @@ -44,14 +51,29 @@ for (;;) { die "monitor failed\n" unless $got; } $_='r' foreach values %reported; + print DEBUG "#########################################\n"; foreach my $ip (qw(4 6)) { + print DEBUG "###### $ip:\n"; my $addrh = new IO::File; open $addrh, "-|", qw(ip -o), "-$ip", qw(addr show) or die "spawn addr $ip show: $!\n"; my $afstr = $ip==4 ? 'inet' : $ip==6 ? 'inet6' : die; while (<$addrh>) { + print DEBUG "#$_"; if (m{^\d+\:\s*(\S+)\s+$afstr\s+([0-9a-z.:]+)(?:/\d+)?\s}) { + my $rhs=$'; #'; my $outline = "$ip $1 $2"; + # "ip -o addr show" has a ridiculous output format. In + # particular, it mixes output keywords which introduce + # values with ones which don't, and there seems to be + # no way to tell without knowing all the possible + # keywords. We hope that before the \ there is nothing + # which contains arbitrary text (specifically, which + # might be `tentative' other than to specify IPv6 + # tentativeness). We have to do this for IPv6 only + # because in the IPv4 output, the interface name + # appears here! + next if $ip==6 && $rhs=~m{[^\\]* tentative\s}; $reported{$outline} .= "y"; } else { chomp;