diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2023-03-07 19:51:33 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2023-03-07 19:51:33 +0100 |
commit | 03f86b5d0809967855fbaafb4d600dc5b82081fa (patch) | |
tree | 4a9a5e3aa3147570124dc348938b695269d8cc30 | |
parent | 269718094177fb8a7e3d3005d1310495009fe8c4 (diff) | |
download | monitoring-plugins-03f86b5.tar.gz |
check_curl: in SSL host caching mode try to connect and bind and take the first getaddrinfo result which succeeds
-rw-r--r-- | plugins/check_curl.c | 22 |
1 files 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) | |||
386 | struct addrinfo hints, *res, *result; | 386 | struct addrinfo hints, *res, *result; |
387 | int errcode; | 387 | int errcode; |
388 | void *ptr; | 388 | void *ptr; |
389 | int s; | ||
389 | 390 | ||
390 | memset (&hints, 0, sizeof (hints)); | 391 | memset (&hints, 0, sizeof (hints)); |
391 | hints.ai_family = address_family; | 392 | hints.ai_family = address_family; |
@@ -399,19 +400,26 @@ lookup_host (const char *host, char *buf, size_t buflen) | |||
399 | res = result; | 400 | res = result; |
400 | 401 | ||
401 | while (res) { | 402 | while (res) { |
402 | inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen); | 403 | inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen); |
403 | switch (res->ai_family) { | 404 | switch (res->ai_family) { |
404 | case AF_INET: | 405 | case AF_INET: |
405 | ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; | 406 | ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; |
407 | break; | ||
408 | case AF_INET6: | ||
409 | ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; | ||
406 | break; | 410 | break; |
407 | case AF_INET6: | ||
408 | ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; | ||
409 | break; | ||
410 | } | 411 | } |
412 | |||
411 | inet_ntop (res->ai_family, ptr, buf, buflen); | 413 | inet_ntop (res->ai_family, ptr, buf, buflen); |
412 | if (verbose >= 1) | 414 | if (verbose >= 1) |
413 | printf ("* getaddrinfo IPv%d address: %s\n", | 415 | printf ("* getaddrinfo IPv%d address: %s\n", |
414 | res->ai_family == PF_INET6 ? 6 : 4, buf); | 416 | res->ai_family == PF_INET6 ? 6 : 4, buf); |
417 | |||
418 | if (s = socket (res->ai_family, res->ai_socktype, res->ai_protocol) == -1) | ||
419 | continue; | ||
420 | if (bind (s, res->ai_addr, res->ai_addrlen == 0) ) | ||
421 | break; | ||
422 | |||
415 | res = res->ai_next; | 423 | res = res->ai_next; |
416 | } | 424 | } |
417 | 425 | ||