[monitoring-plugins] check_curl: in SSL host caching mode try to ...

Andreas Baumann git at monitoring-plugins.org
Tue Mar 7 20:00:12 CET 2023


 Module: monitoring-plugins
 Branch: curlfix1845
 Commit: 03f86b5d0809967855fbaafb4d600dc5b82081fa
 Author: Andreas Baumann <mail at andreasbaumann.cc>
   Date: Tue Mar  7 19:51:33 2023 +0100
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=03f86b5

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 c37d45d..e1bc98d 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;
   }
   



More information about the Commits mailing list