X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fnat%2Fgnunet-nat-server.c;h=66b5ee3dab7b46f02c11004ecf556581d8d3cabf;hb=cffbdaf5b9053fcf4266423b2167227523b082c4;hp=3b4ec22939a6f5bf87e52a2ee2578e55a119a6c5;hpb=502af2167f7c218366666ca4944bd7cc54b5b19a;p=oweals%2Fgnunet.git diff --git a/src/nat/gnunet-nat-server.c b/src/nat/gnunet-nat-server.c index 3b4ec2293..66b5ee3da 100644 --- a/src/nat/gnunet-nat-server.c +++ b/src/nat/gnunet-nat-server.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2011 Christian Grothoff (and other contributing authors) + Copyright (C) 2011 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /** @@ -29,7 +29,6 @@ #include "gnunet_protocols.h" #include "nat.h" -#define DEBUG_NAT GNUNET_NO /** * Our server. @@ -56,12 +55,10 @@ try_anat (uint32_t dst_ipv4, uint16_t dport, int is_tcp) 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); + h = GNUNET_NAT_register (cfg, is_tcp, dport, 0, NULL, NULL, NULL, NULL, NULL, NULL); memset (&sa, 0, sizeof (sa)); sa.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN @@ -83,7 +80,7 @@ struct TcpContext */ struct GNUNET_NETWORK_Handle *s; - /** + /** * Data to transmit. */ uint16_t data; @@ -94,7 +91,7 @@ struct TcpContext * 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 @@ -108,9 +105,7 @@ tcp_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 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); } @@ -122,8 +117,8 @@ tcp_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /** * 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 */ @@ -147,21 +142,17 @@ try_send_tcp (uint32_t dst_ipv4, uint16_t dport, uint16_t data) #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_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, + GNUNET_NETWORK_socket_connect (s, (const struct sockaddr *) &sa, sizeof (sa))) && (errno != EINPROGRESS)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect"); 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); @@ -171,8 +162,8 @@ try_send_tcp (uint32_t dst_ipv4, uint16_t dport, uint16_t data) /** * 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 */ @@ -195,15 +186,11 @@ try_send_udp (uint32_t dst_ipv4, uint16_t dport, uint16_t data) #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_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))) + if (-1 == + GNUNET_NETWORK_socket_sendto (s, &data, sizeof (data), + (const struct sockaddr *) &sa, sizeof (sa))) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); GNUNET_NETWORK_socket_close (s); } @@ -212,22 +199,19 @@ try_send_udp (uint32_t dst_ipv4, uint16_t dport, uint16_t data) /** * 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 */ static void -test (void *cls, - struct GNUNET_SERVER_Client *client, +test (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *msg) { 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) @@ -243,7 +227,7 @@ test (void *cls, /** * Task run during shutdown. * - * @param ctx unused + * @param cls unused * @param tc scheduler context */ static void @@ -263,9 +247,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * @param c configuration */ static void -run (void *cls, - char *const *args, - const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { static const struct GNUNET_SERVER_MessageHandler handlers[] = { {&test, NULL, GNUNET_MESSAGE_TYPE_NAT_TEST, @@ -288,10 +271,10 @@ run (void *cls, }; cfg = c; - if ((args[0] == NULL) || - (1 != SSCANF (args[0], "%u", &port)) || (0 == port) || (65536 <= port)) + 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]); @@ -307,12 +290,12 @@ run (void *cls, in4.sin_len = sizeof (in4); in6.sin6_len = sizeof (in6); #endif - server = GNUNET_SERVER_create (NULL, NULL, - (struct sockaddr * const *) sa, - slen, GNUNET_TIME_UNIT_SECONDS, GNUNET_YES); + server = + GNUNET_SERVER_create (NULL, NULL, (struct sockaddr * const *) sa, slen, + GNUNET_TIME_UNIT_SECONDS, GNUNET_YES); GNUNET_SERVER_add_handlers (server, handlers); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, - &shutdown_task, NULL); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, + NULL); } @@ -330,12 +313,18 @@ main (int argc, char *const argv[]) 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_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; }