Jump to content
  • Advertisement

Archived

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

Raloth

crashing with MSG_PEEK

This topic is 5189 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
Advertisement
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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!