+ 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;
+ sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ GNUNET_RESOLVER_ip_get(cfg, "localhost", AF_INET, timeout, &check_127,
+ cls);
+ GNUNET_RESOLVER_hostname_get(cfg, (const struct sockaddr *) &sa,
+ sizeof(struct sockaddr), GNUNET_YES, timeout, &check_localhost, cls);
+ GNUNET_RESOLVER_hostname_get(cfg, (const struct sockaddr *) &sa,
+ sizeof(struct sockaddr), GNUNET_NO, timeout, &check_localhost_num, cls);
+ GNUNET_RESOLVER_hostname_resolve(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
+ */
+
+ const char * rootserver_name = ROOTSERVER_NAME;
+ struct hostent *rootserver;
+
+ rootserver = gethostbyname(rootserver_name);
+ if (rootserver == NULL)
+ {
+ /* Error: resolving ip addresses does not work */
+#if DEBUG_RESOLVER
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("gethostbyname() could not lookup IP address: %s\n"),
+ hstrerror (h_errno));
+#endif
+ fprintf (stderr,
+ "System seems to be off-line, will not run all DNS tests\n");
+ *ok = 0; /* mark test as passing anyway */
+ return;
+ }
+
+ /* Counting returned IP addresses */
+ while (rootserver->h_addr_list[count_ips] != NULL)
+ count_ips++;
+ if (count_ips > 1)
+ {
+#if DEBUG_RESOLVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "IP received range for root name server, but a root name server has only 1 IP\n");
+#endif
+ GNUNET_break(0);
+ }
+
+ /* Comparing to resolved address to the address the root name server should have */
+ if (strcmp(inet_ntoa(*(struct in_addr *) rootserver->h_addr_list[0]),
+ ROOTSERVER_IP) != 0)
+ {
+#if DEBUG_RESOLVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "IP received and IP for root name server differ\n");
+#endif
+ GNUNET_break(0);
+ }
+#if DEBUG_RESOLVER
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "System's own forward name resolution is working\n");
+#endif
+
+ /* Resolve the same using GNUNET */
+ GNUNET_RESOLVER_ip_get(cfg, ROOTSERVER_NAME, AF_INET, timeout,
+ &check_rootserver_ip, cls);
+
+ /*
+ * Success: forward lookups work as expected
+ * Next step: reverse lookups
+ */
+
+ struct in_addr rootserver_addr;
+ rootserver->h_name = "";
+ if (1 != inet_pton(AF_INET, ROOTSERVER_IP, &rootserver_addr))
+ {
+#if DEBUG_RESOLVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not transform root name server IP address\n");
+#endif
+ GNUNET_break(0);
+ }
+
+ rootserver
+ = gethostbyaddr(&rootserver_addr, sizeof(rootserver_addr), AF_INET);
+ if (rootserver == NULL)
+ {
+ /* Error: resolving IP addresses does not work */
+#if DEBUG_RESOLVER
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("gethostbyaddr() could not lookup hostname: %s\n"),
+ hstrerror (h_errno));
+#endif
+ GNUNET_break(0);
+ }
+ 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");
+#endif
+ /* Resolve the same using GNUNET */
+
+ memset(&sa, 0, sizeof(sa));