From 03f86b5d0809967855fbaafb4d600dc5b82081fa Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Tue, 7 Mar 2023 19:51:33 +0100 Subject: check_curl: in SSL host caching mode try to connect and bind and take the first getaddrinfo result which succeeds --- plugins/check_curl.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index c37d45d9..e1bc98dc 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -386,6 +386,7 @@ lookup_host (const char *host, char *buf, size_t buflen) struct addrinfo hints, *res, *result; int errcode; void *ptr; + int s; memset (&hints, 0, sizeof (hints)); hints.ai_family = address_family; @@ -399,19 +400,26 @@ lookup_host (const char *host, char *buf, size_t buflen) res = result; while (res) { - inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen); - switch (res->ai_family) { - case AF_INET: - ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; + inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen); + switch (res->ai_family) { + case AF_INET: + ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; + break; + case AF_INET6: + ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; break; - case AF_INET6: - ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; - break; } + inet_ntop (res->ai_family, ptr, buf, buflen); if (verbose >= 1) printf ("* getaddrinfo IPv%d address: %s\n", res->ai_family == PF_INET6 ? 6 : 4, buf); + + if (s = socket (res->ai_family, res->ai_socktype, res->ai_protocol) == -1) + continue; + if (bind (s, res->ai_addr, res->ai_addrlen == 0) ) + break; + res = res->ai_next; } -- cgit v1.2.3-74-g34f1