summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-05-13 20:22:01 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-05-13 20:22:01 +0000
commit38d2cfe4fc1f9253d2938052b817921e6c27aa5b (patch)
tree795f1279645f8e550e0c63a6c06511b75bcab3ab /src
parent2b80f3e6262506edabc7353a313f1830a8de60b5 (diff)
- resolve hostname in helper to IP address
Diffstat (limited to 'src')
-rw-r--r--src/testbed/gnunet-helper-testbed.c58
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 @@
#define LOG_DEBUG(...) \
LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+/**
+ * Log an error message at log-level 'level' that indicates a failure of the
+ * command 'cmd' with the message given by gai_strerror(rc).
+ */
+#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)
+
/**
* We need pipe control only on WINDOWS
@@ -313,6 +319,48 @@ child_death_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
/**
+ * Resolves a hostname using getaddrinfo
+ *
+ * @param host the hostname
+ * @return the string representing the IPv4 address of the given host; NULL upon error
+ */
+const char *
+simple_resolve (const char *host)
+{
+ struct addrinfo *res;
+ const struct sockaddr_in *in_addr;
+ char *hostip;
+ struct addrinfo hint;
+ unsigned int rc;
+
+ hint.ai_family = AF_INET; /* IPv4 */
+ hint.ai_socktype = 0;
+ hint.ai_protocol = 0;
+ hint.ai_addrlen = 0;
+ hint.ai_addr = NULL;
+ hint.ai_canonname = NULL;
+ hint.ai_next = NULL;
+ hint.ai_flags = AI_NUMERICSERV;
+ res = NULL;
+ LOG_DEBUG ("Resolving [%s]\n", host);
+ if (0 != (rc = getaddrinfo (host, "22", &hint, &res)))
+ {
+ LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc);
+ return NULL;
+ }
+ GNUNET_assert (NULL != res);
+ GNUNET_assert (NULL != res->ai_addr);
+ GNUNET_assert (sizeof (struct sockaddr_in) == res->ai_addrlen);
+ in_addr = (const struct sockaddr_in *) res->ai_addr;
+ hostip = inet_ntoa (in_addr->sin_addr);
+ GNUNET_assert (NULL != hostip);
+ freeaddrinfo (res);
+ LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip);
+ return hostip;
+}
+
+
+/**
* Functions with this signature are called whenever a
* complete message is received by the tokenizer.
*
@@ -335,6 +383,7 @@ tokenizer_cb (void *cls, void *client,
char *binary;
char *trusted_ip;
char *hostname;
+ const char *hostip;
char *config;
char *xconfig;
size_t config_size;
@@ -400,10 +449,17 @@ tokenizer_cb (void *cls, void *client,
hostname_size);
hostname[hostname_size] = '\0';
}
+ hostip = NULL;
+ if ( (NULL != hostname) && (NULL == (hostip = simple_resolve (hostname))) )
+ {
+ GNUNET_free (hostname);
+ hostname = NULL;
+ }
test_system =
- GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostname, NULL);
+ GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostip, NULL);
GNUNET_free_non_null (hostname);
hostname = NULL;
+ hostip = NULL;
GNUNET_assert (NULL != test_system);
GNUNET_assert (GNUNET_OK ==
GNUNET_TESTING_configuration_create (test_system, cfg));