gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r11028 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r11028 - gnunet/src/util
Date: Thu, 22 Apr 2010 13:18:48 +0200

Author: wachs
Date: 2010-04-22 13:18:48 +0200 (Thu, 22 Apr 2010)
New Revision: 11028

Modified:
   gnunet/src/util/resolver_api.c
   gnunet/src/util/test_resolver_api.c
Log:


Modified: gnunet/src/util/resolver_api.c
===================================================================
--- gnunet/src/util/resolver_api.c      2010-04-22 09:34:46 UTC (rev 11027)
+++ gnunet/src/util/resolver_api.c      2010-04-22 11:18:48 UTC (rev 11028)
@@ -693,6 +693,38 @@
 }
 
 /**
+ * Get local fully qualified domain name
+ * @return fqdn
+ */
+char *
+GNUNET_RESOLVER_local_fqdn_get ( void )
+{
+  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 NULL;
+    }
+#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\n"),
+                hstrerror (h_errno));
+    return NULL;
+  }
+  return GNUNET_strdup (host->h_name);
+}
+
+/**
  * Looking our own hostname.
  *
  * @param sched scheduler to use

Modified: gnunet/src/util/test_resolver_api.c
===================================================================
--- gnunet/src/util/test_resolver_api.c 2010-04-22 09:34:46 UTC (rev 11027)
+++ gnunet/src/util/test_resolver_api.c 2010-04-22 11:18:48 UTC (rev 11028)
@@ -128,6 +128,44 @@
 }
 
 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 NULL;
+    }
+#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 NULL;
+  }
+
+  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_local_hostname(void *cls, const char *hostname)
 {
   int result = 0;
@@ -219,6 +257,7 @@
       GNUNET_TIME_UNIT_MILLISECONDS, 2500);
   int count_ips = 0;
   char * own_hostname;
+  char * own_fqdn;
 
   memset(&sa, 0, sizeof(sa));
   sa.sin_family = AF_INET;
@@ -240,6 +279,13 @@
   GNUNET_free (own_hostname);
 
   /*
+   * 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
    */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]