dhtlog updates
[oweals/gnunet.git] / src / util / resolver_api.c
index 96396bfcccc7a61ade1c5c0cd65bc91cdecbe66f..f4832ed9c87924ae28343779872f453a2ad6ec6f 100644 (file)
@@ -189,17 +189,27 @@ no_resolve (const struct sockaddr *sa, socklen_t salen)
     case AF_INET:
       if (salen != sizeof (struct sockaddr_in))
         return NULL;
-      inet_ntop (AF_INET,
-                 &((struct sockaddr_in *) sa)->sin_addr,
-                 inet4, INET_ADDRSTRLEN);
+      if (NULL == 
+         inet_ntop (AF_INET,
+                    &((struct sockaddr_in *) sa)->sin_addr,
+                    inet4, INET_ADDRSTRLEN))
+       {
+         GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+         return NULL;
+       }
       ret = GNUNET_strdup (inet4);
       break;
     case AF_INET6:
       if (salen != sizeof (struct sockaddr_in6))
         return NULL;
-      inet_ntop (AF_INET6,
-                 &((struct sockaddr_in6 *) sa)->sin6_addr,
-                 inet6, INET6_ADDRSTRLEN);
+      if (NULL == 
+         inet_ntop (AF_INET6,
+                    &((struct sockaddr_in6 *) sa)->sin6_addr,
+                    inet6, INET6_ADDRSTRLEN))
+       {
+         GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+         return NULL;
+       }
       ret = GNUNET_strdup (inet6);
       break;
     default:
@@ -225,7 +235,6 @@ handle_address_response (void *cls, const struct GNUNET_MessageHeader *msg)
   const struct sockaddr *sa;
   socklen_t salen;
 
-
   if (msg == NULL)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -417,12 +426,11 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched,
   unsigned int i;
   struct in_addr v4;
   struct in6_addr v6;
-  char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
+  char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
 
   check_config (cfg);
   slen = strlen (hostname) + 1;
-  if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >
-      GNUNET_SERVER_MAX_MESSAGE_SIZE)
+  if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
     {
       GNUNET_break (0);
       return NULL;
@@ -610,7 +618,7 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
   struct GNUNET_CLIENT_Connection *client;
   struct GNUNET_RESOLVER_GetMessage *msg;
   struct GNUNET_RESOLVER_RequestHandle *rh;
-  char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
+  char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
 
   check_config (cfg);
   rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + salen);
@@ -627,8 +635,7 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
                                           &numeric_reverse, rh);
       return rh;
     }
-  if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >
-      GNUNET_SERVER_MAX_MESSAGE_SIZE)
+  if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
     {
       GNUNET_break (0);
       GNUNET_free (rh);
@@ -669,35 +676,35 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
 
 
 /**
- * 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
+ * Get local fully qualified domain name
+ * @return fqdn
  */
-void
-GNUNET_RESOLVER_local_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
-                                    const struct GNUNET_CONFIGURATION_Handle *cfg,
-                                    GNUNET_RESOLVER_HostnameCallback callback,
-                                    void *cls)
+char *
+GNUNET_RESOLVER_local_fqdn_get ( void )
 {
-
+  struct hostent *host;
   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;
+      return NULL;
     }
 #if DEBUG_RESOLVER
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              _("Resolving our hostname `%s'\n"), hostname);
+              _("Resolving our FQDN `%s'\n"), hostname);
 #endif
-  callback (cls, hostname);
+  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);
 }
 
 /**