GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
+ by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
#include "gnunet_nat_lib.h"
/* Time to wait before stopping NAT, in seconds */
-#define TIMEOUT 30
+#define TIMEOUT 60
struct addr_cls
{
- const struct sockaddr *addr;
+ struct sockaddr *addr;
socklen_t addrlen;
};
-//typedef addr_cls addr_cls;
static void
addr_callback (void *cls, int add_remove,
static int
process_if (void *cls,
const char *name,
- int isDefault,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ int isDefault, const struct sockaddr *addr, socklen_t addrlen)
{
struct addr_cls *data = cls;
- if (addr)
+ if (addr && addrlen > 0)
{
- data->addr = addr;
+ if (data->addr)
+ GNUNET_free (data->addr);
+ data->addr = memcpy (GNUNET_malloc (addrlen), addr, addrlen);
data->addrlen = addrlen;
+ if (isDefault)
+ return GNUNET_SYSERR;
}
-
- if (isDefault && addr)
- return GNUNET_SYSERR;
- else
- return GNUNET_OK;
+ return GNUNET_OK;
}
static void
run (void *cls,
- struct GNUNET_SCHEDULER_Handle *sched,
char *const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_OS_network_interfaces_list (process_if, &data);
if (!data.addr)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not find a valid interface address!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not find a valid interface address!\n");
exit (GNUNET_SYSERR);
}
else
((struct sockaddr_in6 *) addr)->sin6_port = htons (2086);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting NAT redirection from address %s...\n", GNUNET_a2s (addr, data.addrlen));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Requesting NAT redirection from address %s...\n",
+ GNUNET_a2s (addr, data.addrlen));
- nat = GNUNET_NAT_register (sched, addr, data.addrlen, addr_callback, NULL);
+ nat = GNUNET_NAT_register (addr, data.addrlen, addr_callback, NULL);
GNUNET_free (addr);
- GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, TIMEOUT),
- stop, nat);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, TIMEOUT), stop,
+ nat);
}
int
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test-nat", "DEBUG", NULL);
+ char *const argv_prog[] = {
+ "test-nat",
+ "-c",
+ "test-nat.conf",
+ "-L",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL
+ };
+
+ GNUNET_log_setup ("test-nat",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Testing NAT library, timeout set to %d seconds\n", TIMEOUT);
- GNUNET_PROGRAM_run (argc, argv, "test-nat", "nohelp", options, &run, NULL);
+ GNUNET_PROGRAM_run (5, argv_prog, "test-nat", "nohelp", options, &run, NULL);
return 0;
}