better
[oweals/gnunet.git] / src / util / service.c
index efcfa50c98ce186a2755372be702034f5f581581..36a1f05b104443fff75a7e4a7b75ff5ad9ee40ec 100644 (file)
@@ -229,7 +229,7 @@ parse_ipv4_specification (const char *routeList)
  * notation.  The netmask must be given in CIDR notation (/16) or
  * can be omitted to specify a single host.
  * <p>
- * @param routeList a string specifying the forbidden networks
+ * @param routeListX a string specifying the forbidden networks
  * @return the converted list, NULL if the synatx is flawed
  */
 static struct IPv6NetworkSet *
@@ -350,7 +350,7 @@ parse_ipv6_specification (const char *routeListX)
  * Check if the given IP address is in the list of IP addresses.
  *
  * @param list a list of networks
- * @param ip the IP to check (in network byte order)
+ * @param add the IP to check (in network byte order)
  * @return GNUNET_NO if the IP is not in the list, GNUNET_YES if it it is
  */
 static int
@@ -763,6 +763,7 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
   struct addrinfo *pos;
   int ret;
   int tolerant;
+  struct GNUNET_NETWORK_Handle *desc;
 
   if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
                                        sctx->serviceName, "TIMEOUT"))
@@ -813,8 +814,6 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
 
   if (!disablev6)
     {
-      struct GNUNET_NETWORK_Handle *desc;
-
       /* probe IPv6 support */
       desc = GNUNET_NETWORK_socket_socket (PF_INET6, SOCK_STREAM, 0);
       if (NULL == desc)
@@ -825,18 +824,16 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
               GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
               return GNUNET_SYSERR;
             }
-          desc = GNUNET_NETWORK_socket_socket (PF_INET, SOCK_STREAM, 0);
-          if (NULL == desc)
-            {
-              GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                          _
-                          ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
-                          sctx->serviceName, STRERROR (errno));
-              disablev6 = GNUNET_YES;
-            }
+         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                     _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
+                     sctx->serviceName,
+                     STRERROR (errno));
+         disablev6 = GNUNET_YES;
         }
-      if (NULL != desc)
-        GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
+      else
+       {
+         GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
+       }
     }
 
 
@@ -942,8 +939,11 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
       if (disablev6)
         {
           /* V4-only */
-          sctx->addrlen = sizeof (struct sockaddr_in6);
+          sctx->addrlen = sizeof (struct sockaddr_in);
           sctx->addr = GNUNET_malloc (sctx->addrlen);
+#if HAVE_SOCKADDR_IN_SIN_LEN
+          ((struct sockaddr_in *) sctx->addr)->sin_len = sctx->addrlen;
+#endif
           ((struct sockaddr_in *) sctx->addr)->sin_family = AF_INET;
           ((struct sockaddr_in *) sctx->addr)->sin_port = htons (port);
           GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -956,6 +956,9 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
           /* dual stack */
           sctx->addrlen = sizeof (struct sockaddr_in6);
           sctx->addr = GNUNET_malloc (sctx->addrlen);
+#if HAVE_SOCKADDR_IN_SIN_LEN
+          ((struct sockaddr_in6 *) sctx->addr)->sin6_len = sctx->addrlen;
+#endif
           ((struct sockaddr_in6 *) sctx->addr)->sin6_family = AF_INET6;
           ((struct sockaddr_in6 *) sctx->addr)->sin6_port = htons (port);
         }
@@ -1082,6 +1085,11 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                                        sctx->timeout, sctx->require_found);
   if (sctx->server == NULL)
     {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                 _("Failed to start `%s' at `%s'\n"),
+                 sctx->serviceName, 
+                 GNUNET_a2s (sctx->addr,
+                             sctx->addrlen));
       sctx->ret = GNUNET_SYSERR;
       return;
     }
@@ -1098,7 +1106,11 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       sctx->ready_confirm_fd = -1;
       write_pid_file (sctx, getpid ());
     }
-
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+             _("Service `%s' runs at %s\n"),
+             sctx->serviceName,
+             GNUNET_a2s (sctx->addr,
+                         sctx->addrlen));
   sctx->task (sctx->task_cls, tc->sched, sctx->server, sctx->cfg);
 }
 
@@ -1109,11 +1121,11 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 static int
 detach_terminal (struct GNUNET_SERVICE_Context *sctx)
 {
+#ifndef MINGW 
   pid_t pid;
   int nullfd;
   int filedes[2];
 
-#ifndef MINGW
   if (0 != PIPE (filedes))
     {
       GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe");
@@ -1422,7 +1434,7 @@ GNUNET_SERVICE_get_server (struct GNUNET_SERVICE_Context *ctx)
 /**
  * Stop a service that was started with "GNUNET_SERVICE_start".
  *
- * @param ctx the service context returned from the start function
+ * @param sctx the service context returned from the start function
  */
 void
 GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx)