1

Given a file descriptor, I need to get its absolute path whether it is a regular file or a AF_UNIX socket. The code at How can I get a filename from a file descriptor inside a kernel module? works for regular files but with AF_UNIX sockets I get something like this "socket:[12345]" instead of the absolute path "/tmp/.X11-unix/X0".

struct sockaddr_un {
                    unsigned short   sun_family;    // AF_UNIX
                    char            sun_path[108];  // pathname
                    };
Community
  • 1
  • 1
Sapiro
  • 77
  • 7

1 Answers1

1

netstat -x shows the full pathnames for unix sockets, by consulting /proc/net/unix, which is populated by unix_seq_show in net/unix/af_unix.c. See here how it is done:

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