40 |
sub client_ip { |
sub client_ip { |
41 |
my ( $mac ) = @_; |
my ( $mac ) = @_; |
42 |
|
|
43 |
my $conf = "$server::base_dir/conf/$server::ip"; |
my $conf = $server::conf; |
44 |
mkdir $conf unless -e $conf; |
mkdir $conf unless -e $conf; |
45 |
|
|
46 |
if ( -e "$conf/mac/$mac" ) { |
if ( -e "$conf/mac/$mac" ) { |
54 |
my $prefix = $server::ip; |
my $prefix = $server::ip; |
55 |
$prefix =~ s{\.\d+$}{.}; |
$prefix =~ s{\.\d+$}{.}; |
56 |
my $ip = $prefix . $addr; |
my $ip = $prefix . $addr; |
57 |
|
|
58 |
while ( -e "$conf/ip/$ip" || $p->ping( $ip ) ) { |
while ( -e "$conf/ip/$ip" || $p->ping( $ip ) ) { |
59 |
$ip = $prefix . $addr++; |
$ip = $prefix . $addr++; |
60 |
die "all addresses allocated!" if $addr == $server::ip_to; |
die "all addresses allocated!" if $addr == $server::ip_to; |
62 |
|
|
63 |
write_file "$conf/mac/$mac", $ip; |
write_file "$conf/mac/$mac", $ip; |
64 |
|
|
65 |
if ( -l "$conf/ip/$ip" && readlink "$conf/ip/$ip" ne "$conf/mac/$mac" ) { |
my $ip_path = "$conf/ip/$ip"; |
66 |
unlink "$conf/ip/$ip"; |
mkdir $ip_path unless -e $ip_path; |
67 |
warn "$mac IP changed from ", readlink "$conf/ip/$ip", " to $ip"; |
|
68 |
|
if ( -l "$ip_path/mac" && readlink "$ip_path/mac" ne "$conf/mac/$mac" ) { |
69 |
|
warn "$mac IP changed from ", readlink "$ip_path/mac", " to $ip"; |
70 |
|
unlink "$ip_path/mac"; |
71 |
}; |
}; |
72 |
symlink "$conf/mac/$mac", "$conf/ip/$ip"; |
symlink "$conf/mac/$mac", "$ip_path/mac"; |
73 |
|
|
74 |
print "$mac NEW $ip\n"; |
print "$mac NEW $ip\n"; |
75 |
|
|