如何在 Linux 上检查 Unix 域套接字路径的最大允许长度
在 Linux 上,这个长度通常定义为 108。
它由头文件中的UNIX_PATH_MAX
变量定义/usr/include/linux/un.h
:
cat /usr/include/linux/un.h | grep "define UNIX_PATH_MAX"
#define UNIX_PATH_MAX 108
Run Code Online (Sandbox Code Playgroud)
您可以在此处找到更多信息:
在 Mac OS X 上,根据unix
手册页:
UNIX-domain addresses are variable-length filesystem pathnames of at most
104 characters. The include file <sys/un.h> defines this address:
struct sockaddr_un {
u_char sun_len;
u_char sun_family;
char sun_path[104];
};
Run Code Online (Sandbox Code Playgroud)
这是一个在 Linux 和 OS X 上编译的程序,它将输出 unix 域套接字路径的最大长度。
#include <sys/un.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
struct sockaddr_un s;
printf("%lu\n", sizeof(s.sun_path));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在 Linux 上,它输出108
,而在 OS X 上,它输出104
.
归档时间: |
|
查看次数: |
6715 次 |
最近记录: |