[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r27108 - gnunet/src/testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r27108 - gnunet/src/testbed |
Date: |
Mon, 13 May 2013 22:22:01 +0200 |
Author: harsha
Date: 2013-05-13 22:22:01 +0200 (Mon, 13 May 2013)
New Revision: 27108
Modified:
gnunet/src/testbed/gnunet-helper-testbed.c
Log:
- resolve hostname in helper to IP address
Modified: gnunet/src/testbed/gnunet-helper-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-helper-testbed.c 2013-05-13 17:33:31 UTC (rev
27107)
+++ gnunet/src/testbed/gnunet-helper-testbed.c 2013-05-13 20:22:01 UTC (rev
27108)
@@ -58,7 +58,13 @@
#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 @@
/**
+ * 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 @@
char *binary;
char *trusted_ip;
char *hostname;
+ const char *hostip;
char *config;
char *xconfig;
size_t config_size;
@@ -400,10 +449,17 @@
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));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r27108 - gnunet/src/testbed,
gnunet <=