Re: /dev/tcp

Richard Kettlewell <[email protected]>
Newsgroups comp.os.linux.misc
Organization terraraq NNTP server
Message-ID <[email protected]>
Eli the Bearded <*@eli.users.panix.com> writes:
> What system(s) have /dev/tcp/* natively?

Quite possibly none.

>   $ man bash
>   [...]
>   REDIRECTION
>   [...]
>        Bash handles several filenames specially when they are used in
>        redirections,  as described  in the  following table.   If the
>        operating  system on  which  bash is  running  provides  these
>        special files, bash will use them;  other wise it will emulate
>        them internally with the behavior described below.
>   [...]
>               /dev/tcp/host/port
> 		  If  host  is a valid  hostname or Internet address,
> 		  and port is an integer port number or service name,
> 		  bash attempts to open the corresponding TCP socket.
>
> I don't see it on the various systems I have handy (Debian 13, Amazon
> Linux 2023, Mac OS 15.7.x, NetBSD 10.1, Android 14).

The documentation is wrong, at least based on the Bash 5.2.21 source in
Ubuntu. If a filename matches /dev/tcp/*/* then it will call socket &
connect, whatever exists in the local OS. The behaviour can be disabled
at build time but I see nothing that queries the target platform’s
capabilities.

> is it a plan9 thing?

I wondered that, but based on https://9p.io/sys/doc/net/net.html, no.
Plan 9 has /net/tcp but it doesn’t behave like Bash’s /dev/tcp special
case.

Solaris (and other SYSV) has a /dev/tcp but that also does not behave
like the Bash special case, it just provides you with a handle on the
TLI provider for TCP, in case you like gratuitous incompatibility.

-- 
https://www.greenend.org.uk/rjk/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.