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 8470523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:32:34+00:00 2026-06-10T16:32:34+00:00

I’m currently writing a UDP client/server (on GNU/Linux). I’m using sendto() for sending messages

  • 0

I’m currently writing a UDP client/server (on GNU/Linux).
I’m using sendto() for sending messages on a SOCK_DGRAM socket that has not been bound to a port.

The send(2) manpage states that:

On success, these calls return the number of characters sent. On
error, -1 is returned, and errno is set appropriately.

However, sendto always returns its length parameter, indicating success.
With messages greater than 65507 (0xFFE3) bytes, it returns a Message too long error.

For messages greater than the MTU of 1500 bytes, the server always receives (via recvfrom()) messages of exactly 1500 bytes, simply cutting the message, without further notice.

(Why) is this behaviour intended, and is there a way of getting notified that something went wrong?

The only workaround I can currently think of would be to simply assume a MTU of 1500 bytes and never send bigger packets.

This is the relevant method:

int udp_send(uint32_t dst, uint16_t port, char *msg, unsigned len) {
    int sock = socket(AF_INET, SOCK_DGRAM, 0);
    if(sock < 0) {
            perror("Could not open socket");
            return -1;
    }

    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = htonl(dst);

    int count = sendto(sock, msg, len, 0,
            (struct sockaddr *) &addr, sizeof(addr));
    printf("bytes sent: %d\n", count);

    if(count < 0) {
            perror("Could not send message");
            return -3;
    }

    close(sock);
    return count;
}

A call where the described undesired behaviour occurs would be
udp_send(0x7F000001, 1337, bigbuf, 1501);
which would return 1501 while sending only 1500 bytes.

  • 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-10T16:32:35+00:00Added an answer on June 10, 2026 at 4:32 pm

    It turns out that, as suggested by nos in his comment, my sending code was actually perfectly fine; my receive code had a simple bug: At some point, I defined its buffer to be just 1500 Bytes in size, and forgot about it later.

    Furthermore, I was led by the misconception that GNU/Linux can send UDP packets only to the interface’s MTU, which is not true. Even though the standard only guarantess 576 Bytes, at least in my case it seems possible to send (and receive) UDP packets up to 65507 bytes, after which the Message too long error is returned by the sendto() call. The UDP packets are automatically fragmented by the Kernel’s IP layer, and re-assembled by the receiver – I did not consider that UDP could be capable of such advanced techniques.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.