#!/usr/local/bin/perl # # This script generates a link file on standard output for a given # gopher host/port/directory. # # Example: # # gopherdist gopher.micro.umn.edu 70 # # gopherdist gopher.micro.umn.edu 70 "1/UofM Campus Information" sub dokill { kill 9,$child if $child; } sub Opengopher { local($them,$port) = @_; $them = 'localhost' unless $them; $AF_INET = 2; $SOCK_STREAM = 1; $SIG{'INT'} = 'dokill'; $sockaddr = 'S n a4 x8'; chop($hostname = `hostname`); ($name,$aliases,$proto) = getprotobyname('tcp'); ($name,$aliases,$port) = getservbyname($port,'tcp') unless $port =~ /^\d+$/;; ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname); ($name,$aliases,$type,$len,$thataddr) = gethostbyname($them); $this = pack($sockaddr, $AF_INET, 0, $thisaddr); $that = pack($sockaddr, $AF_INET, $port, $thataddr); # Make the socket filehandle. socket(S, $AF_INET, $SOCK_STREAM, $proto) || die $!; # Give the socket an address. bind(S, $this) || die $!; # Call up the server. connect(S,$that) || die $!; # Set socket to be command buffered. select(S); $| = 1; select(STDOUT); } $Host = shift(@ARGV) || die "Usage: $0 host port [path]"; $Port = shift(@ARGV) || die "Usage: $0 host port [path]"; $Path = shift(@ARGV); &Opengopher( $Host, $Port); print S "$Path\r\n"; while () { chop; chop; if (/^\.$/) { exit; } ($ObjName, $Path, $Host, $Port) = split('\t', $_, 6); $Name = substr($ObjName, 1); $Obj = substr($ObjName, 0, 1); print "Type=$Obj\n"; print "Name=$Name\n"; print "Path=$Path\n"; print "Host=$Host\n"; print "Port=$Port\n"; print "#\n"; }