Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8350327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:17:00+00:00 2026-06-09T08:17:00+00:00

i want a full example in C to using flags MSG_TRUNC , MSG_CTRUNC in

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:17:01+00:00Added an answer on June 9, 2026 at 8:17 am

    MSG_TRUNC indicates 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 recvmsg function will set this flag (msg_flags) for the structure msghdr (used for sending UDP packets)

    struct msghdr {
           void                  *msg_name;
           int                   msg_namelen;
           struct iovec          *msg_iov;
           __kernel_size_t       msg_iovlen;
           void                  *msg_control;
           __kernel_size_t       msg_controllen;
           unsigned              msg_flags;
    };
    

    You need to add this structs to your code:

    struct msghdr msg;
    struct iovec iov;
    

    And a your receiving buffer:

    char buffer[BUFFER_SIZE];
    

    Init all this stuff:

    iov.iov_base = buffer;
    iov.iov_len = sizeof(buffer);
    
    msg.msg_iov = iov;
    

    With the maximum size of the buffer set and the flag MSG_TRUNC set, when you call:

    recvmsg(udpSocket, &msg, flags);
    

    The struct header will be populated after this call, and you can check if your received buffer was truncated or not with this:

    if (msg.msg_flags & MSG_TRUNC)
    printf("MSG_TRUNC\n");
    

    EDIT : Using recvfrom

    This is a sample on how to use recvfrom with flags:

    char *buffer[BUFFER_MAX_SIZE]; 
    struct sockaddr from;
    socklen_t from_len;
    int available_data;
    int socket;
    
    socket = socket(AF_INET, SOCK_DGRAM, 0);
    
    available_data = recvfrom(socket, (char*)buffer,0, MSG_TRUNC, &from, &fromlen);
    if(available_data > 0)
    {
        if (available_data > BUFFER_MAX_SIZE) 
        {
            fprintf(stderr, "UDP Packet is bigger than expected\n"); 
    
            exit(EXIT_FAILURE);
        }
    
        else 
        { 
            /* Process receiving data */ 
        }
    }
    else
    {
        /* Handle error */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pack to zip some folder using SharpZipLib. Example stucture directory1: directory2:
I want full path of selected file using GWT by using FileUpload. Can you
i want to get the full address of user programatically using c# how can
I am trying to make a full complex search using php and mysql.I want
I need to pick only a full word using regex,I don't want to pick
I want obtain full URL adres in php script, tell please, this code always
I have a series of tables that contain data I want to full text
I want a ListBox full of items. Although, each item should have a different
I really want to have full control of section headers by laying out in
win32 windows application and want to capture full screen and remove the border of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.