asserts
[oweals/gnunet.git] / src / util / resolver_api.c
index ecd3789f437ba9dbf3d994af3b7ea45c497c1baf..94844289e261c2141cca2a199671ec1ca6144a37 100644 (file)
@@ -25,6 +25,7 @@
  */
 #include "platform.h"
 #include "gnunet_getopt_lib.h"
+#include "gnunet_os_lib.h"
 #include "gnunet_client_lib.h"
 #include "gnunet_protocols.h"
 #include "gnunet_resolver_service.h"
@@ -668,7 +669,39 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
 
 
 /**
- * Perform a reverse DNS lookup.
+ * 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
  * @param cfg configuration to use
@@ -686,7 +719,7 @@ GNUNET_RESOLVER_hostname_resolve (struct GNUNET_SCHEDULER_Handle *sched,
                                   GNUNET_RESOLVER_AddressCallback callback,
                                   void *cls)
 {
-  char hostname[MAX_HOSTNAME];
+  char hostname[GNUNET_OS_get_hostname_max_length() + 1];
 
   check_config (cfg);
   if (0 != gethostname (hostname, sizeof (hostname) - 1))