Question

I am writing a small C program to understand sockets. What is the maximum length of data returned from recvfrom?

recvfrom(raw, packet_buffer, buf_size, ... );

what is the maximum buf_size in linux. Is there a constant related to this size_t?

Thanks

Was it helpful?

Solution

This isn't really a direct answer ... somewhat oblique to the question. For TCP/IP, even if you determine what the maximum size is on your system, it would probably be best to implement the code to not rely on that. With stream-oriented sockets, the excess data is not lost. So you can call the receive function again to retrieve the remaining data. That is not true with message-oriented (UDP) connections, though.

OTHER TIPS

I think that max is 65535 bytes. It does not depend upon MTU since it's handled by protocol stack by itself.. so basically you have a good abstraction prom the effective packets that are sent on network.

The choice of 2^16 should be so because it's the max size of the TCP window (usually it's not 64kb anyway, but smaller): so it's the maximum buffer the protocol allows for a TCP connection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top