#!/usr/local/bin/perl
# plunder - implement a simple client in perl
# after wjm@feenix.metronet.com, emv@msen.com and a host(?) of others...
$host=$ARGV[0]; $port=$ARGV[1]; shift; shift; $path=join(" ",@ARGV);
$AF_INET = 2; $SOCK_STREAM = 1; $sockaddr = 'S n a4 x8';

($name,$aliases,$type,$len,$thataddr) = gethostbyname($host);
$that = pack($sockaddr, $AF_INET, $port, $thataddr);

if(!socket(S, $AF_INET, $SOCK_STREAM, 0)){
  print "3Error creating socket!\tnopath\tnohost\tnoport\r\n.\r\n";
  exit;
}

if(!connect(S, $that)){
  print "3Can't connect to server!\tnopath\tnohost\tnoport\r\n.\r\n";
  exit;
}

select(S); $| = 1; select(STDOUT);

print S "$path\r\n"; while (read(S, $buf, 1024)) { print $buf; }; close(S);

