42 |
sub client_mac_ip { |
sub client_mac_ip { |
43 |
my ( $mac, $request_ip ) = @_; |
my ( $mac, $request_ip ) = @_; |
44 |
|
|
45 |
|
if ( ! $mac ) { |
46 |
|
warn "W: no mac in requiest\n"; |
47 |
|
return; |
48 |
|
} |
49 |
|
|
50 |
my $conf = $server::conf; |
my $conf = $server::conf; |
51 |
mkdir $conf unless -e $conf; |
mkdir $conf unless -e $conf; |
52 |
|
|
100 |
return unless $buf; |
return unless $buf; |
101 |
|
|
102 |
my $dhcp = Net::DHCP::Packet->new($buf); |
my $dhcp = Net::DHCP::Packet->new($buf); |
|
$dhcp->comment( $transaction++ ); |
|
103 |
|
|
104 |
warn "recv: ", $dhcp->toString if $debug; |
warn "recv: ", $dhcp->toString if $debug; |
105 |
|
|
106 |
my $mac = substr($dhcp->chaddr(),0,$dhcp->hlen()*2); |
$dhcp->comment( $transaction++ ); |
107 |
|
|
108 |
|
my $mac = format::mac( substr($dhcp->chaddr(),0,$dhcp->hlen()*2) ); |
109 |
my $ip = client_mac_ip($mac, $dhcp->ciaddr); |
my $ip = client_mac_ip($mac, $dhcp->ciaddr); |
110 |
|
|
111 |
my $hostname = $dhcp->getOptionValue(DHO_HOST_NAME); |
my $hostname = $dhcp->getOptionValue(DHO_HOST_NAME); |
112 |
print "$ip ", client::conf( $ip => 'hostname', default => $hostname ), " >> /etc/hosts\n"; |
print "$ip ", client::conf( $ip => 'hostname', default => $hostname ), " >> /etc/hosts\n" if $hostname; |
113 |
|
|
114 |
my $audit = { mac => format::mac($mac), ip => $ip, hostname => $hostname }; |
my $audit = { mac => $mac, ip => $ip, hostname => $hostname, |
115 |
|
options => { |
116 |
|
map { |
117 |
|
( $_ => $dhcp->getOptionValue( $_ ) ) |
118 |
|
} @{ $dhcp->{options_order} } |
119 |
|
}, |
120 |
|
}; |
121 |
|
|
122 |
=for later |
=for later |
123 |
|
|