Jump to content
  • Advertisement
Sign in to follow this  
DrLecter

WSARecvFrom causes WSAEFAULT error

This topic is 4425 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I'm programming an application using UDP and Winsock 2 (asynchronous, but non-overlapped sockets). I've got a problem receiving packets, though... the handling looks like this:
case FD_READ:
  DWORD numberOfBytesReceived;
  sockaddr_in address;
  int sockaddrSize = sizeof(sockaddr);
  int fail = WSARecvFrom(socket, &readBuffer, 1, &numberOfBytesReceived, 0, (sockaddr*) &address, &sockaddrSize, NULL, NULL);

where 'socket' is a socket that has been bound, 'readBuffer' is a WSABUF (and I'm using that casting from sockaddr_in to sockaddr because beej's tutorial told me to). When I send a datagram to the application, I get to the last line, which returns an error. This is defined as: WSAEFAULT The lpBuffers, lpFlags, lpFrom, lpNumberOfBytesRecvd, lpFromlen, lpOverlapped, or lpCompletionRoutine parameter is not totally contained in a valid part of the user address space: the lpFrom buffer was too small to accommodate the peer address. how can the lpFrom parameter ('(sockaddr*) &address') be too small? I'm thankful for any insights into this problem :) Dr. Lecter

Share this post


Link to post
Share on other sites
Advertisement
The line lists all possible things that could cause that error. Chances are, it's something other than the struct sockaddr_in.

If you're going to pass NULL for overlapped/completion, you might as well use regular ::recvfrom() by the way, and make your code more portable.

Last: the lpFlags parameter isn't documented as accepting NULL on MSDN -- try passing a pointer to a DWORD containing 0 instead.

Share this post


Link to post
Share on other sites
int sockaddrSize = sizeof(sockaddr);
Should be:
int sockaddrSize = sizeof(sockaddr_in);
Although I don't know if the structures are actually different sizes...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!