2 This file is part of GNUnet.
3 Copyright (C) 2015 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file src/nat/gnunet-nat.c
23 * @brief Daemon to auto configure nat
24 * @author Christian Grothoff
25 * @author Bruno Cabral
28 #include "gnunet_util_lib.h"
29 #include "gnunet_nat_lib.h"
30 #include "gnunet_protocols.h"
34 struct GNUNET_CONFIGURATION_Handle *cfg;
39 * Function to iterate over sugested changes options
42 * @param section name of the section
43 * @param option name of the option
44 * @param value value of the option
47 auto_conf_iter (void *cls,
53 PRINTF ( "%s: %s \n", option, value);
59 * Function called with the result from the autoconfiguration.
62 * @param diff minimal suggested changes to the original configuration
63 * to make it work (as best as we can)
64 * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
65 * @param type what the situation of the NAT
69 auto_config_cb(void *cls,
70 const struct GNUNET_CONFIGURATION_Handle *diff,
71 enum GNUNET_NAT_StatusCode result, enum GNUNET_NAT_Type type)
74 char unknown_type[64];
78 case GNUNET_NAT_TYPE_NO_NAT:
81 case GNUNET_NAT_TYPE_UNREACHABLE_NAT:
82 nat_type = "NAT but we can traverse";
84 case GNUNET_NAT_TYPE_STUN_PUNCHED_NAT:
85 nat_type = "NAT but STUN is able to identify the correct information";
87 case GNUNET_NAT_TYPE_UPNP_NAT:
88 nat_type = "NAT but UPNP opened the ports";
91 SPRINTF (unknown_type, "NAT unknown, type %u", type);
92 nat_type = unknown_type;
95 PRINTF ("NAT status: %s \n", nat_type );
96 PRINTF ("SUGGESTED CHANGES: \n" );
98 GNUNET_CONFIGURATION_iterate_section_values (diff,
112 * Main function that will be run.
115 * @param args remaining command-line arguments
116 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
117 * @param c configuration
120 run (void *cls, char *const *args, const char *cfgfile,
121 const struct GNUNET_CONFIGURATION_Handle *c)
123 GNUNET_NAT_autoconfig_start (c, auto_config_cb, NULL);
128 * Main function of gnunet-nat
130 * @param argc number of command-line arguments
131 * @param argv command line
132 * @return 0 on success, -1 on error
135 main (int argc, char *const argv[])
137 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
138 GNUNET_GETOPT_OPTION_END
142 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
145 /* Lets start resolver */
147 struct GNUNET_OS_Process *proc;
149 fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
150 proc = GNUNET_OS_start_process (GNUNET_YES,
151 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
154 "gnunet-service-resolver");
155 GNUNET_assert (NULL != proc);
158 GNUNET_PROGRAM_run (argc, argv, "gnunet-nat [options]",
159 _("GNUnet NAT traversal autoconfigure daemon"), options,
165 /* Now kill the resolver */
166 if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
168 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
170 GNUNET_OS_process_wait (proc);
171 GNUNET_OS_process_destroy (proc);
175 GNUNET_free ((void*) argv);
180 /* end of gnunet-nat-server.c */