C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-15-2009, 04:05 PM   #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?
baccardi is offline   Reply With Quote
Old 03-18-2009, 05:55 PM   #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
Quote:
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.
__________________
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)

Last edited by Cactus_Hugger; 03-18-2009 at 05:59 PM.
Cactus_Hugger is offline   Reply With Quote
Old 03-18-2009, 10:27 PM   #3
Malum in se
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 3,188
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.
__________________
Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.
abachler is offline   Reply With Quote
Old 03-19-2009, 03:39 AM   #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
baccardi is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Implementing the Advanced Encryption Standard KONI C Programming 16 11-23-2007 01:48 PM
char problem eXistenZ Windows Programming 36 02-21-2005 06:32 AM
Max size of an INT Thantos C Programming 5 08-11-2003 07:43 AM
max int size Unregistered C++ Programming 1 10-25-2001 11:32 AM
Hi, could someone help me with arrays? goodn C Programming 20 10-18-2001 09:48 AM


All times are GMT -6. The time now is 03:08 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22