8 die "$us: no arguments permitted\n" if @ARGV;
12 # no entry: not reported, does not exist
13 # ry+: reported, entry exists
14 # r: reported, may not still exist (during processing only)
15 # y+: not reported, entry exists
24 open $monh, "-|", qw(ip -o monitor addr)
25 or die "spawn monitor: $!\n";
26 sleep(1) if $restart++;
29 my $got = sysread $monh, $discard, 4096;
30 die "read monitor: $!\n" unless defined $got;
31 die "monitor failed\n" unless $got;
34 #print STDERR "entering", Dumper \%reported;
35 $_='r' foreach values %reported;
36 #print STDERR "cleaned", Dumper \%reported;
37 foreach my $ip (qw(4 6)) {
38 my $addrh = new IO::File;
39 open $addrh, "-|", qw(ip -o), "-$ip", qw(addr show)
40 or die "spawn addr $ip show: $!\n";
41 my $afstr = $ip==4 ? 'inet' : $ip==6 ? 'inet6' : die;
43 if (m{^\d+\:\s*(\S+)\s+$afstr\s+([0-9a-z.:]+)(?:/\d+)?\s}) {
44 my $outline = "$ip $1 $2";
45 $reported{$outline} .= "y";
48 warn "unexpected output from addr $ip show: $_\n";
52 die "addr $ip show failed $!\n" unless $r;
55 #print STDERR "acquired", Dumper \%reported;
56 foreach my $k (keys %reported) {
57 local $_ = $reported{$k};
67 print STDERR "$us: $@";
72 STDOUT->flush or die $!;