[comp.bugs.4bsd] gethostby* library bug in 4.3BSD

feldman@tymix.UUCP (Steve Feldman) (11/11/86)

Subject: gethostby* routines fail if no nameserver and using virtual circuits
Index:	lib/libc/net/res_send.c 4.3BSD

Description:
	The gethostbyname() and gethostbyaddr() routines fail if
	there is no nameserver running and sethostent(1) is called
	to try to use a virtual circuit to the nameserver.
	This is because res_send() is incorrectly modifying the errno
	code after a virtual circuit connect fails.
Repeat-By:
	Run "netstat -i" on a machine using /etc/hosts without the
	nameserver running.
Fix:
	Apply the following patch to res_send.c.
	Then recompile netstat and systat in /usr/src/ucb,
	and anything else which does a sethostent(1).

*** /usr/src/lib/libc/net/res_send.c	Wed May  7 15:28:05 1986
--- res_send.c	Mon Nov 10 15:46:25 1986
***************
*** 260,271 ****
  		}
  	   }
  	}
! 	(void) close(s);
  	s = -1;
! 	if (v_circuit == 0 && gotsomewhere == 0)
! 		errno = ECONNREFUSED;
! 	else
! 		errno = ETIMEDOUT;
  	return (-1);
  }
  
--- 260,274 ----
  		}
  	   }
  	}
! 	if (s >= 0)
! 		(void) close(s);
  	s = -1;
! 	if (v_circuit == 0) {
! 		if (gotsomewhere == 0)
! 			errno = ECONNREFUSED;
! 		else
! 			errno = ETIMEDOUT;
! 	}
  	return (-1);
  }