tags:

views:

31

answers:

1

How I can see from shell what socket options are set? In particular I'm interesting to know if SO_BROADCAST is set?

+1  A: 

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
Adam Rosenfield
On my system (RHEL 5.3) flag "-T" of lsof can accept "q" and "s", but not "f". Is there another solution?
dimba
You can also try `fuser(1)` http://linux.die.net/man/1/fuser or `netstat(8)` http://linux.die.net/man/8/netstat , but if lsof doesn't work and they don't work, you might be out of luck on your system.
Adam Rosenfield