Siler
Siler

Reputation: 9514

Bash: connect to Linux abstract UNIX socket

I have an abstract Linux socket listening for connections.

An abstract Linux socket is basically a named AF_UNIX socket - except the name doesn't refer to a file on the file-system. Rather the name is simply a unique name located within the abstract socket namespace inside the kernel.

My question: is there any way to connect to an abstract socket simply using a Bash shell? I know from this question that you can use socat or netcat to connect to a normal named AF_UNIX socket that is associated with a file on the file-system. But when I tried to use this with an abstract socket, it didn't work (it treated my name string as a file, and reported "file not found", which is what I expected.)

So, is there any utility I can use to connect to an abstract Linux socket?

Upvotes: 6

Views: 4835

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295884

Modern versions of socat have an ABSTRACT namespace for just this purpose.

Quoting from the manual:

ABSTRACT-CONNECT:<string>

ABSTRACT-LISTEN:<string>

ABSTRACT-SENDTO:<string>

ABSTRACT-RECVFROM:<string>

ABSTRACT-RECV:<string>

ABSTRACT-CLIENT:<string>

The ABSTRACT addresses are almost identical to the related UNIX addresses except that they do not address file system based sockets but an alternate UNIX domain address space. To archieve this the socket address strings are prefixed with "\0" internally. This feature is available (only?) on Linux. Option groups are the same as with the related UNIX addresses, except that the ABSTRACT addresses are not member of the NAMED group.

Upvotes: 6

Related Questions