/[pxelator]/bin/dhcpd.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /bin/dhcpd.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by dpavlin, Sun Jul 26 00:38:57 2009 UTC revision 8 by dpavlin, Mon Jul 27 11:46:44 2009 UTC
# Line 14  die "need to run $0 as root like this\ns Line 14  die "need to run $0 as root like this\ns
14    
15  my $debug = shift @ARGV;  my $debug = shift @ARGV;
16    
17  my $ip_server = '10.0.0.100';  our ( $server_ip, $next_file );
18    require "config.pl";
19    
20  my $sock = IO::Socket::INET->new(  my $sock = IO::Socket::INET->new(
21          LocalPort       => 67,          LocalPort       => 67,
# Line 37  sub client_ip { Line 38  sub client_ip {
38          my $ip = $_mac2ip->{$mac};          my $ip = $_mac2ip->{$mac};
39          return $ip if $ip;          return $ip if $ip;
40    
41          $ip = "10.0.0.$_ip";          $ip = $server_ip;
42            $ip =~ s{\.\d+$}{.$_ip};
43          $_mac2ip->{$mac} = $ip;          $_mac2ip->{$mac} = $ip;
44    
45          $_ip++;          $_ip++;
# Line 71  while (1) { Line 73  while (1) {
73                  my $mac = substr($dhcp->chaddr(),0,$dhcp->hlen()*2);                  my $mac = substr($dhcp->chaddr(),0,$dhcp->hlen()*2);
74                  my $ip = client_ip($mac);                  my $ip = client_ip($mac);
75    
76                    my $file =  $next_file;
77                    $file = 'undionly.kpxe' if ! $file || $dhcp->getOptionValue(DHO_USER_CLASS()) ne 'gPXE';
78    
79                  my $packet = new Net::DHCP::Packet(                  my $packet = new Net::DHCP::Packet(
80                          Op              => BOOTREPLY(),                          Op              => BOOTREPLY(),
81                          Hops    => $dhcp->hops(),                          Hops    => $dhcp->hops(),
# Line 78  while (1) { Line 83  while (1) {
83                          Flags   => $dhcp->flags(),                          Flags   => $dhcp->flags(),
84                          Ciaddr  => $dhcp->ciaddr(),                          Ciaddr  => $dhcp->ciaddr(),
85                          Yiaddr  => $ip,                          Yiaddr  => $ip,
86                          Siaddr  => $ip_server,                          Siaddr  => $server_ip,
87                          Giaddr  => $dhcp->giaddr(),                          Giaddr  => $dhcp->giaddr(),
88                          Chaddr  => $dhcp->chaddr(),                          Chaddr  => $dhcp->chaddr(),
89                          File    => 'undionly.kpxe',                          File    => $file,
90  #                       DHO_DHCP_MESSAGE_TYPE() => DHCPACK(),  #                       DHO_DHCP_MESSAGE_TYPE() => DHCPACK(),
91                  DHO_SUBNET_MASK() => '255.0.0.0',                  DHO_SUBNET_MASK() => '255.0.0.0',
92                  );                  );
93    
94                  warn ">> $mac == $ip server $ip_server\n";                  warn ">> $mac == $ip server $server_ip\n";
95                                    
96                  warn "## ",$packet->toString(),"\n" if $debug;                  warn "## ",$packet->toString(),"\n" if $debug;
97    
98                  my $reply = IO::Socket::INET->new(                  my $reply = IO::Socket::INET->new(
99                          LocalAddr => $ip_server,                          LocalAddr => $server_ip,
100                          LocalPort => 67,                          LocalPort => 67,
101                          Proto => "udp",                          Proto => "udp",
102                          Broadcast => 1,                          Broadcast => 1,

Legend:
Removed from v.1  
changed lines
  Added in v.8

  ViewVC Help
Powered by ViewVC 1.1.26