DHCP 服务器无法在虚拟接口中接收我的客户端

DHCP 服务器无法在虚拟接口中接收我的客户端

我正在使用 Python3 中的套接字编写 DHCP 服务器和我自己的客户端。我的客户:

def client(self):
        print("DHCP client is starting...\n")
        dest = ('<broadcast>', serverPort)
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        s.setsockopt(socket.SOL_SOCKET, 25, str("veth0" + '\0').encode('utf-8'))
        #s.bind(('0.0.0.0', clientPort))

        print("Send DHCP discovery.")
        data = DHCP_client.discover_get();
        s.sendto(data, dest)

我的 DHCP 服务器:

def server(self):
    print("DHCP server is starting...\n")
    
    s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1)
    s.bind(('', serverPort))
    dest = ('255.255.255.255', clientPort)

    while(True):
        data, address = s.recv(65536)
        print(data)

但我看不到服务器捕获的任何消息,即使我可以看到来自的请求sudo tcpdump --interface=veth1 -v

    tcpdump: listening on veth1, link-type EN10MB (Ethernet), capture size 262144 bytes
06:32:10.472938 IP (tos 0x0, ttl 64, id 47168, offset 0, flags [DF], proto UDP (17), length 277)
    ubuntu.37318 > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:05:3c:04:8d:59 (oui Unknown), length 249, xid 0x3903f326, Flags [none]
          Client-Ethernet-Address 00:05:3c:04:8d:59 (oui Unknown)
          Vendor-rfc1048 Extensions
            Magic Cookie 0x63825363
            DHCP-Message Option 53, length 1: Discover
            Requested-IP Option 50, length 4: 192.168.1.100

我这里设置有什么问题吗?我不知道为什么recv无法捕捉到任何东西。你对我有什么建议吗?

我创造veth0veth1通过

ip link add veth0 type veth peer name veth1

相关内容