2 This file is part of GNUnet.
3 Copyright (C) 2015 Christian Grothoff (and other contributing authors)
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)
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";
93 printf("NAT status: %s \n", nat_type );
94 printf("SUGGESTED CHANGES: \n" );
96 GNUNET_CONFIGURATION_iterate_section_values (diff,
110 * Main function that will be run.
113 * @param args remaining command-line arguments
114 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
115 * @param c configuration
118 run (void *cls, char *const *args, const char *cfgfile,
119 const struct GNUNET_CONFIGURATION_Handle *c)
123 GNUNET_NAT_autoconfig_start(c,auto_config_cb, NULL);
129 * Main function of gnunet-nat
131 * @param argc number of command-line arguments
132 * @param argv command line
133 * @return 0 on success, -1 on error
136 main (int argc, char *const argv[])
138 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
139 GNUNET_GETOPT_OPTION_END
143 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
146 /* Lets start resolver */
148 struct GNUNET_OS_Process *proc;
150 fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
151 proc = GNUNET_OS_start_process (GNUNET_YES,
152 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
155 "gnunet-service-resolver");
156 GNUNET_assert (NULL != proc);
159 GNUNET_PROGRAM_run (argc, argv, "gnunet-nat [options]",
160 _("GNUnet NAT traversal autoconfigure daemon"), options,
166 /* Now kill the resolver */
167 if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
169 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
171 GNUNET_OS_process_wait (proc);
172 GNUNET_OS_process_destroy (proc);
176 GNUNET_free ((void*) argv);
181 /* end of gnunet-nat-server.c */