-dnl We want to test for crypt() and dlopen() in libc before checking for
-dnl -lcrypt and -ldl, because some systems (like Irix) have both.
-AC_CHECK_FUNCS(crypt dlopen)
+dnl We want to test for the following in libc before checking for their
+dnl respective libraries, because some systems (like Irix) have both, and the
+dnl non-libc versions may be broken.
+AC_CHECK_FUNCS(crypt dlopen gethostbyname connect)
+
+if test "$ac_cv_func_gethostbyname" = no; then
+ AC_CHECK_LIB(nsl, gethostbyname, NETLIBS="-lnsl $NETLIBS")
+fi
+
+if test "$ac_cv_func_connect" = no; then
+ AC_CHECK_LIB(socket, connect, NETLIBS="-lsocket $NETLIBS",, $NETLIBS)
+fi