diff --git a/configure.in b/configure.in
index 632456d..026b8c6 100644
--- a/configure.in
+++ b/configure.in
@@ -1015,17 +1017,26 @@ if test $glib_native_win32 = no; then
 
   # We can't just use AC_CHECK_FUNC/AC_CHECK_LIB here. Bug 586150
   AC_MSG_CHECKING([for res_query])
-  AC_TRY_LINK([#include <resolv.h>],
+  AC_TRY_LINK([#include <sys/types.h>
+#include <netinet/in.h>
+#include <nameser.h>
+#include <resolv.h>],
               [res_query("test", 0, 0, (void *)0, 0);],
               [AC_MSG_RESULT([yes])],
               [save_libs="$LIBS"
                LIBS="-lresolv $LIBS"
-               AC_TRY_LINK([#include <resolv.h>],
+               AC_TRY_LINK([#include <sys/types.h>
+#include <netinet/in.h>
+#include <nameser.h>
+#include <resolv.h>],
                            [res_query("test", 0, 0, (void *)0, 0);],
                            [AC_MSG_RESULT([in -lresolv])
                             LIBASYNCNS_LIBADD="-lresolv"],
                            [LIBS="-lbind $save_libs"
-                            AC_TRY_LINK([#include <resolv.h>],
+                            AC_TRY_LINK([#include <sys/types.h>
+#include <netinet/in.h>
+#include <nameser.h>
+#include <resolv.h>],
                                         [res_query("test", 0, 0, (void *)0, 0);],
                                         [AC_MSG_RESULT([in -lbind])
                                          LIBASYNCNS_LIBADD="-lbind"],
