diff options
author | eriksejr <hpx@hotmail.com> | 2022-07-14 04:25:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-14 10:25:51 +0200 |
commit | ee50ddf6988e9d14502ed3fa4645dcd679f347f8 (patch) | |
tree | 1a80c67867b88d7ca260ef5535f3cb30085d1dc9 /plugins-root | |
parent | ccf4ed25f9c96e4d0cd647bbd8d91f38df75dfc0 (diff) | |
download | monitoring-plugins-ee50ddf6988e9d14502ed3fa4645dcd679f347f8.tar.gz |
Set msg_namelen to the size of the sockaddr struct for the appropriate address family and not sockaddr_storage (#1771)
Co-authored-by: Erik Sejr <eriks@ssimicro.com>
Co-authored-by: Lorenz <12514511+RincewindsHat@users.noreply.github.com>
Diffstat (limited to 'plugins-root')
-rw-r--r-- | plugins-root/check_icmp.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 61198237..f8f15351 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
@@ -213,7 +213,7 @@ static int mode, protocols, sockets, debug = 0, timeout = 10; | |||
213 | static unsigned short icmp_data_size = DEFAULT_PING_DATA_SIZE; | 213 | static unsigned short icmp_data_size = DEFAULT_PING_DATA_SIZE; |
214 | static unsigned short icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN; | 214 | static unsigned short icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN; |
215 | 215 | ||
216 | static unsigned int icmp_sent = 0, icmp_recv = 0, icmp_lost = 0; | 216 | static unsigned int icmp_sent = 0, icmp_recv = 0, icmp_lost = 0, ttl = 0; |
217 | #define icmp_pkts_en_route (icmp_sent - (icmp_recv + icmp_lost)) | 217 | #define icmp_pkts_en_route (icmp_sent - (icmp_recv + icmp_lost)) |
218 | static unsigned short targets_down = 0, targets = 0, packets = 0; | 218 | static unsigned short targets_down = 0, targets = 0, packets = 0; |
219 | #define targets_alive (targets - targets_down) | 219 | #define targets_alive (targets - targets_down) |
@@ -223,7 +223,6 @@ static pid_t pid; | |||
223 | static struct timezone tz; | 223 | static struct timezone tz; |
224 | static struct timeval prog_start; | 224 | static struct timeval prog_start; |
225 | static unsigned long long max_completion_time = 0; | 225 | static unsigned long long max_completion_time = 0; |
226 | static unsigned char ttl = 0; /* outgoing ttl */ | ||
227 | static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values */ | 226 | static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values */ |
228 | static int min_hosts_alive = -1; | 227 | static int min_hosts_alive = -1; |
229 | float pkt_backoff_factor = 1.5; | 228 | float pkt_backoff_factor = 1.5; |
@@ -520,7 +519,7 @@ main(int argc, char **argv) | |||
520 | add_target(optarg); | 519 | add_target(optarg); |
521 | break; | 520 | break; |
522 | case 'l': | 521 | case 'l': |
523 | ttl = (unsigned char)strtoul(optarg, NULL, 0); | 522 | ttl = (int)strtoul(optarg, NULL, 0); |
524 | break; | 523 | break; |
525 | case 'm': | 524 | case 'm': |
526 | min_hosts_alive = (int)strtoul(optarg, NULL, 0); | 525 | min_hosts_alive = (int)strtoul(optarg, NULL, 0); |
@@ -948,6 +947,7 @@ static int | |||
948 | send_icmp_ping(int sock, struct rta_host *host) | 947 | send_icmp_ping(int sock, struct rta_host *host) |
949 | { | 948 | { |
950 | long int len; | 949 | long int len; |
950 | size_t addrlen; | ||
951 | struct icmp_ping_data data; | 951 | struct icmp_ping_data data; |
952 | struct msghdr hdr; | 952 | struct msghdr hdr; |
953 | struct iovec iov; | 953 | struct iovec iov; |
@@ -979,6 +979,7 @@ send_icmp_ping(int sock, struct rta_host *host) | |||
979 | 979 | ||
980 | if (address_family == AF_INET) { | 980 | if (address_family == AF_INET) { |
981 | struct icmp *icp = (struct icmp*)buf; | 981 | struct icmp *icp = (struct icmp*)buf; |
982 | addrlen = sizeof(struct sockaddr_in); | ||
982 | 983 | ||
983 | memcpy(&icp->icmp_data, &data, sizeof(data)); | 984 | memcpy(&icp->icmp_data, &data, sizeof(data)); |
984 | 985 | ||
@@ -995,7 +996,10 @@ send_icmp_ping(int sock, struct rta_host *host) | |||
995 | } | 996 | } |
996 | else { | 997 | else { |
997 | struct icmp6_hdr *icp6 = (struct icmp6_hdr*)buf; | 998 | struct icmp6_hdr *icp6 = (struct icmp6_hdr*)buf; |
999 | addrlen = sizeof(struct sockaddr_in6); | ||
1000 | |||
998 | memcpy(&icp6->icmp6_dataun.icmp6_un_data8[4], &data, sizeof(data)); | 1001 | memcpy(&icp6->icmp6_dataun.icmp6_un_data8[4], &data, sizeof(data)); |
1002 | |||
999 | icp6->icmp6_type = ICMP6_ECHO_REQUEST; | 1003 | icp6->icmp6_type = ICMP6_ECHO_REQUEST; |
1000 | icp6->icmp6_code = 0; | 1004 | icp6->icmp6_code = 0; |
1001 | icp6->icmp6_cksum = 0; | 1005 | icp6->icmp6_cksum = 0; |
@@ -1016,7 +1020,7 @@ send_icmp_ping(int sock, struct rta_host *host) | |||
1016 | 1020 | ||
1017 | memset(&hdr, 0, sizeof(hdr)); | 1021 | memset(&hdr, 0, sizeof(hdr)); |
1018 | hdr.msg_name = (struct sockaddr *)&host->saddr_in; | 1022 | hdr.msg_name = (struct sockaddr *)&host->saddr_in; |
1019 | hdr.msg_namelen = sizeof(struct sockaddr_storage); | 1023 | hdr.msg_namelen = addrlen; |
1020 | hdr.msg_iov = &iov; | 1024 | hdr.msg_iov = &iov; |
1021 | hdr.msg_iovlen = 1; | 1025 | hdr.msg_iovlen = 1; |
1022 | 1026 | ||