How I can see from shell what socket options are set? In particular I'm interesting to know if SO_BROADCAST is set?
ss command is a tool that is used for displaying network socket related information on a Linux system. The tool displays more detailed information that the netstat command which is used for displaying active socket connections.
The SO_LINGER option expects option_value to point to a linger structure, as defined in socket. h. This structure is defined in the following example: struct linger { int l_onoff; ⁄* option on⁄off *⁄ int l_linger; ⁄* linger time *⁄ }; The l_onoff field is set to 0 , if the SO_LINGER option is disabled.
Examining Unix Domain Sockets. To list all listening Unix Domain Sockets, run the ss -xln command. The x flag ensures that only domain sockets are displayed. Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process . . . u_str LISTEN 0 5 /tmp/stream.
You can use lsof(8)
. If PID
is the process ID and FD
is the file descriptor number of the socket you're interested in, you can do this:
lsof -a -p PID -d FD -T f
To list all IPv4 sockets of a process:
lsof -a -p PID -i 4 -T f
This will print out the socket options with a SO=
, among other information. Note that if no options are set, you'll get the empty string, so you'll see something like SO=PQLEN=0
etc. To test for SO_BROADCAST
, just grep for the string SO_BROADCAST
after the SO=
, e.g.
if lsof -a -p PID -d FD -T f | grep -q 'SO=[^=]*SO_BROADCAST'; then
# socket has SO_BROADCAST
else
# it doesn't
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With