Solaris 11 下的 /proc/net/tcp 替代方案
在大多数 Linux 发行版上,我能够通过读取 /proc/net/tcp 来列出所有 tcp 连接,但这在 Solaris 上不存在,是否有一个文件可以在 Solaris 11 上读取 tcp 连接?
谢谢。
编辑:忘记提及我正在用 c 编码。
On Most Linux Distributions, i was able to list all tcp connections by reading /proc/net/tcp, but this Doesn't exists on solaris, is there a file that i can read tcp connections from on Solaris 11?
thanks.
EDIT: forgot to mention that i'm coding in c.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试重写
netstat
,我建议查看它的源代码:https://hg.java.net/hg/solaris~on-src/file/tip/usr/src/cmd/cmd-inet/usr.bin/netstat/netstat.c重要的部分是
mibopen
,它打开/dev/arp
并将tcp
STREAMS 模块推送到其上,以及mibget 实际请求的连接信息。该代码有点复杂,因此我建议在调试器中单步执行代码以了解其工作原理。关键的系统调用是
open
、ioctl
、putmsg
和getmsg
。如果您只想查看进程打开了哪些套接字,您可以检查
/proc/PID/fd
,如pfiles
中所示:https://hg.java.net/hg/solaris~on-src/file/tip/usr/src/cmd/ptools/pfiles/pfiles.cIf you're trying to rewrite
netstat
, I suggest looking at the source code for it: https://hg.java.net/hg/solaris~on-src/file/tip/usr/src/cmd/cmd-inet/usr.bin/netstat/netstat.cThe important parts are
mibopen
, which opens/dev/arp
and pushes thetcp
STREAMS module onto it, andmibget
which actually requests the connection information. The code is a bit complicated, so I suggest stepping through the code in a debugger to understand how it works. The key syscalls areopen
,ioctl
,putmsg
, andgetmsg
.If you just want to see what sockets a process has open, you can inspect
/proc/PID/fd
, as inpfiles
: https://hg.java.net/hg/solaris~on-src/file/tip/usr/src/cmd/ptools/pfiles/pfiles.c您应该使用
netstat -an
或pcp
You should either use
netstat -an
orpcp