diff options
Diffstat (limited to 'src/testbed/gnunet-helper-testbed.c')
-rw-r--r-- | src/testbed/gnunet-helper-testbed.c | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c index be9154fdc..43766796e 100644 --- a/src/testbed/gnunet-helper-testbed.c +++ b/src/testbed/gnunet-helper-testbed.c | |||
@@ -58,6 +58,12 @@ | |||
58 | #define LOG_DEBUG(...) \ | 58 | #define LOG_DEBUG(...) \ |
59 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 59 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
60 | 60 | ||
61 | /** | ||
62 | * Log an error message at log-level 'level' that indicates a failure of the | ||
63 | * command 'cmd' with the message given by gai_strerror(rc). | ||
64 | */ | ||
65 | #define LOG_GAI(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gai_strerror(rc)); } while(0) | ||
66 | |||
61 | 67 | ||
62 | /** | 68 | /** |
63 | * We need pipe control only on WINDOWS | 69 | * We need pipe control only on WINDOWS |
@@ -313,6 +319,48 @@ child_death_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
313 | 319 | ||
314 | 320 | ||
315 | /** | 321 | /** |
322 | * Resolves a hostname using getaddrinfo | ||
323 | * | ||
324 | * @param host the hostname | ||
325 | * @return the string representing the IPv4 address of the given host; NULL upon error | ||
326 | */ | ||
327 | const char * | ||
328 | simple_resolve (const char *host) | ||
329 | { | ||
330 | struct addrinfo *res; | ||
331 | const struct sockaddr_in *in_addr; | ||
332 | char *hostip; | ||
333 | struct addrinfo hint; | ||
334 | unsigned int rc; | ||
335 | |||
336 | hint.ai_family = AF_INET; /* IPv4 */ | ||
337 | hint.ai_socktype = 0; | ||
338 | hint.ai_protocol = 0; | ||
339 | hint.ai_addrlen = 0; | ||
340 | hint.ai_addr = NULL; | ||
341 | hint.ai_canonname = NULL; | ||
342 | hint.ai_next = NULL; | ||
343 | hint.ai_flags = AI_NUMERICSERV; | ||
344 | res = NULL; | ||
345 | LOG_DEBUG ("Resolving [%s]\n", host); | ||
346 | if (0 != (rc = getaddrinfo (host, "22", &hint, &res))) | ||
347 | { | ||
348 | LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc); | ||
349 | return NULL; | ||
350 | } | ||
351 | GNUNET_assert (NULL != res); | ||
352 | GNUNET_assert (NULL != res->ai_addr); | ||
353 | GNUNET_assert (sizeof (struct sockaddr_in) == res->ai_addrlen); | ||
354 | in_addr = (const struct sockaddr_in *) res->ai_addr; | ||
355 | hostip = inet_ntoa (in_addr->sin_addr); | ||
356 | GNUNET_assert (NULL != hostip); | ||
357 | freeaddrinfo (res); | ||
358 | LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip); | ||
359 | return hostip; | ||
360 | } | ||
361 | |||
362 | |||
363 | /** | ||
316 | * Functions with this signature are called whenever a | 364 | * Functions with this signature are called whenever a |
317 | * complete message is received by the tokenizer. | 365 | * complete message is received by the tokenizer. |
318 | * | 366 | * |
@@ -335,6 +383,7 @@ tokenizer_cb (void *cls, void *client, | |||
335 | char *binary; | 383 | char *binary; |
336 | char *trusted_ip; | 384 | char *trusted_ip; |
337 | char *hostname; | 385 | char *hostname; |
386 | const char *hostip; | ||
338 | char *config; | 387 | char *config; |
339 | char *xconfig; | 388 | char *xconfig; |
340 | size_t config_size; | 389 | size_t config_size; |
@@ -400,10 +449,17 @@ tokenizer_cb (void *cls, void *client, | |||
400 | hostname_size); | 449 | hostname_size); |
401 | hostname[hostname_size] = '\0'; | 450 | hostname[hostname_size] = '\0'; |
402 | } | 451 | } |
452 | hostip = NULL; | ||
453 | if ( (NULL != hostname) && (NULL == (hostip = simple_resolve (hostname))) ) | ||
454 | { | ||
455 | GNUNET_free (hostname); | ||
456 | hostname = NULL; | ||
457 | } | ||
403 | test_system = | 458 | test_system = |
404 | GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostname, NULL); | 459 | GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostip, NULL); |
405 | GNUNET_free_non_null (hostname); | 460 | GNUNET_free_non_null (hostname); |
406 | hostname = NULL; | 461 | hostname = NULL; |
462 | hostip = NULL; | ||
407 | GNUNET_assert (NULL != test_system); | 463 | GNUNET_assert (NULL != test_system); |
408 | GNUNET_assert (GNUNET_OK == | 464 | GNUNET_assert (GNUNET_OK == |
409 | GNUNET_TESTING_configuration_create (test_system, cfg)); | 465 | GNUNET_TESTING_configuration_create (test_system, cfg)); |