显示插座选项 [英] Display socket options

查看:67
本文介绍了显示插座选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从外壳中看到设置了哪些套接字选项?特别是 我很想知道是否设置了SO_BROADCAST?

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

推荐答案

您可以使用 lsof(8) .如果PID是进程ID,而FD是您感兴趣的套接字的文件描述符号,则可以执行以下操作:

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

列出进程的所有IPv4套接字:

To list all IPv4 sockets of a process:

lsof -a -p PID -i 4 -T f

这将打印出带有SO=的套接字选项,以及其他信息.请注意,如果未设置任何选项,则将得到空字符串,因此会看到类似SO=PQLEN=0等的内容.要测试SO_BROADCAST,只需在SO=之后使用grep表示字符串SO_BROADCAST.

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

这篇关于显示插座选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆