/**
- * Perform a reverse DNS lookup.
+ * Get local hostname
+ *
+ * @param sched scheduler to use
+ * @param cfg configuration to use
+ * @param callback function to call with addresses
+ * @param cls closure for callback
+ * @return handle that can be used to cancel the request, NULL on error
+ */
+void
+GNUNET_RESOLVER_local_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_RESOLVER_HostnameCallback callback,
+ void *cls)
+{
+
+ char hostname[GNUNET_OS_get_hostname_max_length() + 1];
+
+ check_config (cfg);
+ 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 hostname `%s'\n"), hostname);
+#endif
+ callback (cls, hostname);
+}
+
+/**
+ * Looking our own hostname.
*
* @param sched scheduler to use
* @param cfg configuration to use
}
}
+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)
{
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
+ */
+ GNUNET_RESOLVER_local_hostname_get(sched, cfg, &check_local_hostname, cls);
+
+
/*
* Testing non-local DNS resolution
* DNS rootserver to test: a.root-servers.net - 198.41.0.4