MinGW
[oweals/gnunet.git] / src / util / test_resolver_api.c
index 3b41477bd6357297ef1032e123f9ff9c9b65beae..2b7929e0e9809021c9ce7295ae6b91da2c48df68 100644 (file)
@@ -127,6 +127,38 @@ check_127(void *cls, const struct sockaddr *sa, socklen_t salen)
     }
 }
 
+static void
+check_local_hostname(void *cls, const char *hostname)
+{
+  int result = 0;
+
+  char own_hostname[GNUNET_OS_get_hostname_max_length() + 1];
+#if DEBUG_RESOLVER
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+          "Hostname resolved here is `%s'.\n", own_hostname);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+          "Hostname resolved using resolver is `%s'.\n", hostname);
+#endif
+
+  result = gethostname (own_hostname, sizeof (own_hostname) - 1);
+
+  if ( 0 != result )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+        "Could not resolve local hostname\n", own_hostname);
+  }
+  GNUNET_assert( 0 == result);
+
+  result = strcmp(hostname, own_hostname);
+  if ( 0 != result )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+        "Local resolved and resolver resolved hostnames are not equal\n", own_hostname);
+  }
+  GNUNET_assert( 0 == result);
+}
+
+
 static void
 check_rootserver_ip(void *cls, const struct sockaddr *sa, socklen_t salen)
 {
@@ -186,6 +218,7 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
   struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply(
       GNUNET_TIME_UNIT_MILLISECONDS, 2500);
   int count_ips = 0;
+  char * own_hostname;
 
   memset(&sa, 0, sizeof(sa));
   sa.sin_family = AF_INET;
@@ -198,6 +231,14 @@ 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 hostname
+   */
+  own_hostname = GNUNET_RESOLVER_local_hostname_get();
+  check_local_hostname( NULL, own_hostname);
+  GNUNET_free (own_hostname);
+
   /*
    * Testing non-local DNS resolution
    * DNS rootserver to test: a.root-servers.net - 198.41.0.4
@@ -292,7 +333,7 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
 
   memset(&sa, 0, sizeof(sa));
   sa.sin_family = AF_INET;
-  inet_aton(ROOTSERVER_IP, &sa.sin_addr);
+  sa.sin_addr.S_un.S_addr = inet_addr(ROOTSERVER_IP);
 
   GNUNET_RESOLVER_hostname_get(sched, cfg, (const struct sockaddr *) &sa,
       sizeof(struct sockaddr), GNUNET_YES, timeout, &check_rootserver_name, cls);