Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there any way to lookup the send/receive buffer sizes for TCP sockets?

I've poked around with both netstat and ss, as well as the raw /proc/net/tcp. Lots of goodies there, including the counts of bytes in flight, timers, process name, etc.

But I'd like to be able to diagnose whether some proceses are setting SO_{SND,RCV}BUF...and more interestingly what values the kernel is actually using for each SKB.

share|improve this question
1  
Are you looking for the configuration settings (min/max/default), or the current amount of memory used? –  Hyppy Mar 14 '11 at 20:42

2 Answers 2

From the lsof FAQ (search for "Why doesn't lsof report socket options"), I believe Linux doesn't make the info you're after available. (at least not via /proc)

If it did, you could use lsof -i <pid> -a -i tcp -T f, but -T only takes "qs", not f on Linux. You can get some other info from netstat (netstat --tcp -p -o -e -e -v | grep <pid>) which includes the Send Queue and Receive Queue and some timer info.

What you could do is use strace. You'd have to either run the program via strace (strace -ff -e network,ioctl PROGRAM) or before it sets up the TCP socket (strace -fff -e network,ioctl -p PID). ioctl is how those options would be set, and network should catch enough to tell what connections those are. (but just ioctl and then use lsof to figure out where the connections to should work, too)

share|improve this answer

You can change the size of the receive and the send buffer as follows (send buffer shown):

int buffersize = 64*1024;  // 64k
setsockopt(socket, SOL_SOCKET, SO_SNDBUF, (char *) &buffersize, sizeof(buffersize));

and to get the current size, use:

getsockopt(socket, SOL_SOCKET, SO_SNDBUF, (char &) &buffersize, sizeof(buffersize));

There is a known bug in Linux that reports the current buffer size as 1/2 the set value. I can't remember if the internal value is 1/2 of what was requested, or whether the report is 1/2 of what it really is.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.