--- bin/dhcpd.pl 2009/07/26 00:38:57 1 +++ bin/dhcpd.pl 2009/07/27 11:46:44 8 @@ -14,7 +14,8 @@ my $debug = shift @ARGV; -my $ip_server = '10.0.0.100'; +our ( $server_ip, $next_file ); +require "config.pl"; my $sock = IO::Socket::INET->new( LocalPort => 67, @@ -37,7 +38,8 @@ my $ip = $_mac2ip->{$mac}; return $ip if $ip; - $ip = "10.0.0.$_ip"; + $ip = $server_ip; + $ip =~ s{\.\d+$}{.$_ip}; $_mac2ip->{$mac} = $ip; $_ip++; @@ -71,6 +73,9 @@ my $mac = substr($dhcp->chaddr(),0,$dhcp->hlen()*2); my $ip = client_ip($mac); + my $file = $next_file; + $file = 'undionly.kpxe' if ! $file || $dhcp->getOptionValue(DHO_USER_CLASS()) ne 'gPXE'; + my $packet = new Net::DHCP::Packet( Op => BOOTREPLY(), Hops => $dhcp->hops(), @@ -78,20 +83,20 @@ Flags => $dhcp->flags(), Ciaddr => $dhcp->ciaddr(), Yiaddr => $ip, - Siaddr => $ip_server, + Siaddr => $server_ip, Giaddr => $dhcp->giaddr(), Chaddr => $dhcp->chaddr(), - File => 'undionly.kpxe', + File => $file, # DHO_DHCP_MESSAGE_TYPE() => DHCPACK(), DHO_SUBNET_MASK() => '255.0.0.0', ); - warn ">> $mac == $ip server $ip_server\n"; + warn ">> $mac == $ip server $server_ip\n"; warn "## ",$packet->toString(),"\n" if $debug; my $reply = IO::Socket::INET->new( - LocalAddr => $ip_server, + LocalAddr => $server_ip, LocalPort => 67, Proto => "udp", Broadcast => 1,