linux - 在 netstat 中检索套接字状态的系统调用是什么?

标签 linux sockets

在 netstat 中检索套接字状态的系统调用是什么?我实际上对 netstat 的实现方式并不感兴趣,而是对哪些系统调用可以检索该信息感兴趣。 getsockopt() 似乎获取的是套接字的静态信息,而不是套接字的动态/运行状态。

ssnetstat 似乎采用不同的方法,根据 iproute document说:

This utility presents a new approach, which is supposed to scale well. I am not going to describe technical details here and will concentrate on description of the command. The only important thing to say is that it is not so bad idea to load module tcp_diag, which can be found in directory Modules of iproute2. If you do not make this ss will work, but it falls back to /proc and becomes slow like netstat, well, a bit faster yet (see section "Some numbers").

ss是否使用一些系统调用来获取套接字的运行状态?

最佳答案

它使用“netlink 协议(protocol)”从网络堆栈(内核中的传输层引擎)累积数据。

netlink 协议(protocol)比它更通用,因此为了完整性起见,我们不仅涵盖了套接字统计信息。

特别是对于套接字 [ http://man7.org/linux/man-pages/man7/sock_diag.7.html][sockdiag]子系统。

最近也有 ss 的实现,例如[ https://github.com/svinota/pyroute2/blob/master/cli/ss2][ss2]在 python 。从那里开始,细读它,获得要点就更简单了。

干杯。

关于linux - 在 netstat 中检索套接字状态的系统调用是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54962013/

相关文章:

java - 如何查明客户端/服务器套接字连接的所有资源(线程、PrintWriter 等)是否正确关闭?

c# - 你如何在 C# 中使用 TCP 客户端读取整个输入缓冲区?

c++ - 使用 boost::thread 崩溃

linux - 如何使用 meld 比较不同目录中的两个同名文件(不给出路径)?

linux - 清理 iframe 恶意软件

linux - 排序列表...完成!段错误(核心已转储)

c++ - 运行 shell 脚本时出错 : "pipe call failed"

c# - 尝试使用 C# 访问 Windows 7 计算机上的端口 80 时出错

Python 套接字错误 : [Errno 104] Connection reset by peer

xcode - 沙箱无法访问本地套接字