Making HTTP requests from a container that has no curl, using bash /dev/tcp
16 points by indigo
16 points by indigo
I just had to deal with this exact problem on OpenBSD today!
I found that it also didn't come preinstalled with curl or wget so I wondered how people test out httpd and I got pointed to the ftp program which will download an http url. I know I could install curl and wget but I learned something by not taking the easy route :)
Seeing that bash could support it, I gave it a try on ksh the default shell on OpenBSD to see if I could use that trick and it doesn't work. I probably should have guessed this is a bash specific trick from the blog post, but I wanted to try it anyways.
Depending on the userland, gawk offers the same trick: https://www.gnu.org/software/gawk/manual/html_node/TCP_002fIP-Networking.html
I don't have a default OpenBSD installation within reach at the moment, but isn't nc(1) installed by default?
I just checked, yes it is.
That would be my first choice, then, to do a health check of the sort the author is doing on OpenBSD.
The names were picked because no real Unix has a /dev/tcp or /dev/udp hierarchy, so there’s nothing to collide with.
This sentence cites the man page but that isn’t what the man page says: it says bash will use the system’s /dev/tcp if it has one, or emulate it otherwise. I’m not sure if real /dev/tcp ever happened in practice…
Bash copied this feature from ksh93 (it doesn’t seem to be in ksh88) which is roughly contemporary with the initial work on Plan 9. I suspect the idea was to emulate Plan 9 style features on trad unix. But there was a thing for distributed systems on unix around that time (aiming to work like clustered VAX/VMS) so I suspect there might have been a real /dev/tcp somewhere…