235711131719
235711131719

Reputation: 37

Socket Descriptor Changed After Call to recvfrom

EDIT: Removed code/explanation because this project has been given again and students can easily find the solution via this post.

To clarify what happened, I simply passed the wrong length/size in my recvfrom() call.

Upvotes: 1

Views: 959

Answers (1)

caf
caf

Reputation: 239011

In this line:

if(recvfrom( temp->sockfd, sendHostIP, BUFFER_LEN, 0, (struct sockaddr *)&recvAddr, &recvLen) < 0)
    errorMsg("recvfrom");

You pass BUFFER_LEN as the length (256), but sendHostIP is only of length MAXHOSTNAMELEN (64).

This causes recvfrom() to overflow that buffer. The same problem occurs when you read in to localHostIP.

Upvotes: 1

Related Questions