66 |
return $value; |
return $value; |
67 |
} |
} |
68 |
|
|
69 |
|
sub all_conf { |
70 |
|
my $ip = shift; |
71 |
|
my $path = ip_path $ip || return; |
72 |
|
my $conf; |
73 |
|
foreach my $file ( glob("$path/*") ) { |
74 |
|
my $name = $file; |
75 |
|
$name =~ s{^.+/([^/]+)$}{$1}; |
76 |
|
$conf->{ $name } = read_file $file; |
77 |
|
} |
78 |
|
return $conf; |
79 |
|
} |
80 |
sub next_ip($) { |
sub next_ip($) { |
81 |
my $mac = shift; |
my $mac = shift; |
82 |
|
$mac = format::mac($mac); |
83 |
|
|
84 |
my $p = Net::Ping->new; |
my $p = Net::Ping->new; |
85 |
|
|
103 |
|
|
104 |
sub save_ip_mac { |
sub save_ip_mac { |
105 |
my ($ip,$mac) = @_; |
my ($ip,$mac) = @_; |
106 |
|
$mac = format::mac($mac); |
107 |
|
|
108 |
mkdir ip_path($ip) unless -e $ip; |
mkdir ip_path($ip) unless -e ip_path($ip); |
109 |
|
|
110 |
my $mac_path = mac_path($mac); |
my $mac_path = mac_path($mac); |
111 |
unlink $mac_path if -e $mac_path; # XXX audit? |
unlink $mac_path if -l $mac_path; # XXX audit? |
112 |
symlink ip_path($ip), $mac_path; |
symlink ip_path($ip), $mac_path; |
113 |
write_file ip_path($ip,'mac'), $mac; |
write_file ip_path($ip,'mac'), $mac; |
114 |
} |
} |
115 |
|
|
116 |
sub ip_from_mac($) { |
sub ip_from_mac($) { |
117 |
my $mac = shift; |
my $mac = shift; |
118 |
|
$mac = format::mac($mac); |
|
$mac = lc $mac; |
|
|
$mac =~ s{:}{}g; |
|
119 |
|
|
120 |
my $mac_path = mac_path $mac; |
my $mac_path = mac_path $mac; |
121 |
return unless -e $mac_path; |
return unless -e $mac_path; |