--- configure.in.orig	Thu Jul 29 09:43:13 2004
+++ configure.in	Mon Dec 13 17:53:21 2004
@@ -163,13 +163,36 @@
 AC_SUBST(NEED_SOCKLEN_T_DEFINE)
 
 dnl HP-UX needs -d_XOPEN_SOURCE_EXTENDED for h_errno
-AC_MSG_CHECKING(for h_errno)
-AC_EGREP_HEADER(h_errno, netdb.h, [AC_MSG_RESULT(normal)],
-   [CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE_EXTENDED"
-    AC_EGREP_HEADER(h_errno, netdb.h, 
-       [AC_MSG_RESULT(needs _XOPEN_SOURCE_EXTENDED)],
-       [AC_MSG_ERROR("not found.")])
-   ])
+AC_MSG_CHECKING(if netdb.h declares h_errno)
+AC_TRY_LINK([
+	#include <netdb.h>
+	], [
+		return h_errno;
+	], [
+		aptget_cv_netdb_declares_h_errno=yes
+	], [
+		aptget_cv_netdb_declares_h_errno=no
+	])
+
+if test "x$aptget_cv_netdb_declares_h_errno" = "xno"; then
+	CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE_EXTENDED"
+fi
+
+AC_TRY_LINK([
+	#include <netdb.h>
+	], [
+		return h_errno;
+	], [
+		aptget_cv_netdb_declares_h_errno=yes
+	], [
+		aptget_cv_netdb_declares_h_errno=no
+	])
+
+AC_MSG_RESULT([$aptget_cv_netdb_declares_h_errno])
+
+if test "x$aptget_cv_netdb_declares_h_errno" = "xno"; then
+	AC_MSG_ERROR([h_errno is required])
+fi
 
 dnl Check for debiandoc
 AC_PATH_PROG(DEBIANDOC_HTML,debiandoc2html)
