6 |
|
|
7 |
use File::Slurp; |
use File::Slurp; |
8 |
use Net::Ping; |
use Net::Ping; |
|
use Carp qw/confess/; |
|
9 |
|
|
10 |
use server; |
use server; |
11 |
use format; |
use format; |
30 |
} elsif ( -f $path ) { |
} elsif ( -f $path ) { |
31 |
$value = read_file $path; |
$value = read_file $path; |
32 |
} else { |
} else { |
33 |
confess "$path not file or symlink"; |
warn "W: $path not file or symlink\n"; |
34 |
} |
} |
35 |
return $value; |
return $value; |
36 |
} |
} |
84 |
|
|
85 |
warn "next_ip $ip\n"; |
warn "next_ip $ip\n"; |
86 |
|
|
87 |
mkdir ip_path($ip); |
save_ip_mac( $ip, $mac ); |
88 |
|
|
89 |
|
return $ip; |
90 |
|
} |
91 |
|
|
92 |
|
sub save_ip_mac { |
93 |
|
my ($ip,$mac) = @_; |
94 |
|
|
95 |
|
mkdir ip_path($ip) unless -e ip_path($ip); |
96 |
|
|
97 |
my $mac_path = mac_path($mac); |
my $mac_path = mac_path($mac); |
98 |
unlink $mac_path if -e $mac_path; # XXX audit? |
unlink $mac_path if -e $mac_path; # XXX audit? |
99 |
symlink ip_path($ip), $mac_path; |
symlink ip_path($ip), $mac_path; |
100 |
write_file ip_path($ip,'mac'), $mac; |
write_file ip_path($ip,'mac'), $mac; |
|
|
|
|
return $ip; |
|
|
|
|
101 |
} |
} |
102 |
|
|
103 |
sub ip_from_mac($) { |
sub ip_from_mac($) { |