X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-dhcp.git/blobdiff_plain/983fb79bd981ce343422d292cc0d1d1831a82158..HEAD:/invirt-dhcpserver diff --git a/invirt-dhcpserver b/invirt-dhcpserver index 04376d0..ffbf839 100755 --- a/invirt-dhcpserver +++ b/invirt-dhcpserver @@ -162,12 +162,9 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer): def SendDhcpPacketTo(self, To, packet): intf = self.backend.find_interface(packet) if intf: - out_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - out_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1) - out_socket.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, intf) - #out_socket.bind((ip, self.listen_port)) - ret = out_socket.sendto(packet.EncodePacket(), (To,self.emit_port)) - out_socket.close() + self.dhcp_socket.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, intf) + ret = self.dhcp_socket.sendto(packet.EncodePacket(), (To,self.emit_port)) + self.dhcp_socket.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, '') return ret else: return self.dhcp_socket.sendto(packet.EncodePacket(),(To,self.emit_port)) @@ -227,12 +224,14 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer): else : s.syslog(s.LOG_INFO,"Get DHCPREQUEST_UNKNOWN_STATE packet : not implemented") - if self.backend.Request(packet) : packet.TransformToDhcpAckPacket() - else : packet.TransformToDhcpNackPacket() - - self.SendPacket(packet) - - + if self.backend.Request(packet): + packet.TransformToDhcpAckPacket() + self.SendPacket(packet) + elif self.backend.Discover(packet): + packet.TransformToDhcpNackPacket() + self.SendPacket(packet) + else: + pass # We aren't authoritative, so don't reply if we don't know them. # FIXME: These are not yet implemented. def HandleDhcpDecline(self, packet): @@ -257,6 +256,14 @@ if '__main__' == __name__: options = { "server_listen_port":67, "client_listen_port":68, "listen_address":"0.0.0.0"} + + myip = socket.gethostbyname(socket.gethostname()) + if not myip: + print "invirt-dhcpserver: cannot determine local IP address by looking up %s" % socket.gethostname() + sys.exit(1) + + dhcp_options['server_identifier'] = myip + backend = DhcpBackend() server = DhcpServer(backend, options)