我已使用wireshark查看DHCP數據包結構。現在我創建了一個DHCPDISCOVER請求並將其存儲在'消息'中。然後我在網絡上播放它。DHCP客戶端不接收端口68上的響應
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
perror("socket");
exit(1);
}
setsockopt(sockfd,SOL_SOCKET,SO_BROADCAST, &on,sizeof(on));
setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR, &on,sizeof(on));
bzero(&cliaddr, sizeof(cliaddr));
cliaddr.sin_family = AF_INET;
cliaddr.sin_addr.s_addr = htonl(INADDR_ANY);
cliaddr.sin_port = htons(68);
if (bind(sockfd, (struct sockaddr *) &cliaddr, sizeof(cliaddr)) < 0) {
perror("bind");
exit(1);
}
bzero(&addr, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr("255.255.255.255");
addr.sin_port = htons(67);
cnt = sendto(sockfd, message, sizeof(message), 0,(struct sockaddr *) &addr, sizeof(addr));
if (cnt < 0) {
perror("sendto");
exit(1);
}
addrlen = sizeof(servaddr);
cnt = recvfrom(sockfd, reply, sizeof(reply), 0,(struct sockaddr *) &servaddr, &addrlen);
if (cnt < 0) {
perror("recvfrom");
exit(1);
}
printf("\nReply Received\n");
我運行這個程序,並分析發送的數據包,並使用Wireshark的好評。我看到DHCPDISCOVER數據包在端口67上發送,並且在wireshark窗口中的68端口上接收到DHCPOffer數據包。我的客戶端發送的數據包正常,但沒有收到此數據包,並且阻止了recvfrom調用。出了什麼問題?