#!/afs/athena/contrib/perl/perl

require 'sys/socket.ph';
require 'netinet/in.ph';
require 'netinet/ip.ph';

sub BYTE_ORDER {0;}
sub LITTLE_ENDIAN {0;}
sub BIG_ENDIAN {0;}

$final = pop(@ARGV);
@end = unpack('C4', (gethostbyname($final))[4]);
print("Going to @end, via\n");
for $host (@ARGV) {
    push(@middle, unpack('C4', (gethostbyname($host))[4]));
}
print("@middle\n");


socket(S, &AF_INET, &SOCK_STREAM, &PF_UNSPEC) || die "socket: $!\n";

$opt = pack(sprintf("C C C C%d C4 C",scalar(@middle)),
	    &IPOPT_LSRR, scalar(@middle)+7, 4, @middle, @end, 0);

setsockopt(S, &IPPROTO_IP, &IP_OPTIONS, $opt) || die "setsockopt: $!\n";

print("Set for source routing...\n");
$sin = pack("S n C4 x8", &AF_INET, 13, @end);

# bind(S, pack("S n C4 x8", &AF_INET, 0, 127,0,0,1)) || die "bind: $!\n";
print("Connecting...\n");
connect(S, $sin) || die "connect: $!\n";
#print("Sending CR\n");
#print S "mkgray\n\r";
print("Data----------------------------\n");
print while(<S>);
print("End of Data---------------------\n");

close(S);
