checkpoint save
[oweals/gnunet.git] / src / nat / nat_mini.c
index ccdc832658d406228eb8245f8ea2cca56c2f0b3a..5dffa8120baba31b38029769a2d0d0db52320bed 100644 (file)
@@ -28,6 +28,7 @@
 #include "gnunet_nat_lib.h"
 #include "nat.h"
 
+#define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
 
 /**
  * How long do we give upnpc to create a mapping?
@@ -163,17 +164,19 @@ GNUNET_NAT_mini_get_external_ipv4 (struct GNUNET_TIME_Relative timeout,
 {
   struct GNUNET_NAT_ExternalHandle *eh;
 
+  if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary ("external-ip"))
+    return NULL;
   eh = GNUNET_malloc (sizeof (struct GNUNET_NAT_ExternalHandle));
   eh->cb = cb;
   eh->cb_cls = cb_cls;
-  eh->opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
+  eh->opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
   if (NULL == eh->opipe)
   {
     GNUNET_free (eh);
     return NULL;
   }
   eh->eip =
-      GNUNET_OS_start_process (NULL, eh->opipe, "external-ip", "external-ip",
+    GNUNET_OS_start_process (GNUNET_NO, 0, NULL, eh->opipe, "external-ip", "external-ip",
                                NULL);
   if (NULL == eh->eip)
   {
@@ -199,7 +202,7 @@ void
 GNUNET_NAT_mini_get_external_ipv4_cancel (struct GNUNET_NAT_ExternalHandle *eh)
 {
   (void) GNUNET_OS_process_kill (eh->eip, SIGKILL);
-  GNUNET_OS_process_close (eh->eip);
+  GNUNET_OS_process_destroy (eh->eip);
   GNUNET_DISK_pipe_close (eh->opipe);
   if (GNUNET_SCHEDULER_NO_TASK != eh->task)
     GNUNET_SCHEDULER_cancel (eh->task);
@@ -375,7 +378,7 @@ process_refresh_output (void *cls, const char *line)
   if (NULL == strstr (s, pstr))
     return;                     /* skip */
   if (1 !=
-      sscanf (line,
+      SSCANF (line,
               (mini->is_tcp) ? "%*u TCP  %u->%*s:%*u %*s" :
               "%*u UDP  %u->%*s:%*u %*s", &nport))
     return;                     /* skip */
@@ -443,7 +446,7 @@ process_map_output (void *cls, const char *line)
    */
   if ((NULL == (ipaddr = strstr (line, " "))) ||
       (NULL == (pstr = strstr (ipaddr, ":"))) ||
-      (1 != sscanf (pstr + 1, "%u", &port)))
+      (1 != SSCANF (pstr + 1, "%u", &port)))
   {
     return;                     /* skip line */
   }
@@ -521,9 +524,7 @@ process_unmap_output (void *cls, const char *line)
 
   if (NULL == line)
   {
-#if DEBUG_NAT
-    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", "UPnP unmap done\n");
-#endif
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "UPnP unmap done\n");
     GNUNET_OS_command_stop (mini->unmap_cmd);
     mini->unmap_cmd = NULL;
     GNUNET_free (mini);
@@ -574,11 +575,8 @@ GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini)
    * often are the same, but it might... */
   GNUNET_snprintf (pstr, sizeof (pstr), "%u",
                    (unsigned int) ntohs (mini->current_addr.sin_port));
-#if DEBUG_NAT
-  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
-                   "Unmapping port %u with UPnP\n",
-                   ntohs (mini->current_addr.sin_port));
-#endif
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Unmapping port %u with UPnP\n",
+       ntohs (mini->current_addr.sin_port));
   mini->unmap_cmd =
       GNUNET_OS_command_run (&process_unmap_output, mini, UNMAP_TIMEOUT,
                              "upnpc", "upnpc", "-d", pstr,