1

I ran an strace on a client application failure and got something like this:

socket(PF_LOCAL, SOCK_SEQPACKET|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
setsockopt(3, SOL_SOCKET, SO_PASSCRED, [1], 4) = 0
connect(3, {sa_family=AF_LOCAL, sun_path="/path/to/socket"}, 19) = -1 EPROTOTYPE (Protocol wrong type for socket)
close(3)                                = 0
exit_group(2)                           = ?
+++ exited with 2 +++

I then tried to guess the socket type by emulating the socket in place with various parameters to socat, but to no avail.

I also looked at the code from this answer here, but it appears to be making a socket, not using an existing one, and I can't seem to find how to get a socket from a path.

Without digging through the source code, is there an easy way to determine the details (such as the protocol type) of an existing socket from the socket's path (if it exists)?

0

You can use lsof /path/to/socket:

COMMAND     PID USER   FD   TYPE             DEVICE SIZE/OFF      NODE NAME
hindsight 19619 root    6u  unix 0xffff88038612b480      0t0 257123917 /path/to/socket

Knowing the PID you can find out more about the process itself:

cat /proc/19619/io 
rchar: 11635200437
wchar: 2722080850
syscr: 16905056
syscw: 920240
read_bytes: 36397568
write_bytes: 3515994112
cancelled_write_bytes: 760422400

Or you could use ss for displaying all Unix sockets.

ss -x
  • -x Display Unix domain sockets
  • -e Show detailed socket information
  • -m Show socket memory usage

and you can filter for some type:

ss -x -A unix_stream

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.