aboutsummaryrefslogtreecommitdiff
path: root/src/nat/gnunet-nat-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nat/gnunet-nat-server.c')
-rw-r--r--src/nat/gnunet-nat-server.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/src/nat/gnunet-nat-server.c b/src/nat/gnunet-nat-server.c
index 3b4ec2293..988e9fbc9 100644
--- a/src/nat/gnunet-nat-server.c
+++ b/src/nat/gnunet-nat-server.c
@@ -148,13 +148,11 @@ try_send_tcp (uint32_t dst_ipv4, uint16_t dport, uint16_t data)
148 sa.sin_addr.s_addr = dst_ipv4; 148 sa.sin_addr.s_addr = dst_ipv4;
149 sa.sin_port = htons (dport); 149 sa.sin_port = htons (dport);
150#if DEBUG_NAT 150#if DEBUG_NAT
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TCP message to `%s'\n",
152 "Sending TCP message to `%s'\n",
153 GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa))); 152 GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa)));
154#endif 153#endif
155 if ((GNUNET_OK != 154 if ((GNUNET_OK !=
156 GNUNET_NETWORK_socket_connect (s, 155 GNUNET_NETWORK_socket_connect (s, (const struct sockaddr *) &sa,
157 (const struct sockaddr *) &sa,
158 sizeof (sa))) && (errno != EINPROGRESS)) 156 sizeof (sa))) && (errno != EINPROGRESS))
159 { 157 {
160 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect"); 158 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect");
@@ -196,14 +194,12 @@ try_send_udp (uint32_t dst_ipv4, uint16_t dport, uint16_t data)
196 sa.sin_addr.s_addr = dst_ipv4; 194 sa.sin_addr.s_addr = dst_ipv4;
197 sa.sin_port = htons (dport); 195 sa.sin_port = htons (dport);
198#if DEBUG_NAT 196#if DEBUG_NAT
199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending UDP packet to `%s'\n",
200 "Sending UDP packet to `%s'\n",
201 GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa))); 198 GNUNET_a2s ((struct sockaddr *) &sa, sizeof (sa)));
202#endif 199#endif
203 if (-1 == GNUNET_NETWORK_socket_sendto (s, 200 if (-1 ==
204 &data, sizeof (data), 201 GNUNET_NETWORK_socket_sendto (s, &data, sizeof (data),
205 (const struct sockaddr *) &sa, 202 (const struct sockaddr *) &sa, sizeof (sa)))
206 sizeof (sa)))
207 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); 203 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto");
208 GNUNET_NETWORK_socket_close (s); 204 GNUNET_NETWORK_socket_close (s);
209} 205}
@@ -218,8 +214,7 @@ try_send_udp (uint32_t dst_ipv4, uint16_t dport, uint16_t data)
218 * @param msg message with details about what to test 214 * @param msg message with details about what to test
219 */ 215 */
220static void 216static void
221test (void *cls, 217test (void *cls, struct GNUNET_SERVER_Client *client,
222 struct GNUNET_SERVER_Client *client,
223 const struct GNUNET_MessageHeader *msg) 218 const struct GNUNET_MessageHeader *msg)
224{ 219{
225 const struct GNUNET_NAT_TestMessage *tm; 220 const struct GNUNET_NAT_TestMessage *tm;
@@ -263,9 +258,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
263 * @param c configuration 258 * @param c configuration
264 */ 259 */
265static void 260static void
266run (void *cls, 261run (void *cls, char *const *args, const char *cfgfile,
267 char *const *args, 262 const struct GNUNET_CONFIGURATION_Handle *c)
268 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
269{ 263{
270 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 264 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
271 {&test, NULL, GNUNET_MESSAGE_TYPE_NAT_TEST, 265 {&test, NULL, GNUNET_MESSAGE_TYPE_NAT_TEST,
@@ -288,8 +282,8 @@ run (void *cls,
288 }; 282 };
289 283
290 cfg = c; 284 cfg = c;
291 if ((args[0] == NULL) || 285 if ((args[0] == NULL) || (1 != SSCANF (args[0], "%u", &port)) || (0 == port)
292 (1 != SSCANF (args[0], "%u", &port)) || (0 == port) || (65536 <= port)) 286 || (65536 <= port))
293 { 287 {
294 fprintf (stderr, 288 fprintf (stderr,
295 _ 289 _
@@ -307,12 +301,12 @@ run (void *cls,
307 in4.sin_len = sizeof (in4); 301 in4.sin_len = sizeof (in4);
308 in6.sin6_len = sizeof (in6); 302 in6.sin6_len = sizeof (in6);
309#endif 303#endif
310 server = GNUNET_SERVER_create (NULL, NULL, 304 server =
311 (struct sockaddr * const *) sa, 305 GNUNET_SERVER_create (NULL, NULL, (struct sockaddr * const *) sa, slen,
312 slen, GNUNET_TIME_UNIT_SECONDS, GNUNET_YES); 306 GNUNET_TIME_UNIT_SECONDS, GNUNET_YES);
313 GNUNET_SERVER_add_handlers (server, handlers); 307 GNUNET_SERVER_add_handlers (server, handlers);
314 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 308 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
315 &shutdown_task, NULL); 309 NULL);
316} 310}
317 311
318 312
@@ -331,10 +325,9 @@ main (int argc, char *const argv[])
331 }; 325 };
332 326
333 if (GNUNET_OK != 327 if (GNUNET_OK !=
334 GNUNET_PROGRAM_run (argc, argv, 328 GNUNET_PROGRAM_run (argc, argv, "gnunet-nat-server [options] PORT",
335 "gnunet-nat-server [options] PORT", 329 _("GNUnet NAT traversal test helper daemon"), options,
336 _("GNUnet NAT traversal test helper daemon"), 330 &run, NULL))
337 options, &run, NULL))
338 return 1; 331 return 1;
339 return 0; 332 return 0;
340} 333}