#!/usr/local/bin/perl5

# Made by Stefan Petersen, E92, KTH for private purpose only.
# Bug reports and ideas to spe@stacken.kth.se
# Standard disclaimer; USE AT YOUR OWN RISK!!

# History:
# 951128 First version born which dumps page to stdout
# 980413 Cleaning up for official export ;-)

# Define port and host
($site,$file,$port) = @ARGV;
$port = 80 unless $port;

# Define SigInt kill process
$SIG{'INT'} = 'dokill';
sub dokill { kill 9,$child if $child; }

use Socket;  # Call in protocol definitions

# Define protocols, addresses and so on for the connection
$sockaddr = 'S n a4 x8';

($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^\d+$/;
($name, $aliases, $type, $len, $siteaddr) = gethostbyname($site);

$site_p = pack($sockaddr, AF_INET, $port, $siteaddr);

socket(S, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
connect(S, $site_p) || die "connect: $!";

select(S); $| = 1; select(stdout);  # set socket to autoflush

# Send WWW-query for the file
print S "GET ".$file."\n";

# Print out what you get and dump it on stdout
while (<S>) {
    print;
    }

close(S);
