Advertisement Jump to content


This topic is now archived and is closed to further replies.


crashing with MSG_PEEK

This topic is 5431 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

Whenever I use the MSG_PEEK flag things crash, but leaving it out leads to no problems . Can anyone help me out with this?
char data[1];
sockaddr_in from;
int fromsize = sizeof(from);
int numbytes = recvfrom(receiveSocket,data,1,MSG_PEEK,(sockaddr*)&from,&fromsize); 
I''m just trying to get the number of bytes that are in the packet that was sent.

Share this post

Link to post
Share on other sites
Using MSG_PEEK will attempt to copy the message to your supplied buffer while also leaving it in the OS packet buffer for the next call to recvfrom(). I doubt that your packets will fit inside the 1-byte buffer you specified. It should give an error but not crash.

It would probably be easier to just have a max packet size and avoid MSG_PEEK alltogether. You might waste a few bytes but its unlikely you need to keep a large amount of unprocessed packets lying around. Any packet larger than your max packet can be safely discarded since you know its not valid for your app.

Share this post

Link to post
Share on other sites
The only thing I''m worried about is that my program might not send anything larger than the maximum size, but someone elses might...

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!