views:

205

answers:

2

Hello,

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

A: 

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.

Jack
No, it's much larger than that, and a function of how much memory the system has, by default. On most systems these days it's a few megabytes.
Andrew McGregor
A: 

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.

Mark Wilkins