zlacker

[return to "The Source History of Cat"]
1. LukeSh+xi[view] [source] 2018-11-13 02:16:00
>>janvdb+(OP)
I was surprised to read that some versions of cat (apparently BSD Net/2 and derivatives) have special code for sockets. What does cat do with sockets!?

Well, AF_UNIX sockets are sockets with paths in the filesystem. You must either connect() to them or bind() to them instead of open()ing them. Apparently, BSD-derived versions of cat will try to connect() to to a file if open() fails.

With GNU cat, if you try to cat a socket, it will go like this:

    $ ls -l test.sock
    srwxr-xr-x 1 luke users 0 Nov 12 21:07 test.sock
    $ cat test.sock 
    cat: test.sock: No such device or address
but BSD-derived cats will successfully open the socket for reading. That behavior can be accomplished on other systems by using socat instead; BSD cat behaves somewhat like:

    $ socat UNIX:test.sock STDOUT
◧◩
2. loeg+5D2[view] [source] 2018-11-14 02:11:43
>>LukeSh+xi
Hah, I learned something about cat today. Thanks.

Amusingly, the BSD socket behavior can be disabled with the compiler macro -DNO_UDOM_SUPPORT, but as far as I can tell it is not documented nor hooked into the rest of the build system in any way since its introduction in 2001:

https://svnweb.freebsd.org/base?view=revision&revision=83482

[go to top]