fixing 2012: network structure alignment now forced to be correct even on W32 using...
[oweals/gnunet.git] / src / nat / nat_mini.c
index 1f5a83d2d8c417d2b732e9ecbf4ed62b09b443a6..5a83d7a4fea22e7dd4ce3b013d9d7aee494175b0 100644 (file)
@@ -28,7 +28,7 @@
 #include "gnunet_nat_lib.h"
 #include "nat.h"
 
-#define DEBUG_NAT GNUNET_NO
+#define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
 
 /**
  * How long do we give upnpc to create a mapping?
@@ -164,6 +164,8 @@ 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;
@@ -361,12 +363,12 @@ process_refresh_output (void *cls, const char *line)
   }
   /*
    * we're looking for output of the form:
-   * 
+   *
    * "0 TCP  3000->192.168.2.150:3000  'libminiupnpc' ''"
    * "1 UDP  3001->192.168.2.150:3001  'libminiupnpc' ''"
-   * 
+   *
    * the pattern we look for is:
-   * 
+   *
    * "%s TCP  PORT->STRING:OURPORT *" or
    * "%s UDP  PORT->STRING:OURPORT *"
    */
@@ -439,7 +441,7 @@ process_map_output (void *cls, const char *line)
   }
   /*
    * The upnpc output we're after looks like this:
-   * 
+   *
    * "external 87.123.42.204:3000 TCP is redirected to internal 192.168.2.150:3000"
    */
   if ((NULL == (ipaddr = strstr (line, " "))) ||
@@ -475,7 +477,7 @@ process_map_output (void *cls, const char *line)
  * general-purpose 'GNUNET_NAT_register' code).  However, it can be
  * used if specifically UPnP-based NAT traversal is to be used or
  * tested.
- * 
+ *
  * @param port port to map
  * @param is_tcp GNUNET_YES to map TCP, GNUNET_NO for UDP
  * @param ac function to call with mapping result
@@ -523,7 +525,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");
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "UPnP unmap done\n");
 #endif
     GNUNET_OS_command_stop (mini->unmap_cmd);
     mini->unmap_cmd = NULL;
@@ -539,7 +541,7 @@ process_unmap_output (void *cls, const char *line)
  * this function will give 'upnpc' 1s to remove tha mapping,
  * so while this function is non-blocking, a task will be
  * left with the scheduler for up to 1s past this call.
- * 
+ *
  * @param mini the handle
  */
 void
@@ -576,9 +578,8 @@ GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini)
   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));
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Unmapping port %u with UPnP\n",
+       ntohs (mini->current_addr.sin_port));
 #endif
   mini->unmap_cmd =
       GNUNET_OS_command_run (&process_unmap_output, mini, UNMAP_TIMEOUT,