[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r10873 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r10873 - gnunet/src/util |
Date: |
Mon, 12 Apr 2010 12:07:22 +0200 |
Author: wachs
Date: 2010-04-12 12:07:22 +0200 (Mon, 12 Apr 2010)
New Revision: 10873
Modified:
gnunet/src/util/resolver_api.c
gnunet/src/util/test_resolver_api.c
Log:
added function GNUNET_RESOLVER_local_hostname_get to resolve local hostname
Modified: gnunet/src/util/resolver_api.c
===================================================================
--- gnunet/src/util/resolver_api.c 2010-04-12 06:54:21 UTC (rev 10872)
+++ gnunet/src/util/resolver_api.c 2010-04-12 10:07:22 UTC (rev 10873)
@@ -669,10 +669,42 @@
/**
- * 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
* @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
* @param callback function to call with addresses
* @param cls closure for callback
Modified: gnunet/src/util/test_resolver_api.c
===================================================================
--- gnunet/src/util/test_resolver_api.c 2010-04-12 06:54:21 UTC (rev 10872)
+++ gnunet/src/util/test_resolver_api.c 2010-04-12 10:07:22 UTC (rev 10873)
@@ -128,6 +128,38 @@
}
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)
{
int *ok = cls;
@@ -198,7 +230,14 @@
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
*/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r10873 - gnunet/src/util,
gnunet <=