fix build issues
[oweals/gnunet.git] / src / nat-auto / gnunet-nat-auto.c
index d411c6d75915d08337680e278daf1aa2394cf6b6..5eb0a4be3fe93d4c95db5e3a2cc1bb82fc0fc52c 100644 (file)
@@ -47,7 +47,7 @@ static int write_cfg;
 
 /**
  * Configuration filename.
- */ 
+ */
 static const char *cfg_file;
 
 /**
@@ -56,16 +56,9 @@ static const char *cfg_file;
 static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
- * Address we are bound to (in test), or should bind to
- * (if #do_stun is set).
- */
-static char *bind_addr;
-
-/**
- * External IP address and port to use for the test.
- * If not set, use #bind_addr.
+ * Adapter we are supposed to test.
  */
-static char *extern_addr;
+static char *section_name;
 
 /**
  * Should we run autoconfiguration?
@@ -122,7 +115,7 @@ auto_conf_iter (void *cls,
                 const char *value)
 {
   struct GNUNET_CONFIGURATION_Handle *new_cfg = cls;
-  
+
   PRINTF ("%s: %s\n",
          option,
          value);
@@ -181,6 +174,9 @@ auto_config_cb (void *cls,
              GNUNET_NAT_AUTO_status2string (result),
              nat_type);
 
+  if (NULL == diff)
+    return;
+
   /* Shortcut: if there are no changes suggested, bail out early. */
   if (GNUNET_NO ==
       GNUNET_CONFIGURATION_is_dirty (diff))
@@ -192,21 +188,17 @@ auto_config_cb (void *cls,
   /* Apply diff to original configuration and show changes
      to the user */
   new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL;
-  
-  if (NULL != diff)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-               _("Suggested configuration changes:\n"));
-    GNUNET_CONFIGURATION_iterate_section_values (diff,
-                                                "nat",
-                                                &auto_conf_iter,
-                                                new_cfg);
-  }
+
+  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+              _("Suggested configuration changes:\n"));
+  GNUNET_CONFIGURATION_iterate_section_values (diff,
+                                               "nat",
+                                               &auto_conf_iter,
+                                               new_cfg);
 
   /* If desired, write configuration to file; we write only the
      changes to the defaults to keep things compact. */
-  if ( (write_cfg) &&
-       (NULL != diff) )
+  if (write_cfg)
   {
     struct GNUNET_CONFIGURATION_Handle *def_cfg;
 
@@ -296,20 +288,17 @@ run (void *cls,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
-  struct sockaddr_in bind_sa;
-  struct sockaddr_in extern_sa;
-
   cfg_file = cfgfile;
   cfg = c;
-  
+
   GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
                                 NULL);
 
   if (do_auto)
   {
     ah = GNUNET_NAT_AUTO_autoconfig_start (c,
-                                     &auto_config_cb,
-                                     NULL);
+                                           &auto_config_cb,
+                                           NULL);
   }
 
   if (use_tcp && use_udp)
@@ -327,45 +316,11 @@ run (void *cls,
   if (use_udp)
     proto = IPPROTO_UDP;
 
-  if (NULL != bind_addr)
-  {
-    if (GNUNET_OK !=
-       GNUNET_STRINGS_to_address_ipv4 (bind_addr,
-                                       strlen (bind_addr),
-                                       &bind_sa))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-                 "Invalid socket address `%s'\n",
-                 bind_addr);
-      global_ret = 1;
-      return;
-    }
-  }
-  if (NULL != extern_addr)
-  {
-    if (GNUNET_OK !=
-       GNUNET_STRINGS_to_address_ipv4 (extern_addr,
-                                       strlen (extern_addr),
-                                       &extern_sa))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
-                 "Invalid socket address `%s'\n",
-                 extern_addr);
-      global_ret = 1;
-      return;
-    }
-  }
-
-  if (NULL != bind_addr)
+  if (NULL != section_name)
   {
-    if (NULL == extern_addr)
-      extern_sa = bind_sa;
     nt = GNUNET_NAT_AUTO_test_start (c,
                                     proto,
-                                    bind_sa.sin_addr,
-                                    ntohs (bind_sa.sin_port),
-                                    extern_sa.sin_addr,
-                                    ntohs (extern_sa.sin_port),
+                                    section_name,
                                     &test_report_cb,
                                     NULL);
   }
@@ -374,7 +329,7 @@ run (void *cls,
 
 
 /**
- * Main function of gnunet-nat
+ * Main function of gnunet-nat-auto
  *
  * @param argc number of command-line arguments
  * @param argv command line
@@ -388,12 +343,9 @@ main (int argc,
     {'a', "auto", NULL,
      gettext_noop ("run autoconfiguration"),
      GNUNET_NO, &GNUNET_GETOPT_set_one, &do_auto },
-    {'b', "bind", "ADDRESS",
-     gettext_noop ("which IP and port are we bound to"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &bind_addr },
-    {'e', "external", "ADDRESS",
-     gettext_noop ("which external IP and port should be used to test"),
-     GNUNET_YES, &GNUNET_GETOPT_set_string, &extern_addr },
+    {'S', "section", "NAME",
+     gettext_noop ("section name providing the configuration for the adapter"),
+     GNUNET_YES, &GNUNET_GETOPT_set_string, &section_name },
     {'t', "tcp", NULL,
      gettext_noop ("use TCP"),
      GNUNET_NO, &GNUNET_GETOPT_set_one, &use_tcp },