#!/usr/local/bin/perl # # Netprog spring 98 # # test client used for grading proxy web servers # give this perl script the address of the server as a hostname and port number # # This client reads a script that contains commands used to test # project 1 submissions. Supported commands are: # # CONNECT : establish a connection to the proxy server # SEND "string" : send the specified string (in quotes) # SENDFILE file : send the contents of the file # CLOSE : close the TCP socket # SYSTEM command : execute the specified system command require 5.002; use strict; use Socket; # check and make sure we have something to run my $hostname = shift || die "No host specified!"; my $port = shift || die "No port specified!"; my $script = shift || die "No script specified"; np_connect($hostname,$port); #printf("Got a connection\n"); #printf(WEB "GET /~hollingd/netprog/proj1/foo.html HTTP/1.0\r\n\r\n"); #while () { # print; #} # # handles the CONNECT command sub np_connect { my($chost,$cport) = @_; printf("HOST IS $chost, port is $cport\n"); # create a socket socket(WEB, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die $!; my $addr = gethostbyname($chost); # build address of destination # Need perl 5.002 to do this right! my $serv_addr = sockaddr_in($cport,$addr) || die $!; printf("Calling connect\n"); # call connect connect(WEB,$serv_addr) || die $!; select WEB; $|=1; select STDOUT; }