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))
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)