bugfix
[oweals/gnunet.git] / src / util / service.c
index cf970323582c51df996e3cf816d36152117c9509..0569a0fde698c079a56da25a1d75feb7071dcdce 100644 (file)
@@ -620,34 +620,26 @@ check_access (void *cls, const struct sockaddr *addr, socklen_t addrlen)
   const struct sockaddr_in *i4;
   const struct sockaddr_in6 *i6;
   int ret;
-  char buf[INET6_ADDRSTRLEN];
-  uint16_t port;
 
   switch (addr->sa_family)
     {
     case AF_INET:
       GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
       i4 = (const struct sockaddr_in *) addr;
-      port = ntohs (i4->sin_port);
       ret = ((sctx->v4_allowed == NULL) ||
              (check_ipv4_listed (sctx->v4_allowed,
                                  &i4->sin_addr)))
         && ((sctx->v4_denied == NULL) ||
             (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
-      if (ret != GNUNET_OK)
-        inet_ntop (AF_INET, &i4->sin_addr, buf, sizeof (buf));
       break;
     case AF_INET6:
       GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
       i6 = (const struct sockaddr_in6 *) addr;
-      port = ntohs (i6->sin6_port);
       ret = ((sctx->v6_allowed == NULL) ||
              (check_ipv6_listed (sctx->v6_allowed,
                                  &i6->sin6_addr)))
         && ((sctx->v6_denied == NULL) ||
             (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
-      if (ret != GNUNET_OK)
-        inet_ntop (AF_INET6, &i6->sin6_addr, buf, sizeof (buf));
       break;
     default:
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -657,8 +649,8 @@ check_access (void *cls, const struct sockaddr *addr, socklen_t addrlen)
   if (ret != GNUNET_OK)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  _("Access from `%s:%u' denied to service `%s'\n"),
-                  buf, port, sctx->serviceName);
+                  _("Access from `%s' denied to service `%s'\n"),
+                  GNUNET_a2s(addr, addrlen), sctx->serviceName);
     }
   return ret;
 }
@@ -762,7 +754,7 @@ static int
 setup_service (struct GNUNET_SERVICE_Context *sctx)
 {
   unsigned long long maxbuf;
-  unsigned long long idleout;
+  struct GNUNET_TIME_Relative idleout;
   char *hostname;
   unsigned long long port;
   int disablev6;
@@ -776,12 +768,12 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
                                        sctx->serviceName, "TIMEOUT"))
     {
       if (GNUNET_OK !=
-          GNUNET_CONFIGURATION_get_value_number (sctx->cfg,
-                                                 sctx->serviceName,
-                                                 "TIMEOUT", &idleout))
+          GNUNET_CONFIGURATION_get_value_time (sctx->cfg,
+                                              sctx->serviceName,
+                                              "TIMEOUT", &idleout))
         return GNUNET_SYSERR;
 
-      sctx->timeout.value = idleout;
+      sctx->timeout = idleout;
     }
   else
     sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -908,7 +900,8 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
       if (pos == NULL)
         {
           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                      _("Failed to find IPv4 address for `%s'.\n"), hostname);
+                      _("Failed to find %saddress for `%s'.\n"),
+                     disablev6 ? "IPv4 " : "", hostname);
           freeaddrinfo (res);
           GNUNET_free (hostname);
           return GNUNET_SYSERR;
@@ -932,6 +925,7 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
           GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
           sctx->addrlen = pos->ai_addrlen;
           sctx->addr = GNUNET_malloc (sctx->addrlen);
+          memcpy (sctx->addr, res->ai_addr, sctx->addrlen);
           GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                       _
                       ("Configured to bind to %s address; %s connections to this service will fail!\n"),
@@ -1162,7 +1156,7 @@ detach_terminal (struct GNUNET_SERVICE_Context *sctx)
   GNUNET_break (0 == CLOSE (0));
   GNUNET_break (0 == CLOSE (1));
   GNUNET_break (0 == CLOSE (filedes[0]));
-  nullfd = GNUNET_DISK_file_open ("/dev/null", O_RDWR | O_APPEND);
+  nullfd = OPEN ("/dev/null", O_RDWR | O_APPEND);
   if (nullfd < 0)
     return GNUNET_SYSERR;
   /* set stdin/stdout to /dev/null */