LRN: Fix automake deps to allow -j* builds again
[oweals/gnunet.git] / src / util / test_resolver_api.c
index 734420e84ec06a3033b09dedd75f33195abd31b3..39cfa43fc4c3982e6b26d39780ac1328e11a7a47 100644 (file)
@@ -54,6 +54,7 @@ check_hostname(void *cls, const struct sockaddr *sa, socklen_t salen)
       GNUNET_a2s(sa, salen));
 }
 
+
 static void
 check_localhost_num(void *cls, const char *hostname)
 {
@@ -78,6 +79,7 @@ check_localhost_num(void *cls, const char *hostname)
     }
 }
 
+
 static void
 check_localhost(void *cls, const char *hostname)
 {
@@ -94,11 +96,9 @@ check_localhost(void *cls, const char *hostname)
     }
   else
     {
-#if DEBUG_RESOLVER
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-          "Received invalid hostname `%s'.\n", hostname);
-#endif
-      GNUNET_break(0);
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                 "Received unexpected hostname `%s', expected `localhost' (this could be OK).\n", 
+                 hostname);
     }
 }
 
@@ -219,28 +219,22 @@ check_rootserver_name(void *cls, const char *hostname)
 }
 
 static void
-run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
+run(void *cls, char * const *args,
     const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   int *ok = cls;
   struct sockaddr_in sa;
   struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply(
-      GNUNET_TIME_UNIT_MILLISECONDS, 2500);
+      GNUNET_TIME_UNIT_SECONDS, 30);
   int count_ips = 0;
   char * own_fqdn;
 
   memset(&sa, 0, sizeof(sa));
   sa.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+  sa.sin_len = (u_char) sizeof (sa);
+#endif
   sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-  GNUNET_RESOLVER_ip_get(sched, cfg, "localhost", AF_INET, timeout, &check_127,
-      cls);
-  GNUNET_RESOLVER_hostname_get(sched, cfg, (const struct sockaddr *) &sa,
-      sizeof(struct sockaddr), GNUNET_YES, timeout, &check_localhost, cls);
-  GNUNET_RESOLVER_hostname_get(sched, cfg, (const struct sockaddr *) &sa,
-      sizeof(struct sockaddr), GNUNET_NO, timeout, &check_localhost_num, cls);
-  GNUNET_RESOLVER_hostname_resolve(sched, cfg, AF_UNSPEC, timeout,
-      &check_hostname, cls);
-
 
   /*
    * Looking up our own fqdn
@@ -253,7 +247,6 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
    * Testing non-local DNS resolution
    * DNS rootserver to test: a.root-servers.net - 198.41.0.4
    */
-
   const char * rootserver_name = ROOTSERVER_NAME;
   struct hostent *rootserver;
 
@@ -297,7 +290,7 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
 #endif
 
   /* Resolve the same using GNUNET */
-  GNUNET_RESOLVER_ip_get(sched, cfg, ROOTSERVER_NAME, AF_INET, timeout,
+  GNUNET_RESOLVER_ip_get(ROOTSERVER_NAME, AF_INET, timeout,
       &check_rootserver_ip, cls);
 
   /*
@@ -339,19 +332,41 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
   }
 
 #if DEBUG_RESOLVER
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "System's own reverse name resolution is working\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
+             "System's own reverse name resolution is working\n");
 #endif
-  /* Resolve the same using GNUNET */
 
+  /* Resolve the same using GNUNET */
   memset(&sa, 0, sizeof(sa));
   sa.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+  sa.sin_len = (u_char) sizeof (sa);
+#endif
 #ifndef MINGW
   inet_aton(ROOTSERVER_IP, &sa.sin_addr);
 #else
   sa.sin_addr.S_un.S_addr = inet_addr(ROOTSERVER_IP);
 #endif
-  GNUNET_RESOLVER_hostname_get(sched, cfg, (const struct sockaddr *) &sa,
+  GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
       sizeof(struct sockaddr), GNUNET_YES, timeout, &check_rootserver_name, cls);
+
+  memset(&sa, 0, sizeof(sa));
+  sa.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+  sa.sin_len = (u_char) sizeof (sa);
+#endif
+  sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+  GNUNET_RESOLVER_ip_get("localhost", AF_INET, timeout, &check_127,
+                        cls);
+  GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
+      sizeof(struct sockaddr), GNUNET_YES, timeout, &check_localhost, cls);
+
+  GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
+      sizeof(struct sockaddr), GNUNET_NO, timeout, &check_localhost_num, cls);
+  GNUNET_RESOLVER_hostname_resolve(AF_UNSPEC, timeout,
+      &check_hostname, cls);
+
 }
 
 static int
@@ -377,6 +392,7 @@ check()
       "-L", "DEBUG",
 #endif
       "-c", "test_resolver_api_data.conf", NULL);
+  GNUNET_assert (NULL != proc);
   GNUNET_free(fn);
   GNUNET_assert(GNUNET_OK == GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *))
       - 1, argv, "test-resolver-api", "nohelp", options, &run, &ok));