*** resolv.orig	Thu May  8 13:33:13 1997
--- resolv.pl	Mon Feb 15 19:21:38 1993
***************
*** 4,9 ****
--- 4,10 ----
  # by Marc Horowitz <marc@mit.edu>
  
  # $Id: resolv.pl,v 1.16 1993/02/11 04:42:21 marc Exp $
+ # minor modifications by <bert@mit.edu>
  
  # The interface works like this (all functions are in the main package)
  #
***************
*** 242,258 ****
  %nstcp = ();			# assoc array of open VC's
  $sockcnt = "nstcp000";
  
  sub sysread_nchars { # @_ = ($fh,$len)
      local($fh,$len) = @_;
      local($tresp, $resp);
  
      $tresp = "";
!     while(length($resp) < $len) {
! 	sysread($fh,$tresp,$len - length($resp)) || die "recv: $!";
  	print "Got a partial response (size=",length($tresp),")\n"
  	    if (&debug && length($tresp) < $len);
  	$resp.=$tresp;
      }
      return($resp);
  }
  
--- 243,264 ----
  %nstcp = ();			# assoc array of open VC's
  $sockcnt = "nstcp000";
  
+ $error = "";
+ 
  sub sysread_nchars { # @_ = ($fh,$len)
      local($fh,$len) = @_;
      local($tresp, $resp);
  
      $tresp = "";
!     $error = "";
!     while((length($resp) < $len) && (! $error)){
! 	if (! sysread($fh,$tresp,$len - length($resp))) { $error = $!; }
! 	else {
  	    print "Got a partial response (size=",length($tresp),")\n"
  		if (&debug && length($tresp) < $len);
  	    $resp.=$tresp;
  	}
+     }
      return($resp);
  }
  
***************
*** 272,286 ****
  
  	    socket($fh,&main'AF_INET,&main'SOCK_STREAM,&main'PF_UNSPEC) ||
  		die "socket: $!";
! 	    connect($fh, $sin) || die "connect: $!";
! 
! 	    $nstcp{$sin} = $fh;
  	}
  
  	if ($packet) {
  	    if (&debug) {
! 		print "Sending to ",join(".",(unpack("S n C4",$sin))[2..5,1])
! 		    ," via TCP\n"; # 
  	    }
  
  	    send($fh,$len,0);
--- 278,293 ----
  
  	    socket($fh,&main'AF_INET,&main'SOCK_STREAM,&main'PF_UNSPEC) ||
  		die "socket: $!";
! #	    connect($fh, $sin) || die "connect: $!";
! 	    if (! connect($fh, $sin)) { $res'error = $!; }
!             else { $nstcp{$sin} = $fh;  $res'error = ""; }
          }
  
+ 	if (! $res'error) {
  	    if ($packet) {
  		if (&debug) {
! 		    print "Sending to ",
! 		      join(".",(unpack("S n C4",$sin))[2..5,1])," via TCP\n";
  		}
  
  		send($fh,$len,0);
***************
*** 288,304 ****
  	}
  
  	if (&debug) {
! 	    print "Receiving from ",join(".",(unpack("S n C4",$sin))[2..5,1])
! 		," via TCP\n";
  	}
  
- 
  	$len = &sysread_nchars($fh,2);
  	if ($len = unpack("n",$len)) {
  	    print "Got a size (size=$len)\n" if (&debug);
  	    $resp = &sysread_nchars($fh,$len);
  	}
  
  	print "Got a response (size=",length($resp),")\n" if (&debug);
  
  	if (! ($options & &main'RES_STAYOPEN)) {
--- 295,313 ----
  	    }
  
  	    if (&debug) {
! 		print "Receiving from ",
! 		  join(".",(unpack("S n C4",$sin))[2..5,1])," via TCP\n";
  	    }
  
  	    $len = &sysread_nchars($fh,2);
+ 	    if (! $res'error) {
  	      if ($len = unpack("n",$len)) {
  		  print "Got a size (size=$len)\n" if (&debug);
  		  $resp = &sysread_nchars($fh,$len);
  	      }
+ 	    }
  
+ 	    if (! $res'error) {
  	      print "Got a response (size=",length($resp),")\n" if (&debug);
  
  	      if (! ($options & &main'RES_STAYOPEN)) {
***************
*** 305,312 ****
  	    foreach (keys(%nstcp)) {
  		if (&debug) {
  		    local($,) = (".");
! 		    print "Disconnecting from ",(unpack("S n C4",$_))[2..5,1]
! 			,"\n";
  		}
  
  		close($_);
--- 314,321 ----
  		foreach (keys(%nstcp)) {
  		    if (&debug) {
  			local($,) = (".");
! 			print "Disconnecting from ",
! 			  (unpack("S n C4",$_))[2..5,1],"\n";
  		    }
  
  		    close($_);
***************
*** 313,321 ****
  	    }
  	    %nstcp = ();
  	}
      } else {
! 	print "Sending to ",join(".",(unpack("S n C4",$sin))[2..5,1])
! 	    ," via UDP\n" if &debug;
  
  	send(NSUDP,$packet,0,$sin) || die "send: $!";
  
--- 322,332 ----
  		}
  		%nstcp = ();
  	      }
+ 	    }
+         }
      } else {
! 	print "Sending to ",
! 	join(".",(unpack("S n C4",$sin))[2..5,1])," via UDP\n" if &debug;
  
          send(NSUDP,$packet,0,$sin) || die "send: $!";
  
***************
*** 328,334 ****
  	print "Got a response (size=",length($resp),")\n" if (&debug);
      }
  
!     &parse_response($resp);
  }
  
  $localns = "";
--- 339,345 ----
          print "Got a response (size=",length($resp),")\n" if (&debug);
      }
  
!     &parse_response($resp) if ! $res'error;
  }
  
  $localns = "";
