Thread: udp max datagram size

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    26

    udp max datagram size

    i'm writing udp server on windows xp, the problem is i can't send large buffers. Many websites say that i should check the maximum datagram size with getsockopt(), i do so and receive 65507, using this size everything works fine on lan but when i try the server on the internet the datagrams are splitted into 1500 byte packets and i don't get the original datagram, i've read this is ethernet limit (1500 bytes). So how much bytes should my datagram be in order to send it over the internet?

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    This is a mystery that has eluded me for quite some time. After I researched it, this is the best I came up with.

    In theory, a UDP packet's size is the minimum of 65527 (UDP's max size) & any underlying layer. So, let's go down the layers. We already know UDP. Next is IP.

    IP packet size is 20 octets (or more) + data. Let's assume that no options are in use, and it's 20 octets for a header. That leaves 65535 - 20 (or more) for data, or 65515. Minus 8 for our UDP header, and that's 65507. (The number you were getting.) That's for IPv4 - IPv6 will be slightly different.

    Next layer is the link layer, ie ethernet or wireless, etc. This can vary from one section of a network to another too. The link layer has what is known as a "MTU", or max transmission unit. However, we shouldn't need to worry about this because IP will fragment packets for us.

    The kicker, however, comes in RFC 879 (RFC 791 states this as well) which states that hosts are required IP only requires that links be able to handle IP packets up to 576 octets and that
    The maximum size datagram that all hosts are required to accept or reassemble from fragments is 576 octets.
    ...
    Hosts must not send datagrams larger than 576 octets unless they have specific knowledge that the destination host is prepared to accept larger datagrams.
    That said, IPv4's header is (without options) 20 octets and at most, according to RFC 791, 60 octets. UDP's is 8 octets. Thus: 576 - 60 - 8 = 508 octets, a magic number which I've seen recommended by others more than once.

    In practice, you might be able to send more than this, but I would call this a "safe maximum".

    As for becoming what RFC 879 calls "a host with specific knowledge that the destination host is prepared to accept larger datagrams", you can try Path MTU discovery, which is something I know nothing about.
    Last edited by Cactus_Hugger; 03-18-2009 at 05:59 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    links that can only handle 576 bytes are ancient, out-dated- and rarely encountered unless you are communicating with a 3rd world country, which means you still have to consider them when writing code. You will NEVER encounter one of these aritfacts unless you forget to write code to handle them, in which case your ISP will use nothign but those.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    well i've read about mtu, and the minimum i could find was 1492 as i remember, so i succesfully use 1400 byte datagrams

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. char problem
    By eXistenZ in forum Windows Programming
    Replies: 36
    Last Post: 02-21-2005, 06:32 AM
  3. Max size of an INT
    By Thantos in forum C Programming
    Replies: 5
    Last Post: 08-11-2003, 07:43 AM
  4. max int size
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2001, 11:32 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM