X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-dhcp.git/blobdiff_plain/b3b2ea80e5c3aae0d9ab7814893c4dde05979c89..01aed19cb0d062c77cef8877b2510fe5b1b09ff2:/invirt-dhcpserver diff --git a/invirt-dhcpserver b/invirt-dhcpserver index 04376d0..d4e40e0 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)) @@ -257,6 +254,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)