Plan 9 networking
Using the /net
filesystem
You can make network connections just by interacting with files in /net.
Connecting via TCP
First you could create a new socket by reading the contents of
/net/tcp/clone
, then one would write to the socket in
/net/tcp/$socketno/ctl
, to connect to some host, and then
read/write to /net/tcp/$socketno/data
.
Apparently, one can’t close the /net/tcp/clone
file after
reading from it or the connection will be closed, and this
code keeps it open by piping it to a file descriptor and
not closing it until we’re done.
I don’t know what the file descriptor “5” is.
<[5] /net/tcp/clone { # Pipe the /net/tcp/clone file to fd 5.
# Don't close it until this block is closed?
netdir = '/net/tcp/' ^ `{cat /fd/5}
# Connect to some host 9.9.9.9 on port 19
echo connect 9.9.9.9!19 > $netdir/ctl || echo cant connect
cat $netdir/data
}
This task is eased by the aux/trampoline
tool trampoline(8)
, and by
the dial(2)
C function.
aux/listen1
aux/listen
/bin/service/
By: fgt (Sun Apr 5 23:58:24 EDT 2015)
grep for me please 66969