How I can see from shell what socket options are set? In particular I'm interesting to know if SO_BROADCAST is set?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
回答2:
On Linux, you can use the knetstat kernel module to inspect socket options, including SO_BROADCAST
.