#include "gnunet_protocols.h"
#include "nat.h"
-#define DEBUG_NAT GNUNET_NO
/**
* Our server.
struct GNUNET_NAT_Handle *h;
struct sockaddr_in sa;
-#if DEBUG_NAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asking for connection reversal with %x and code %u\n",
(unsigned int) dst_ipv4, (unsigned int) dport);
-#endif
h = GNUNET_NAT_register (cfg, is_tcp, dport, 0, NULL, NULL, NULL, NULL, NULL);
memset (&sa, 0, sizeof (sa));
sa.sin_family = AF_INET;
*/
struct GNUNET_NETWORK_Handle *s;
- /**
+ /**
* Data to transmit.
*/
uint16_t data;
* Task called by the scheduler once we can do the TCP send
* (or once we failed to connect...).
*
- * @param ctx the 'struct TcpContext'
+ * @param cls the 'struct TcpContext'
* @param tc scheduler context
*/
static void
if (-1 ==
GNUNET_NETWORK_socket_send (ctx->s, &ctx->data, sizeof (ctx->data)))
{
-#if DEBUG_NAT
GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
-#endif
}
GNUNET_NETWORK_socket_shutdown (ctx->s, SHUT_RDWR);
}
/**
* Try to send 'data' to the
* IP 'dst_ipv4' at port 'dport' via TCP.
- *
- * @param dst_ivp4 target IP
+ *
+ * @param dst_ipv4 target IP
* @param dport target port
* @param data data to send
*/
#endif
sa.sin_addr.s_addr = dst_ipv4;
sa.sin_port = htons (dport);
-#if DEBUG_NAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TCP message to `%s'\n",
GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa)));
-#endif
if ((GNUNET_OK !=
GNUNET_NETWORK_socket_connect (s, (const struct sockaddr *) &sa,
sizeof (sa))) && (errno != EINPROGRESS))
GNUNET_NETWORK_socket_close (s);
return;
}
- ctx = GNUNET_malloc (sizeof (struct TcpContext));
+ ctx = GNUNET_new (struct TcpContext);
ctx->s = s;
ctx->data = data;
GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_SECONDS, s, &tcp_send, ctx);
/**
* Try to send 'data' to the
* IP 'dst_ipv4' at port 'dport' via UDP.
- *
- * @param dst_ivp4 target IP
+ *
+ * @param dst_ipv4 target IP
* @param dport target port
* @param data data to send
*/
#endif
sa.sin_addr.s_addr = dst_ipv4;
sa.sin_port = htons (dport);
-#if DEBUG_NAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending UDP packet to `%s'\n",
GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa)));
-#endif
if (-1 ==
GNUNET_NETWORK_socket_sendto (s, &data, sizeof (data),
(const struct sockaddr *) &sa, sizeof (sa)))
/**
* We've received a request to probe a NAT
* traversal. Do it.
- *
+ *
* @param cls unused
* @param client handle to client (we always close)
* @param msg message with details about what to test
const struct GNUNET_NAT_TestMessage *tm;
uint16_t dport;
-#if DEBUG_NAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received test request\n");
-#endif
tm = (const struct GNUNET_NAT_TestMessage *) msg;
dport = ntohs (tm->dport);
if (0 == dport)
/**
* Task run during shutdown.
*
- * @param ctx unused
+ * @param cls unused
* @param tc scheduler context
*/
static void
if ((args[0] == NULL) || (1 != SSCANF (args[0], "%u", &port)) || (0 == port)
|| (65536 <= port))
{
- fprintf (stderr,
+ FPRINTF (stderr,
_
("Please pass valid port number as the first argument! (got `%s')\n"),
args[0]);
GNUNET_GETOPT_OPTION_END
};
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 2;
+
if (GNUNET_OK !=
GNUNET_PROGRAM_run (argc, argv, "gnunet-nat-server [options] PORT",
_("GNUnet NAT traversal test helper daemon"), options,
&run, NULL))
+ {
+ GNUNET_free ((void*) argv);
return 1;
+ }
+ GNUNET_free ((void*) argv);
return 0;
}