i want a full example in C to using flags MSG_TRUNC , MSG_CTRUNC in UDP socket
and some explanation to these flags
recvmsg(udpSocket, &msg, flags);
if (msg.msg_flags & MSG_TRUNC)
printf("MSG_TRUNC\n");
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
MSG_TRUNCindicates that the buffer space provided for receiving was insufficient, so that some of the packet data were lost.This flag is used when you want to discover how much data was truncated. The
recvmsgfunction will set this flag (msg_flags) for the structuremsghdr(used for sending UDP packets)You need to add this structs to your code:
And a your receiving buffer:
Init all this stuff:
With the maximum size of the buffer set and the flag MSG_TRUNC set, when you call:
The struct header will be populated after this call, and you can check if your received buffer was truncated or not with this:
EDIT : Using recvfrom
This is a sample on how to use recvfrom with flags: