unix套接字上的连接数

时间:2020-12-31 07:37:23

Given an arbritary unix socket address, am I able to get the number of connections on it via a POSIX api call?

给定一个arbritary unix套接字地址,我是否能够通过POSIX api调用获得它上的连接数?

Or would I have to walk though the /proc filesystem?

或者我必须遍历/proc文件系统吗?

1 个解决方案

#1


3  

I'll assume you mean the number of current connections on a port, not the total connection count over the lifetime of a socket fd which was my first thought. I'm afraid the most portable method is popen("netstat -n", "r") and try to parse it. POSIX gives us very little in the area of system/network administration tools.

我假设您是指在一个端口上的当前连接的数量,而不是一个套接字fd的生存期的总连接数,这是我的第一个想法。恐怕最可移植的方法是popen(“netstat -n”、“r”)并尝试解析它。POSIX在系统/网络管理工具方面给我们的帮助很少。

#1


3  

I'll assume you mean the number of current connections on a port, not the total connection count over the lifetime of a socket fd which was my first thought. I'm afraid the most portable method is popen("netstat -n", "r") and try to parse it. POSIX gives us very little in the area of system/network administration tools.

我假设您是指在一个端口上的当前连接的数量,而不是一个套接字fd的生存期的总连接数,这是我的第一个想法。恐怕最可移植的方法是popen(“netstat -n”、“r”)并尝试解析它。POSIX在系统/网络管理工具方面给我们的帮助很少。