Query TCP buffer sizes for a socket on linux

linux-networkingtcp

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.

Best Answer

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)

Related Topic