Re: /dev/tcp

Richard Kettlewell <[email protected]>
Newsgroups comp.os.linux.misc
Organization terraraq NNTP server
Message-ID <[email protected]>
Lars Poulsen <[email protected]> writes:
> Eli the Bearded wrote:
>> What system(s) have /dev/tcp/* natively?
>>    [...]
>>                /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.
>
> After several days, we have now ascertained that nobody ever
> implemented this with a true device interface - it is a fiction
> implemented by the shell intercepting the filename and diverting it.
>
> Which is kinda strange. It seems like it should be easier to really do
> it as a true device interface. It would be easier for quick-and-dirty
> programs than the socket interface.

A magic filename would only be useful if it worked everywhere or if you
were only targetting the platform(s) that supported it. All the failure
modes would have to be compressed into a single errno value.

In contrast getaddrinfo+socket+connect is only a few lines of code, it
works everywhere, and you can easily tell the end user which part of the
process failed, when it doesn’t work.

> Maybe the problem is the DNS lookup would have to be done below the
> kernel boundary? But would it really be that much harder than the
> weird stuff done with virtual file systems?

The Linux kernel can already call up to userspace to do DNS lookups:
https://docs.kernel.org/networking/dns_resolver.html

-- 
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.