Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find socket options set by an executable program in Linux

Tags:

linux

I need to find out the socket options that an executing client program has set while opening TCP connections to a server. The client is running on Linux. Is it available under /proc/tcp?

like image 969
user963986 Avatar asked May 31 '26 18:05

user963986


1 Answers

I needed to do this too.

lsof doesn't help much as the tcp options aren't exposed in /proc/ as standard.

I used this kernel module https://github.com/veithen/knetstat which I modified to work with older kernel versions as well here: https://github.com/abligh/knetstat

This lets you do:

# cat /proc/net/tcpstat | head
Recv-Q Send-Q Local Address           Foreign Address         Stat Diag Options
     0      0 0.0.0.0:16013           0.0.0.0:*               LSTN      SO_REUSEADDR=0,SO_KEEPALIVE=0,TCP_NODELAY=0
     0      0 127.0.0.1:25            0.0.0.0:*               LSTN      SO_REUSEADDR=1,SO_KEEPALIVE=1,TCP_NODELAY=0
     0      0 0.0.0.0:111             0.0.0.0:*               LSTN      SO_REUSEADDR=1,SO_KEEPALIVE=0,TCP_NODELAY=0
     0      0 0.0.0.0:4643            0.0.0.0:*               LSTN      SO_REUSEADDR=1,SO_KEEPALIVE=0,TCP_NODELAY=0
     0      0 127.0.0.1:753           0.0.0.0:*               LSTN      SO_REUSEADDR=1,SO_KEEPALIVE=0,TCP_NODELAY=0
     0      0 127.0.0.1:113           0.0.0.0:*               LSTN      SO_REUSEADDR=1,SO_KEEPALIVE=0,TCP_NODELAY=0
     0      0 127.0.0.1:754           0.0.0.0:*               LSTN      SO_REUSEADDR=1,SO_KEEPALIVE=0,TCP_NODELAY=0
     0      0 127.0.0.1:1234          0.0.0.0:*               LSTN      SO_REUSEADDR=1,SO_KEEPALIVE=0,TCP_NODELAY=0
     0      0 0.0.0.0:53618           0.0.0.0:*               LSTN      SO_REUSEADDR=0,SO_KEEPALIVE=0,TCP_NODELAY=0
like image 81
abligh Avatar answered Jun 03 '26 12:06

abligh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!