/[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 6 by dpavlin, Sun Jul 26 15:16:52 2009 UTC revision 12 by dpavlin, Mon Jul 27 22:18:51 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  our ( $server_ip, $next_file );  our ( $server_ip, $file, $next_file );
 require "config.pl";  
18    
19  my $sock = IO::Socket::INET->new(  my $sock = IO::Socket::INET->new(
20          LocalPort       => 67,          LocalPort       => 67,
# Line 38  sub client_ip { Line 37  sub client_ip {
37          my $ip = $_mac2ip->{$mac};          my $ip = $_mac2ip->{$mac};
38          return $ip if $ip;          return $ip if $ip;
39    
40          $ip = "10.0.0.$_ip";          $ip = $server_ip;
41            $ip =~ s{\.\d+$}{.$_ip};
42          $_mac2ip->{$mac} = $ip;          $_mac2ip->{$mac} = $ip;
43    
44          $_ip++;          $_ip++;
# Line 52  sub client_ip { Line 52  sub client_ip {
52    
53  while (1) {  while (1) {
54    
55            require "config.pl"; # refresh config
56    
57          print "waiting for DHCP requests on ",$sock->sockhost,":",$sock->sockport,"\n";          print "waiting for DHCP requests on ",$sock->sockhost,":",$sock->sockport,"\n";
58    
59          my $buf;          my $buf;
# Line 72  while (1) { Line 74  while (1) {
74                  my $mac = substr($dhcp->chaddr(),0,$dhcp->hlen()*2);                  my $mac = substr($dhcp->chaddr(),0,$dhcp->hlen()*2);
75                  my $ip = client_ip($mac);                  my $ip = client_ip($mac);
76    
77                  my $file =  $next_file;                  if ( ! $file ) {
78                  $file = 'undionly.kpxe' if ! $file || $dhcp->getOptionValue(DHO_USER_CLASS()) ne 'gPXE';                          if ( $dhcp->getOptionValue(DHO_USER_CLASS()) ne 'gPXE' ) {
79                                    $file = 'undionly.kpxe';
80                            } else {
81                                    $file = $next_file;
82                            }
83                    }
84    
85                  my $packet = new Net::DHCP::Packet(                  my $packet = new Net::DHCP::Packet(
86                          Op              => BOOTREPLY(),                          Op              => BOOTREPLY(),

Legend:
Removed from v.6  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.26