home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.muug.mb.ca
/
2014.06.ftp.muug.mb.ca.tar
/
ftp.muug.mb.ca
/
pub
/
src
/
gopher
/
gopher1.01
/
misc
/
shell-utils
/
gophercat
< prev
next >
Wrap
Text File
|
1991-08-29
|
2KB
|
81 lines
#!/usr/local/bin/perl
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);
}
$ZeName = shift(@ARGV) || die "I need an argument\n";
open(GopherFile, "/tmp/.gopher") || die "You haven't run gsetup yet!";
$Firstline = <GopherFile>;
($CurrentHost, $Port, $Path) = split('\t',$Firstline);
&Opengopher( $CurrentHost, $Port);
print S "$Path\n";
while (<S>) {
chop;
chop;
($ObjName, $Path, $Host, $Port) = split('\t', $_, 6);
$Name = substr($ObjName, 1);
$Obj = substr($ObjName, 0, 1);
if ($ZeName eq $Name) {
$ZePath = $Path;
$ZeHost = $Host;
$ZePort = $Port;
}
}
close S;
&Opengopher( $ZeHost, $ZePort);
print S "$ZePath\r\n";
while (<S>) {
chop;
chop;
print;
print "\n";
}