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 / ungopher < prev   
Text File  |  1992-02-16  |  2KB  |  79 lines

  1. #!/usr/local/bin/perl
  2. # ungopher - vacuum out gopher tunnels
  3.  
  4. # usage:
  5. # ungopher [www style gopher reference]
  6. # ungopher gopher://gopher.msen.com:70/cicnet
  7.  
  8. # original NNTP client suggested by eci386!clewis
  9. # socket code mailed to me by cmf@obie.cis.pitt.edu (Carl M. Fongheiser)
  10. # adaptation for gopher by emv@msen.com (Edward Vielmetti)
  11.  
  12. # Configuration information -- change to reflect your site.
  13.  
  14. $DEFAULTGOPHER='gopher://gopher.msen.com:70/';
  15. $GOPHER=$ARGV[0] ? $ARGV[0] : $DEFAULTGOPHER ;
  16.  
  17. ($host, $port, $path) = &parseref($GOPHER);
  18.  
  19. $DEBUG = 1;                # uh, if it don't work
  20.  
  21. print "$GOPHER\n" if ($DEBUG);
  22. print "host=$host; port=$port; path=$path\n" if ($DEBUG);
  23.  
  24. if ($GOPHER) {
  25.  
  26.    require 'sys/socket.ph';
  27.  
  28.    $sockaddr = 'S n a4 x8';
  29.  
  30.    chop($hostname = `hostname`);
  31.  
  32.    ($name,$aliases,$proto) = getprotobyname('tcp');
  33.    ($name,$aliases,$port) = getservbyname($port, 'tcp')
  34.     unless $port =~ /^\d+$/;
  35.    ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname);
  36.    ($name,$aliases,$type,$len,$thataddr) = gethostbyname($host);
  37.  
  38.    $this = pack($sockaddr, &AF_INET, 0, $thisaddr);
  39.    $that = pack($sockaddr, &AF_INET, $port, $thataddr);
  40.  
  41.    socket(N, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!";
  42.    bind(N, $this) || die "bind: $!";
  43.    connect(N, $that) || die "connect: $!";
  44.  
  45.    $DEBUG && print "sending path=$path\n";
  46.    send(N,"$path\r\n",0);
  47.    print STDERR "$path\r\n" if ($DEBUG);
  48.    while(<N>)  {
  49.       chop;chop; 
  50.       next if /^[\. ]*$/;
  51.       s/^(.)// && ( $type = $1);
  52.       @G= split(/\t/);
  53.       print "Type=$type\n";
  54.       print "Name=$G[0]\n";
  55.       print "Path=$G[1]\n";
  56.       print "Host=$G[2]\n";
  57.       print "Port=$G[3]\n\n";
  58.    }
  59.  
  60.    close(N);
  61.  
  62. }
  63.  
  64. sub parseref {
  65.     # turn gopher://gopher.msen.com:70/cicnet/
  66.     # into
  67.     # host=gopher.msen.com; port=70; path=/cicnet/
  68.     local($_) = @_;
  69.     local($host, $port, $path);
  70.     if (/^(gopher:\/\/)([^:]+):(\d+)(.*)$/) 
  71.         {
  72.         $host = $2;
  73.         $port=$3;
  74.         $path=$4;
  75.         }
  76.     return($host, $port, $path);
  77. }
  78.  
  79.