summaryrefslogtreecommitdiffstats
path: root/plugins-root
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2014-11-28 14:35:38 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2014-11-28 15:23:28 (GMT)
commit8e5118e0cba939a3a2854204ee3169466190018f (patch)
tree86363edb8d2f1dbf524ede14773581c80cfba39b /plugins-root
parent5265fabeb98dc2af702a56f1a4b45627c3d4d93f (diff)
downloadmonitoring-plugins-8e5118e0cba939a3a2854204ee3169466190018f.tar.gz
Don't mix variable declarations and code
We still support pre-C99 compilers.
Diffstat (limited to 'plugins-root')
-rw-r--r--plugins-root/check_icmp.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index d2f637f..0771325 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -378,6 +378,9 @@ main(int argc, char **argv)
378 int icmp_sockerrno, udp_sockerrno, tcp_sockerrno; 378 int icmp_sockerrno, udp_sockerrno, tcp_sockerrno;
379 int result; 379 int result;
380 struct rta_host *host; 380 struct rta_host *host;
381#ifdef SO_TIMESTAMP
382 int on = 1;
383#endif
381 384
382 setlocale (LC_ALL, ""); 385 setlocale (LC_ALL, "");
383 bindtextdomain (PACKAGE, LOCALEDIR); 386 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -403,7 +406,6 @@ main(int argc, char **argv)
403 setuid(getuid()); 406 setuid(getuid());
404 407
405#ifdef SO_TIMESTAMP 408#ifdef SO_TIMESTAMP
406 int on = 1;
407 if(setsockopt(icmp_sock, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on))) 409 if(setsockopt(icmp_sock, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on)))
408 if(debug) printf("Warning: no SO_TIMESTAMP support\n"); 410 if(debug) printf("Warning: no SO_TIMESTAMP support\n");
409#endif // SO_TIMESTAMP 411#endif // SO_TIMESTAMP
@@ -828,6 +830,8 @@ send_icmp_ping(int sock, struct rta_host *host)
828 } packet = { NULL }; 830 } packet = { NULL };
829 long int len; 831 long int len;
830 struct icmp_ping_data data; 832 struct icmp_ping_data data;
833 struct msghdr hdr;
834 struct iovec iov;
831 struct timeval tv; 835 struct timeval tv;
832 struct sockaddr *addr; 836 struct sockaddr *addr;
833 837
@@ -863,16 +867,16 @@ send_icmp_ping(int sock, struct rta_host *host)
863 printf("Sending ICMP echo-request of len %u, id %u, seq %u, cksum 0x%X to host %s\n", 867 printf("Sending ICMP echo-request of len %u, id %u, seq %u, cksum 0x%X to host %s\n",
864 sizeof(data), ntohs(packet.icp->icmp_id), ntohs(packet.icp->icmp_seq), packet.icp->icmp_cksum, host->name); 868 sizeof(data), ntohs(packet.icp->icmp_id), ntohs(packet.icp->icmp_seq), packet.icp->icmp_cksum, host->name);
865 869
866 struct msghdr hdr;
867 memset(&hdr, 0, sizeof(hdr));
868 hdr.msg_name = addr;
869 hdr.msg_namelen = sizeof(struct sockaddr);
870 struct iovec iov;
871 memset(&iov, 0, sizeof(iov)); 870 memset(&iov, 0, sizeof(iov));
872 iov.iov_base = packet.buf; 871 iov.iov_base = packet.buf;
873 iov.iov_len = icmp_pkt_size; 872 iov.iov_len = icmp_pkt_size;
873
874 memset(&hdr, 0, sizeof(hdr));
875 hdr.msg_name = addr;
876 hdr.msg_namelen = sizeof(struct sockaddr);
874 hdr.msg_iov = &iov; 877 hdr.msg_iov = &iov;
875 hdr.msg_iovlen = 1; 878 hdr.msg_iovlen = 1;
879
876 len = sendmsg(sock, &hdr, MSG_CONFIRM); 880 len = sendmsg(sock, &hdr, MSG_CONFIRM);
877 881
878 if(len < 0 || (unsigned int)len != icmp_pkt_size) { 882 if(len < 0 || (unsigned int)len != icmp_pkt_size) {
@@ -892,9 +896,15 @@ recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr,
892 u_int *timo, struct timeval* tv) 896 u_int *timo, struct timeval* tv)
893{ 897{
894 u_int slen; 898 u_int slen;
895 int n; 899 int n, ret;
896 struct timeval to, then, now; 900 struct timeval to, then, now;
897 fd_set rd, wr; 901 fd_set rd, wr;
902 char ans_data[4096];
903 struct msghdr hdr;
904 struct iovec iov;
905#ifdef SO_TIMESTAMP
906 struct cmsghdr* chdr;
907#endif
898 908
899 if(!*timo) { 909 if(!*timo) {
900 if(debug) printf("*timo is not\n"); 910 if(debug) printf("*timo is not\n");
@@ -918,22 +928,20 @@ recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr,
918 928
919 slen = sizeof(struct sockaddr); 929 slen = sizeof(struct sockaddr);
920 930
921 struct msghdr hdr;
922 memset(&hdr, 0, sizeof(hdr));
923 hdr.msg_name = saddr;
924 hdr.msg_namelen = slen;
925 struct iovec iov;
926 memset(&iov, 0, sizeof(iov)); 931 memset(&iov, 0, sizeof(iov));
927 iov.iov_base = buf; 932 iov.iov_base = buf;
928 iov.iov_len = len; 933 iov.iov_len = len;
934
935 memset(&hdr, 0, sizeof(hdr));
936 hdr.msg_name = saddr;
937 hdr.msg_namelen = slen;
929 hdr.msg_iov = &iov; 938 hdr.msg_iov = &iov;
930 hdr.msg_iovlen = 1; 939 hdr.msg_iovlen = 1;
931 char ans_data[4096];
932 hdr.msg_control = ans_data; 940 hdr.msg_control = ans_data;
933 hdr.msg_controllen = sizeof(ans_data); 941 hdr.msg_controllen = sizeof(ans_data);
934 int ret = recvmsg(sock, &hdr, 0); 942
943 ret = recvmsg(sock, &hdr, 0);
935#ifdef SO_TIMESTAMP 944#ifdef SO_TIMESTAMP
936 struct cmsghdr* chdr;
937 for(chdr = CMSG_FIRSTHDR(&hdr); chdr; chdr = CMSG_NXTHDR(&hdr, chdr)) { 945 for(chdr = CMSG_FIRSTHDR(&hdr); chdr; chdr = CMSG_NXTHDR(&hdr, chdr)) {
938 if(chdr->cmsg_level == SOL_SOCKET 946 if(chdr->cmsg_level == SOL_SOCKET
939 && chdr->cmsg_type == SO_TIMESTAMP 947 && chdr->cmsg_type == SO_TIMESTAMP