【问题标题】:Get absolute path from a fd of an AF_UNIX socket in kernel module从内核模块中的 AF_UNIX 套接字的 fd 获取绝对路径
【发布时间】:2015-10-09 14:33:20
【问题描述】:

给定一个文件描述符,我需要获取它的绝对路径,无论它是普通文件还是AF_UNIX 套接字。 How can I get a filename from a file descriptor inside a kernel module? 的代码适用于常规文件,但使用AF_UNIX 套接字我得到类似"socket:[12345]" 的东西,而不是绝对路径“/tmp/.X11-unix/X0”。

struct sockaddr_un {
                    unsigned short   sun_family;    // AF_UNIX
                    char            sun_path[108];  // pathname
                    };

【问题讨论】:

  • 因为它不是普通文件。

标签: c struct linux-kernel kernel kernel-module


【解决方案1】:

netstat -x 显示了 unix 套接字的完整路径名,通过咨询 /proc/net/unix,由 net/unix/af_unix.c 中的 unix_seq_show 填充。在这里查看它是如何完成的:

http://lxr.free-electrons.com/source/net/unix/af_unix.c?v=4.1#L2252

【讨论】:

    猜你喜欢
    • 2013-04-25
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 2012-10-25
    • 1970-01-01
    相关资源
    最近更新 更多