From 38d9ea07370dcd75e68e9c70898789cf6016da51 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Thu, 7 Oct 2021 13:01:05 +0200 Subject: [PATCH] wip: resolve --- connectd/connectd.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/connectd/connectd.c b/connectd/connectd.c index 43bb12248f63..ab5c8aa0376c 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -788,6 +788,8 @@ static void try_connect_one_addr(struct connecting *connect) bool use_proxy = connect->daemon->always_use_proxy; const struct wireaddr_internal *addr = &connect->addrs[connect->addrnum]; struct io_conn *conn; + struct addrinfo hints, *ais, *aii; + int gai_err; /* In case we fail without a connection, make destroy_io_conn happy */ connect->conn = NULL; @@ -836,7 +838,37 @@ static void try_connect_one_addr(struct connecting *connect) af = AF_INET6; break; case ADDR_TYPE_DNS: - // TODO: resolve with getaddrinfo and set af + /* Resolve with getaddrinfo */ + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + hints.ai_family = AF_UNSPEC; + hints.ai_protocol = 0; + hints.ai_flags = AI_ADDRCONFIG; + gai_err = getaddrinfo((char *)addr->u.wireaddr.addr, + tal_fmt(tmpctx, "%d", + addr->u.wireaddr.port), + &hints, &ais); + if (gai_err != 0) + status_failed(STATUS_FAIL_INTERNAL_ERROR, + gai_strerror(gai_err)); + for (aii = ais; aii; aii = aii->ai_next) { + // TODO: if we get IPv4 and IPv6 we should try both + if (aii->ai_family == AF_INET) { + af = AF_INET; + break; + } + if (aii->ai_family == AF_INET6) { + af = AF_INET6; + break; + } + // TODO: how to tell io_new_conn the correct ip? + // it also uses addr = &connect->addrs[connect->addrnum]; + //memcpy(&ai, aii, sizeof(struct addrinfo)); + //freeaddrinfo(ais); + //return ai; + } + freeaddrinfo(ais); + // TODO: handle no suitable ai_family found break; } }