odyssey: do not resolve ip addresses
#include <ctype.h>
#include <inttypes.h>
#include <assert.h>
+#include <arpa/inet.h>
#include <machinarium.h>
#include <kiwi.h>
@@ -263,12 +264,37 @@ od_backend_connect_to(od_server_t *server,
time_connect_start = machine_time();
struct sockaddr_un saddr_un;
+ struct sockaddr_in saddr_v4;
+ struct sockaddr_in6 saddr_v6;
struct sockaddr *saddr;
struct addrinfo *ai = NULL;
- if (server_config->host) {
+
/* resolve server address */
+ if (server_config->host)
+ {
+ /* assume IPv6 or IPv4 is specified */
+ int rc_resolve = -1;
+ if (strchr(server_config->host, ':')) {
+ /* v6 */
+ memset(&saddr_v6, 0, sizeof(saddr_v6));
+ saddr_v6.sin6_family = AF_INET6;
+ saddr_v6.sin6_port = htons(server_config->port);
+ rc_resolve = inet_pton(AF_INET6, server_config->host, &saddr_v6.sin6_addr);
+ saddr = (struct sockaddr*)&saddr_v6;
+ } else {
+ /* v4 or hostname */
+ memset(&saddr_v4, 0, sizeof(saddr_v4));
+ saddr_v4.sin_family = AF_INET;
+ saddr_v4.sin_port = htons(server_config->port);
+ rc_resolve = inet_pton(AF_INET, server_config->host, &saddr_v4.sin_addr);
+ saddr = (struct sockaddr*)&saddr_v4;
+ }
+
+ /* schedule getaddrinfo() execution */
+ if (rc_resolve != 1) {
char port[16];
od_snprintf(port, sizeof(port), "%d", server_config->port);
+
rc = machine_getaddrinfo(server_config->host, port, NULL, &ai, 0);
if (rc != 0) {
od_error(&instance->logger, context, NULL, server,
@@ -279,6 +305,7 @@ od_backend_connect_to(od_server_t *server,
}
assert(ai != NULL);
saddr = ai->ai_addr;
+ }
} else {
/* set unix socket path */
memset(&saddr_un, 0, sizeof(saddr_un));
