Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
编辑:删除代码/解释,因为这个项目已经再次给出,学生可以通过这篇文章轻松找到解决方案。
为了澄清发生了什么,我只是在我的 recvfrom() 调用中传递了错误的长度/大小。
在这一行:
if(recvfrom( temp->sockfd, sendHostIP, BUFFER_LEN, 0, (struct sockaddr *)&recvAddr, &recvLen) < 0) errorMsg("recvfrom");
BUFFER_LEN您作为长度 (256)传递,但sendHostIP只是长度MAXHOSTNAMELEN(64)。
BUFFER_LEN
sendHostIP
MAXHOSTNAMELEN
这会导致recvfrom()该缓冲区溢出。当您读入localHostIP.
recvfrom()
localHostIP