diff options
author | Lorenz Kästle <lorenz.kaestle@netways.de> | 2024-10-30 16:12:19 (GMT) |
---|---|---|
committer | Lorenz Kästle <lorenz.kaestle@netways.de> | 2024-10-30 16:12:19 (GMT) |
commit | de6e3c45f3f0889a5b4aada623cbefbd9fcb434d (patch) | |
tree | 98765e11067910102c9b602a223ee5a2818c2d1e /plugins-root | |
parent | 3f1db8dc3a0a5233d338fd6bd5e80971bfb21545 (diff) | |
download | monitoring-plugins-de6e3c45f3f0889a5b4aada623cbefbd9fcb434d.tar.gz |
check_icmp: Apply clang-format againrefs/pull/2028/head
Diffstat (limited to 'plugins-root')
-rw-r--r-- | plugins-root/check_icmp.c | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 6eefeb0..960ab8f 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
@@ -580,7 +580,8 @@ int main(int argc, char **argv) { | |||
580 | icmp_data_size = size; | 580 | icmp_data_size = size; |
581 | icmp_pkt_size = size + ICMP_MINLEN; | 581 | icmp_pkt_size = size + ICMP_MINLEN; |
582 | } else | 582 | } else |
583 | usage_va("ICMP data length must be between: %lu and %lu", sizeof(struct icmp) + sizeof(struct icmp_ping_data), MAX_PING_DATA - 1); | 583 | usage_va("ICMP data length must be between: %lu and %lu", sizeof(struct icmp) + sizeof(struct icmp_ping_data), |
584 | MAX_PING_DATA - 1); | ||
584 | break; | 585 | break; |
585 | case 'i': | 586 | case 'i': |
586 | pkt_interval = get_timevar(optarg); | 587 | pkt_interval = get_timevar(optarg); |
@@ -803,7 +804,8 @@ int main(int argc, char **argv) { | |||
803 | "target_interval: %0.3f, pkt_interval %0.3f\n" | 804 | "target_interval: %0.3f, pkt_interval %0.3f\n" |
804 | "crit.rta: %0.3f\n" | 805 | "crit.rta: %0.3f\n" |
805 | "max_completion_time: %0.3f\n", | 806 | "max_completion_time: %0.3f\n", |
806 | packets, targets, (float)target_interval / 1000, (float)pkt_interval / 1000, (float)crit.rta / 1000, (float)max_completion_time / 1000); | 807 | packets, targets, (float)target_interval / 1000, (float)pkt_interval / 1000, (float)crit.rta / 1000, |
808 | (float)max_completion_time / 1000); | ||
807 | } | 809 | } |
808 | 810 | ||
809 | if (debug) { | 811 | if (debug) { |
@@ -997,9 +999,10 @@ static int wait_for_reply(int sock, u_int t) { | |||
997 | /* address_family == AF_INET6 ? sizeof(struct icmp6_hdr) | 999 | /* address_family == AF_INET6 ? sizeof(struct icmp6_hdr) |
998 | : sizeof(struct icmp));*/ | 1000 | : sizeof(struct icmp));*/ |
999 | 1001 | ||
1000 | if ((address_family == PF_INET && (ntohs(packet.icp->icmp_id) != pid || packet.icp->icmp_type != ICMP_ECHOREPLY || ntohs(packet.icp->icmp_seq) >= targets * packets)) || | 1002 | if ((address_family == PF_INET && (ntohs(packet.icp->icmp_id) != pid || packet.icp->icmp_type != ICMP_ECHOREPLY || |
1001 | (address_family == PF_INET6 && | 1003 | ntohs(packet.icp->icmp_seq) >= targets * packets)) || |
1002 | (ntohs(packet.icp6->icmp6_id) != pid || packet.icp6->icmp6_type != ICMP6_ECHO_REPLY || ntohs(packet.icp6->icmp6_seq) >= targets * packets))) { | 1004 | (address_family == PF_INET6 && (ntohs(packet.icp6->icmp6_id) != pid || packet.icp6->icmp6_type != ICMP6_ECHO_REPLY || |
1005 | ntohs(packet.icp6->icmp6_seq) >= targets * packets))) { | ||
1003 | if (debug > 2) | 1006 | if (debug > 2) |
1004 | printf("not a proper ICMP_ECHOREPLY\n"); | 1007 | printf("not a proper ICMP_ECHOREPLY\n"); |
1005 | handle_random_icmp(buf + hlen, &resp_addr); | 1008 | handle_random_icmp(buf + hlen, &resp_addr); |
@@ -1010,14 +1013,14 @@ static int wait_for_reply(int sock, u_int t) { | |||
1010 | if (address_family == PF_INET) { | 1013 | if (address_family == PF_INET) { |
1011 | memcpy(&data, packet.icp->icmp_data, sizeof(data)); | 1014 | memcpy(&data, packet.icp->icmp_data, sizeof(data)); |
1012 | if (debug > 2) | 1015 | if (debug > 2) |
1013 | printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n", (unsigned long)sizeof(data), ntohs(packet.icp->icmp_id), ntohs(packet.icp->icmp_seq), | 1016 | printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n", (unsigned long)sizeof(data), ntohs(packet.icp->icmp_id), |
1014 | packet.icp->icmp_cksum); | 1017 | ntohs(packet.icp->icmp_seq), packet.icp->icmp_cksum); |
1015 | host = table[ntohs(packet.icp->icmp_seq) / packets]; | 1018 | host = table[ntohs(packet.icp->icmp_seq) / packets]; |
1016 | } else { | 1019 | } else { |
1017 | memcpy(&data, &packet.icp6->icmp6_dataun.icmp6_un_data8[4], sizeof(data)); | 1020 | memcpy(&data, &packet.icp6->icmp6_dataun.icmp6_un_data8[4], sizeof(data)); |
1018 | if (debug > 2) | 1021 | if (debug > 2) |
1019 | printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n", (unsigned long)sizeof(data), ntohs(packet.icp6->icmp6_id), ntohs(packet.icp6->icmp6_seq), | 1022 | printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n", (unsigned long)sizeof(data), ntohs(packet.icp6->icmp6_id), |
1020 | packet.icp6->icmp6_cksum); | 1023 | ntohs(packet.icp6->icmp6_seq), packet.icp6->icmp6_cksum); |
1021 | host = table[ntohs(packet.icp6->icmp6_seq) / packets]; | 1024 | host = table[ntohs(packet.icp6->icmp6_seq) / packets]; |
1022 | } | 1025 | } |
1023 | 1026 | ||
@@ -1069,12 +1072,13 @@ static int wait_for_reply(int sock, u_int t) { | |||
1069 | 1072 | ||
1070 | switch (address_family) { | 1073 | switch (address_family) { |
1071 | case AF_INET: { | 1074 | case AF_INET: { |
1072 | printf("%0.3f ms rtt from %s, outgoing ttl: %u, incoming ttl: %u, max: %0.3f, min: %0.3f\n", (float)tdiff / 1000, address, ttl, ip->ip.ip_ttl, | 1075 | printf("%0.3f ms rtt from %s, outgoing ttl: %u, incoming ttl: %u, max: %0.3f, min: %0.3f\n", (float)tdiff / 1000, address, |
1073 | (float)host->rtmax / 1000, (float)host->rtmin / 1000); | 1076 | ttl, ip->ip.ip_ttl, (float)host->rtmax / 1000, (float)host->rtmin / 1000); |
1074 | break; | 1077 | break; |
1075 | }; | 1078 | }; |
1076 | case AF_INET6: { | 1079 | case AF_INET6: { |
1077 | printf("%0.3f ms rtt from %s, outgoing ttl: %u, max: %0.3f, min: %0.3f\n", (float)tdiff / 1000, address, ttl, (float)host->rtmax / 1000, (float)host->rtmin / 1000); | 1080 | printf("%0.3f ms rtt from %s, outgoing ttl: %u, max: %0.3f, min: %0.3f\n", (float)tdiff / 1000, address, ttl, |
1081 | (float)host->rtmax / 1000, (float)host->rtmin / 1000); | ||
1078 | }; | 1082 | }; |
1079 | } | 1083 | } |
1080 | } | 1084 | } |
@@ -1083,7 +1087,8 @@ static int wait_for_reply(int sock, u_int t) { | |||
1083 | if (mode == MODE_HOSTCHECK) { | 1087 | if (mode == MODE_HOSTCHECK) { |
1084 | printf("OK - %s responds to ICMP. Packet %u, rta %0.3fms|" | 1088 | printf("OK - %s responds to ICMP. Packet %u, rta %0.3fms|" |
1085 | "pkt=%u;;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n", | 1089 | "pkt=%u;;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n", |
1086 | host->name, icmp_recv, (float)tdiff / 1000, icmp_recv, packets, (float)tdiff / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000); | 1090 | host->name, icmp_recv, (float)tdiff / 1000, icmp_recv, packets, (float)tdiff / 1000, (float)warn.rta / 1000, |
1091 | (float)crit.rta / 1000); | ||
1087 | exit(STATE_OK); | 1092 | exit(STATE_OK); |
1088 | } | 1093 | } |
1089 | } | 1094 | } |
@@ -1138,8 +1143,8 @@ static int send_icmp_ping(int sock, struct rta_host *host) { | |||
1138 | icp->icmp_cksum = icmp_checksum((uint16_t *)buf, (size_t)icmp_pkt_size); | 1143 | icp->icmp_cksum = icmp_checksum((uint16_t *)buf, (size_t)icmp_pkt_size); |
1139 | 1144 | ||
1140 | if (debug > 2) | 1145 | if (debug > 2) |
1141 | printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n", (unsigned long)sizeof(data), ntohs(icp->icmp_id), ntohs(icp->icmp_seq), | 1146 | printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n", (unsigned long)sizeof(data), |
1142 | icp->icmp_cksum, host->name); | 1147 | ntohs(icp->icmp_id), ntohs(icp->icmp_seq), icp->icmp_cksum, host->name); |
1143 | } else { | 1148 | } else { |
1144 | struct icmp6_hdr *icp6 = (struct icmp6_hdr *)buf; | 1149 | struct icmp6_hdr *icp6 = (struct icmp6_hdr *)buf; |
1145 | addrlen = sizeof(struct sockaddr_in6); | 1150 | addrlen = sizeof(struct sockaddr_in6); |
@@ -1154,8 +1159,8 @@ static int send_icmp_ping(int sock, struct rta_host *host) { | |||
1154 | // let checksum be calculated automatically | 1159 | // let checksum be calculated automatically |
1155 | 1160 | ||
1156 | if (debug > 2) { | 1161 | if (debug > 2) { |
1157 | printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n", (unsigned long)sizeof(data), ntohs(icp6->icmp6_id), ntohs(icp6->icmp6_seq), | 1162 | printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n", (unsigned long)sizeof(data), |
1158 | icp6->icmp6_cksum, host->name); | 1163 | ntohs(icp6->icmp6_id), ntohs(icp6->icmp6_seq), icp6->icmp6_cksum, host->name); |
1159 | } | 1164 | } |
1160 | } | 1165 | } |
1161 | 1166 | ||
@@ -1542,11 +1547,13 @@ static void finish(int sig) { | |||
1542 | 1547 | ||
1543 | if (rta_mode) { | 1548 | if (rta_mode) { |
1544 | if (host->pl < 100) { | 1549 | if (host->pl < 100) { |
1545 | printf("%srta=%0.3fms;%0.3f;%0.3f;0; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ", (targets > 1) ? host->name : "", host->rta / 1000, (float)warn.rta / 1000, | 1550 | printf("%srta=%0.3fms;%0.3f;%0.3f;0; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ", (targets > 1) ? host->name : "", |
1546 | (float)crit.rta / 1000, (targets > 1) ? host->name : "", (float)host->rtmax / 1000, (targets > 1) ? host->name : "", | 1551 | host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000, (targets > 1) ? host->name : "", |
1552 | (float)host->rtmax / 1000, (targets > 1) ? host->name : "", | ||
1547 | (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0); | 1553 | (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0); |
1548 | } else { | 1554 | } else { |
1549 | printf("%srta=U;;;; %srtmax=U;;;; %srtmin=U;;;; ", (targets > 1) ? host->name : "", (targets > 1) ? host->name : "", (targets > 1) ? host->name : ""); | 1555 | printf("%srta=U;;;; %srtmax=U;;;; %srtmin=U;;;; ", (targets > 1) ? host->name : "", (targets > 1) ? host->name : "", |
1556 | (targets > 1) ? host->name : ""); | ||
1550 | } | 1557 | } |
1551 | } | 1558 | } |
1552 | 1559 | ||
@@ -1556,12 +1563,13 @@ static void finish(int sig) { | |||
1556 | 1563 | ||
1557 | if (jitter_mode) { | 1564 | if (jitter_mode) { |
1558 | if (host->pl < 100) { | 1565 | if (host->pl < 100) { |
1559 | printf("%sjitter_avg=%0.3fms;%0.3f;%0.3f;0; %sjitter_max=%0.3fms;;;; %sjitter_min=%0.3fms;;;; ", (targets > 1) ? host->name : "", (float)host->jitter, | 1566 | printf("%sjitter_avg=%0.3fms;%0.3f;%0.3f;0; %sjitter_max=%0.3fms;;;; %sjitter_min=%0.3fms;;;; ", |
1560 | (float)warn.jitter, (float)crit.jitter, (targets > 1) ? host->name : "", (float)host->jitter_max / 1000, (targets > 1) ? host->name : "", | 1567 | (targets > 1) ? host->name : "", (float)host->jitter, (float)warn.jitter, (float)crit.jitter, |
1568 | (targets > 1) ? host->name : "", (float)host->jitter_max / 1000, (targets > 1) ? host->name : "", | ||
1561 | (float)host->jitter_min / 1000); | 1569 | (float)host->jitter_min / 1000); |
1562 | } else { | 1570 | } else { |
1563 | printf("%sjitter_avg=U;;;; %sjitter_max=U;;;; %sjitter_min=U;;;; ", (targets > 1) ? host->name : "", (targets > 1) ? host->name : "", | 1571 | printf("%sjitter_avg=U;;;; %sjitter_max=U;;;; %sjitter_min=U;;;; ", (targets > 1) ? host->name : "", |
1564 | (targets > 1) ? host->name : ""); | 1572 | (targets > 1) ? host->name : "", (targets > 1) ? host->name : ""); |
1565 | } | 1573 | } |
1566 | } | 1574 | } |
1567 | 1575 | ||
@@ -1594,7 +1602,8 @@ static void finish(int sig) { | |||
1594 | /* finish with an empty line */ | 1602 | /* finish with an empty line */ |
1595 | puts(""); | 1603 | puts(""); |
1596 | if (debug) | 1604 | if (debug) |
1597 | printf("targets: %u, targets_alive: %u, hosts_ok: %u, hosts_warn: %u, min_hosts_alive: %i\n", targets, targets_alive, hosts_ok, hosts_warn, min_hosts_alive); | 1605 | printf("targets: %u, targets_alive: %u, hosts_ok: %u, hosts_warn: %u, min_hosts_alive: %i\n", targets, targets_alive, hosts_ok, |
1606 | hosts_warn, min_hosts_alive); | ||
1598 | 1607 | ||
1599 | exit(status); | 1608 | exit(status); |
1600 | } | 1609 | } |