- added check against statistics
[oweals/gnunet.git] / src / nat / nat.c
index 802b241e4b97f02f8a07957834eefee7baefb671..53301ebb128684e4262b67ff32c885c9e5467679 100644 (file)
@@ -629,12 +629,16 @@ process_hostname_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen)
  * @param name name of the interface
  * @param isDefault do we think this may be our default interface
  * @param addr address of the interface
+ * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
+ * @param netmask the network mask (can be NULL for unknown or unassigned))
  * @param addrlen number of bytes in addr
  * @return GNUNET_OK to continue iterating
  */
 static int
 process_interfaces (void *cls, const char *name, int isDefault,
-                    const struct sockaddr *addr, socklen_t addrlen)
+                    const struct sockaddr *addr,
+                    const struct sockaddr *broadcast_addr,
+                    const struct sockaddr *netmask, socklen_t addrlen)
 {
   struct GNUNET_NAT_Handle *h = cls;
   const struct sockaddr_in *s4;
@@ -649,7 +653,7 @@ process_interfaces (void *cls, const char *name, int isDefault,
     ip = &s4->sin_addr;
 
     /* Check if address is in 127.0.0.0/8 */
-    uint32_t address = ntohl ((in_addr_t) (s4->sin_addr.s_addr));
+    uint32_t address = ntohl ((uint32_t) (s4->sin_addr.s_addr));
     uint32_t value = (address & 0xFF000000) ^ 0x7F000000;
 
     if ((h->return_localaddress == GNUNET_NO) && (value == 0))
@@ -791,7 +795,7 @@ nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 #if HAVE_SOCKADDR_IN_SIN_LEN
   sin_addr.sin_len = sizeof (sin_addr);
 #endif
-  if ((NULL == port_start) || (1 != sscanf (port_start, "%d", &port)) ||
+  if ((NULL == port_start) || (1 != SSCANF (port_start, "%d", &port)) ||
       (-1 == inet_pton (AF_INET, mybuf, &sin_addr.sin_addr)))
   {
     /* should we restart gnunet-helper-nat-server? */
@@ -831,7 +835,7 @@ start_gnunet_nat_server (struct GNUNET_NAT_Handle *h)
       (h->internal_address != NULL) &&
       (NULL !=
        (h->server_stdout =
-        GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES))))
+        GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES))))
   {
 #if DEBUG_NAT
     LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting `%s' at `%s'\n",
@@ -839,7 +843,7 @@ start_gnunet_nat_server (struct GNUNET_NAT_Handle *h)
 #endif
     /* Start the server process */
     h->server_proc =
-        GNUNET_OS_start_process (NULL, h->server_stdout,
+        GNUNET_OS_start_process (GNUNET_NO, NULL, h->server_stdout,
                                  "gnunet-helper-nat-server",
                                  "gnunet-helper-nat-server",
                                  h->internal_address, NULL);
@@ -1132,9 +1136,9 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp,
   h->nat_punched =
       GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "PUNCHED_NAT");
   h->enable_nat_client =
-      GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "ENABLE_NAT_CLIENT");
+      GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "ENABLE_ICMP_CLIENT");
   h->enable_nat_server =
-      GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "ENABLE_NAT_SERVER");
+      GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "ENABLE_ICMP_SERVER");
   h->enable_upnp =
       GNUNET_CONFIGURATION_get_value_yesno (cfg, "nat", "ENABLE_UPNP");
   h->use_localaddresses =
@@ -1304,32 +1308,34 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h)
  * gnunet-helper-nat-client to send dummy ICMP responses to cause
  * that peer to connect to us (connection reversal).
  *
- * @param h NAT handle for us (largely used for configuration)
- * @param sa the address of the peer (IPv4-only)
+ * @return GNUNET_SYSERR on error, GNUNET_NO if nat client is disabled,
+ *         GNUNET_OK otherwise
  */
-void
+int
 GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h,
                        const struct sockaddr_in *sa)
+
+
 {
   char inet4[INET_ADDRSTRLEN];
   char port_as_string[6];
   struct GNUNET_OS_Process *proc;
 
   if (GNUNET_YES != h->enable_nat_client)
-    return;                     /* not permitted / possible */
+    return GNUNET_NO;                     /* not permitted / possible */
 
   if (h->internal_address == NULL)
   {
     LOG (GNUNET_ERROR_TYPE_WARNING, "nat",
          _
          ("Internal IP address not known, cannot use ICMP NAT traversal method\n"));
-    return;
+    return GNUNET_SYSERR;
   }
   GNUNET_assert (sa->sin_family == AF_INET);
   if (NULL == inet_ntop (AF_INET, &sa->sin_addr, inet4, INET_ADDRSTRLEN))
   {
     GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "nat", "inet_ntop");
-    return;
+    return GNUNET_SYSERR;
   }
   GNUNET_snprintf (port_as_string, sizeof (port_as_string), "%d", h->adv_port);
 #if DEBUG_NAT
@@ -1338,15 +1344,17 @@ GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h,
        inet4, (unsigned int) h->adv_port);
 #endif
   proc =
-      GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-nat-client",
+      GNUNET_OS_start_process (GNUNET_NO,
+                              NULL, NULL, "gnunet-helper-nat-client",
                                "gnunet-helper-nat-client", h->internal_address,
                                inet4, port_as_string, NULL);
   if (NULL == proc)
-    return;
+    return GNUNET_SYSERR;
   /* we know that the gnunet-helper-nat-client will terminate virtually
    * instantly */
   GNUNET_OS_process_wait (proc);
   GNUNET_OS_process_close (proc);
+  return GNUNET_OK;
 }