dhtlog updates
[oweals/gnunet.git] / src / util / test_resolver_api.c
index 5802370e3fc529d2c07679daa55baadacada0fb7..2c3f953676ad823fa431828d2baec3c0f9485d72 100644 (file)
@@ -4,7 +4,7 @@
 
  GNUnet is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
+ by the Free Software Foundation; either version 3, or (at your
  option) any later version.
 
  GNUnet is distributed in the hope that it will be useful, but
@@ -127,6 +127,46 @@ check_127(void *cls, const struct sockaddr *sa, socklen_t salen)
     }
 }
 
+static void
+check_local_fqdn(void *cls, const char *gnunet_fqdn)
+{
+  int result = 0;
+
+  struct hostent *host;
+  char hostname[GNUNET_OS_get_hostname_max_length() + 1];
+
+  if (0 != gethostname (hostname, sizeof (hostname) - 1))
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR |
+                           GNUNET_ERROR_TYPE_BULK, "gethostname");
+      return;
+    }
+#if DEBUG_RESOLVER
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              _("Resolving our FQDN `%s'\n"), hostname);
+#endif
+  host = gethostbyname ( hostname );
+  if ( NULL == host)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Could not resolve our FQDN : %s %u\n"),
+                hstrerror (h_errno), h_errno);
+    return;
+  }
+
+  GNUNET_assert( 0 != host);
+
+  result = strcmp(host->h_name, gnunet_fqdn);
+  if ( 0 != result )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+        "Local resolved and resolver resolved fqdns are not equal\n");
+  }
+  GNUNET_assert( 0 == result);
+}
+
+
+
 static void
 check_rootserver_ip(void *cls, const struct sockaddr *sa, socklen_t salen)
 {
@@ -182,10 +222,12 @@ static void
 run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, 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);
   int count_ips = 0;
+  char * own_fqdn;
 
   memset(&sa, 0, sizeof(sa));
   sa.sin_family = AF_INET;
@@ -198,12 +240,21 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
       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
+   */
+  own_fqdn = GNUNET_RESOLVER_local_fqdn_get();
+  check_local_fqdn( NULL, own_fqdn);
+  GNUNET_free_non_null (own_fqdn);
+
   /*
    * Testing non-local DNS resolution
    * DNS rootserver to test: a.root-servers.net - 198.41.0.4
    */
 
-  char const * rootserver_name = ROOTSERVER_NAME;
+  const char * rootserver_name = ROOTSERVER_NAME;
   struct hostent *rootserver;
 
   rootserver = gethostbyname(rootserver_name);
@@ -215,7 +266,9 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
           _("gethostbyname() could not lookup IP address: %s\n"),
           hstrerror (h_errno));
 #endif
-      GNUNET_break(0);
+      fprintf (stderr,
+              "System seems to be off-line, will not run all DNS tests\n");
+      *ok = 0; /* mark test as passing anyway */
       return;
     }
 
@@ -266,7 +319,7 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
       = gethostbyaddr(&rootserver_addr, sizeof(rootserver_addr), AF_INET);
   if (rootserver == NULL)
     {
-      /* Error: resolving ip addresses does not work */
+      /* Error: resolving IP addresses does not work */
 #if DEBUG_RESOLVER
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
           _("gethostbyaddr() could not lookup hostname: %s\n"),
@@ -274,14 +327,16 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
 #endif
       GNUNET_break(0);
     }
-
-  if (0 != strcmp(rootserver->h_name, ROOTSERVER_NAME))
+  else
+  {
+    if (0 != strcmp(rootserver->h_name, ROOTSERVER_NAME))
     {
 #if DEBUG_RESOLVER
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received hostname and hostname for root name server differ\n");
 #endif
       GNUNET_break(0);
     }
+  }
 
 #if DEBUG_RESOLVER
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "System's own reverse name resolution is working\n");
@@ -290,8 +345,11 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
 
   memset(&sa, 0, sizeof(sa));
   sa.sin_family = AF_INET;
+#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,
       sizeof(struct sockaddr), GNUNET_YES, timeout, &check_rootserver_name, cls);
 }