]> git.datanom.net - pve-dhcp-server.git/commitdiff
Adapt to latest code
authorMichael Rasmussen <mir@datanom.net>
Wed, 23 Jul 2014 22:06:06 +0000 (00:06 +0200)
committerMichael Rasmussen <mir@datanom.net>
Wed, 23 Jul 2014 22:06:06 +0000 (00:06 +0200)
dhcp.pl
dhcpd.pl

diff --git a/dhcp.pl b/dhcp.pl
index 56f950239c7b80181fdd93d8a5a189dbb23c1394..7890766decddfe6cd9bf7d93c22cbb617658b9ef 100644 (file)
--- a/dhcp.pl
+++ b/dhcp.pl
@@ -10,11 +10,11 @@ use Net::DHCP::Constants;
 
 use POSIX qw(setsid strftime);
 
-my ($request, $send, $receive, $discover, $response, $buf, $serverip, $myip, $mymac);
+my ($request, $send, $receive, $discover, $response, $buf, $serverip, $myip, $mymac, $hostname);
 
 $mymac = qx/ \/sbin\/ifconfig | grep -P '^eth0.+HWaddr\\s*' | awk '{print \$5}' /;
 $mymac =~ tr/://d;
-
+chomp($hostname = `hostname -s`);
 # Overrule when testing
 #$mymac = '001cc0c33317';
 logger("mac: $mymac");
@@ -33,6 +33,7 @@ $send = IO::Socket::IP->new(  Proto => 'udp',
                                 Broadcast => 1,
                                 PeerPort => 'bootps(67)',
                                 PeerAddr => inet_ntoa(INADDR_LOOPBACK),#(INADDR_BROADCAST),
+                                #PeerAddr => inet_ntoa(INADDR_BROADCAST),
                                 )
       || die "Socket (send) creation error: $@\n";     # yes, it uses $@ here
 
@@ -44,6 +45,7 @@ $discover = Net::DHCP::Packet->new(
               DHO_DHCP_MESSAGE_TYPE() => DHCPDISCOVER(),
               Flags => 0x8000,
                          DHO_VENDOR_CLASS_IDENTIFIER() => 'foo',
+                         DHO_HOST_NAME() => $hostname,
               );
 
 logger("Sending DISCOVER to " . $send->peerhost . ":" . $send->peerport);
@@ -55,6 +57,7 @@ $receive = IO::Socket::IP->new(  Proto => 'udp',
                                 Broadcast => 1,
                                 LocalPort => 'bootpc(68)',
                                 #LocalAddr => inet_ntoa(INADDR_LOOPBACK),#(INADDR_ANY),
+                                LocalAddr => inet_ntoa(INADDR_ANY),
                                 )
       || die "Socket (receive) creation error: $@\n";     # yes, it uses $@ here
 
@@ -64,6 +67,10 @@ $receive->recv($buf, 1024, 0);
 logger("Got response from " . $receive->peerhost . ":" . $receive->peerport);
 $receive->close;
 $response = new Net::DHCP::Packet($buf);
+if ($response->getOptionValue(DHO_DHCP_MESSAGE_TYPE()) == DHCPNAK()) {
+       logger("Request for ip was denied");
+       exit;
+}
 $serverip = $response->getOptionValue(DHO_DHCP_SERVER_IDENTIFIER());
 $myip = $response->yiaddr();
 
@@ -76,6 +83,7 @@ $request = Net::DHCP::Packet->new(
                       Giaddr => $send->sockhost(),
                       DHO_DHCP_MESSAGE_TYPE() => DHCPREQUEST(),
                                          DHO_VENDOR_CLASS_IDENTIFIER() => 'foo',
+                                         DHO_HOST_NAME() => $hostname,
                       DHO_DHCP_REQUESTED_ADDRESS() => $myip,
                       );
 
@@ -90,6 +98,7 @@ $receive = IO::Socket::IP->new(  Proto => 'udp',
                                 Broadcast => 1,
                                 LocalPort => 'bootpc(68)',
                                 #LocalAddr => inet_ntoa(INADDR_LOOPBACK),#inet_ntoa(INADDR_ANY),
+                                LocalAddr => inet_ntoa(INADDR_ANY),
                                 )
       || die "Socket creation error: $@\n";     # yes, it uses $@ here
 
@@ -116,6 +125,7 @@ if ($response->getOptionValue(DHO_DHCP_MESSAGE_TYPE()) == DHCPACK()) {
                                                  Ciaddr => $myip,
                                                  Giaddr => $send->sockhost(),
                                                  DHO_VENDOR_CLASS_IDENTIFIER() => 'foo',
+                                                 DHO_HOST_NAME() => $hostname,
                                                  DHO_DHCP_MESSAGE_TYPE() => DHCPRELEASE()
                                                  );
 
index 2afdbcd638d99c3cefdf4924f0010a9f20b3217a..d2f34442116c17a5ca1ea74c59f529351bdfbea7 100644 (file)
--- a/dhcpd.pl
+++ b/dhcpd.pl
@@ -2,13 +2,13 @@
 
 use strict;
 use warnings;
-use PVE::DHCPServer qw(:constants);
+use PVE::DHCPServer;
 use Data::Dumper;
 
 my $server = PVE::DHCPServer->new(
     NODAEMON => 1,
     DEBUG => 1,
-    LOG_LEVEL => DEBUG);
+    LOG_LEVEL => INFO);
 
 #print Dumper($server);
 $server->run;
This page took 0.062663 seconds and 5 git commands to generate.