/net in Linux: project log

A Glendix project

A test script to fetch over HTTP on command-line

I decided to use HTTP Get request as a good test of the /net filesystem’s first deliverable (once I complete it). I plan to get connect, sendmsg and recvmsg working in order to have this work in Linux. The script just reads and writes to files, and achieves fetching a page over HTTP on Plan 9’s shell. Even so, simple cat and echo commands sent to the netfs in shell do not work, because when we echo connect <ip>!<port> to the ctl file, and exit to terminal again for next command, the file and the connection get closed. Here’s the script, that works on Plan 9:

#!/bin/rc
server=$1
port=80
clonefile=/net/tcp/clone
netdir=()

fn showme {
while (~ `{cat $netdir/status} Established*) {
line=`{read}
if (! ~ $#line 0)
echo $line
}
exit
}

<[5] $clonefile {
netdir=`{basename -d $clonefile} ^ / ^  `{cat /fd/5}
echo connect $server!$port >$netdir/ctl || exit ‘Cannot Connect’
echo connected to tcp!$server!$port on $netdir
cat $netdir/data | tr -d ‘
‘ | showme &

while (cmd=`{read}) {
echo $cmd > $netdir/data
}
}

To use this script, run it with the server ip as an argument. While using the url will work on Plan 9, I have not implemented DNS for /net on Linux yet, so even after I complete the first deliverable, only IPs will work. After you run the command, enter the request as :
GET / HTTP/1.0
Host: <hostname>

You will see the requested page fetched and displayed on your shell. It will be best to use rc from plan9ports though.

Thank you Anant for helping in finishing the above script!

April 20, 2009 - Posted by | Glendix, libfs, Linux kernel, Networking, Plan 9 from Bell Labs

No comments yet.

Leave a comment