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.
crashing with MSG_PEEK
Whenever I use the MSG_PEEK flag things crash, but leaving it out leads to no problems . Can anyone help me out with this?
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement