-DVERSION=\"${version}\" \
        -I. -I${top_srcdir}/interface \
        -I${stagedir}/include \
-       -I${cares_prefix}/include \
        ${COVERAGE_FLAGS} -D_GNU_SOURCE -DDATAGRID_EXTENSION
 
 LDFLAGS:=${COVERAGE_FLAGS}
        -lglobus_common_${thrflavour} \
        -lglobus_gssapi_gsi_${thrflavour}
 
+ARES_INC:=-I${cares_prefix}/include
 ARES_LIBS:=-L${cares_prefix}/lib -lcares
 
 EX_LIBS:= ${GLOBUS_LIBS} ${ARES_LIBS}
        rm -rf *.o *.lo *.a *.la .libs test_gss
 
 %.o: %.c
-       ${COMPILE} ${GLOBUS_INC} -o $@ -c $<
+       ${COMPILE} ${GLOBUS_INC} ${ARES_INC} -o $@ -c $<
 
 %.thr.o: %.c
-       ${COMPILE} ${GLOBUS_THR_INC} -o $@ -c $<
+       ${COMPILE} ${GLOBUS_THR_INC} ${ARES_INC} -o $@ -c $<
 
 test_gss.o: %.o: %.cpp
        ${CXX} -c ${CFLAGS} ${GLOBUS_INC} ${TEST_INC} -Wno-error $<
 
 extern "C" {
 #endif
 
+#include <sys/time.h>
 #include <stdlib.h>
 
 enum {
 
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 #include <ares.h>
+#include <ares_version.h>
 #include <errno.h>
 
 #include <globus_common.h>
 }
 
 /* ares callback handler for ares_gethostbyname()       */
-static void callback_handler(void *arg, int status, struct hostent *h) {
+#if ARES_VERSION >= 0x010500
+static void callback_handler(void *arg, int status, int timeouts, struct hostent *h)
+#else
+static void callback_handler(void *arg, int status, struct hostent *h)
+#endif
+{
        struct asyn_result *arp = (struct asyn_result *) arg;
 
        switch (status) {
 
 
        timeout.tv_sec = to ? atoi(to) : 10 ;
        timeout.tv_usec = 0;
+       my_cred = NULL;
        
        key_file = cred_file = getenv("X509_USER_PROXY");
        CPPUNIT_ASSERT_MESSAGE("credential file", cred_file);
         sock = socket(PF_INET,SOCK_STREAM,0);
        CPPUNIT_ASSERT_MESSAGE("socket()", sock >= 0);
 
+       memset(&a, 0, sizeof a);
         a.sin_family = AF_INET;
         a.sin_port = 0;
         a.sin_addr.s_addr = INADDR_ANY;