crashing with MSG_PEEK

Started by
1 comment, last by Raloth 20 years, 1 month ago
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.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
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.
The only thing I''m worried about is that my program might not send anything larger than the maximum size, but someone elses might...
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...

This topic is closed to new replies.

Advertisement