View | Details | Raw Unified | Return to bug 264342 | Differences between
and this patch

Collapse All | Expand All

(-)plugins-root/check_icmp.c (-10 / +15 lines)
Lines 233-239 Link Here
233
static struct timezone tz;
233
static struct timezone tz;
234
static struct timeval prog_start;
234
static struct timeval prog_start;
235
static unsigned long long max_completion_time = 0;
235
static unsigned long long max_completion_time = 0;
236
static unsigned char ttl = 0;	/* outgoing ttl */
236
static int ttl = 0;	/* outgoing ttl */
237
static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values */
237
static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values */
238
static int min_hosts_alive = -1;
238
static int min_hosts_alive = -1;
239
float pkt_backoff_factor = 1.5;
239
float pkt_backoff_factor = 1.5;
Lines 530-536 Link Here
530
				add_target(optarg);
530
				add_target(optarg);
531
				break;
531
				break;
532
			case 'l':
532
			case 'l':
533
				ttl = (unsigned char)strtoul(optarg, NULL, 0);
533
				ttl = (unsigned int)strtoul(optarg, NULL, 0);
534
				break;
534
				break;
535
			case 'm':
535
			case 'm':
536
				min_hosts_alive = (int)strtoul(optarg, NULL, 0);
536
				min_hosts_alive = (int)strtoul(optarg, NULL, 0);
Lines 629-637 Link Here
629
	if(!ttl) ttl = 64;
629
	if(!ttl) ttl = 64;
630
630
631
	if(icmp_sock) {
631
	if(icmp_sock) {
632
		result = setsockopt(icmp_sock, SOL_IP, IP_TTL, &ttl, sizeof(ttl));
632
		result = setsockopt(icmp_sock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
633
		if(debug) {
633
		if(debug) {
634
			if(result == -1) printf("setsockopt failed\n");
634
			if(result == -1) printf("setsockopt ttl failed: %s\n",strerror(errno));
635
			else printf("ttl set to %u\n", ttl);
635
			else printf("ttl set to %u\n", ttl);
636
		}
636
		}
637
	}
637
	}
Lines 942-947 Link Here
942
	struct msghdr hdr;
942
	struct msghdr hdr;
943
	struct iovec iov;
943
	struct iovec iov;
944
	struct timeval tv;
944
	struct timeval tv;
945
	size_t addrlen;
945
	void *buf = NULL;
946
	void *buf = NULL;
946
947
947
	if(sock == -1) {
948
	if(sock == -1) {
Lines 969-974 Link Here
969
970
970
	if (address_family == AF_INET) {
971
	if (address_family == AF_INET) {
971
		struct icmp *icp = (struct icmp*)buf;
972
		struct icmp *icp = (struct icmp*)buf;
973
		addrlen = sizeof(struct sockaddr_in);
972
974
973
		memcpy(&icp->icmp_data, &data, sizeof(data));
975
		memcpy(&icp->icmp_data, &data, sizeof(data));
974
976
Lines 980-990 Link Here
980
		icp->icmp_cksum = icmp_checksum((unsigned short*)buf, icmp_pkt_size);
982
		icp->icmp_cksum = icmp_checksum((unsigned short*)buf, icmp_pkt_size);
981
983
982
		if (debug > 2)
984
		if (debug > 2)
983
			printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n",
985
			printf("Sending ICMP4 echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n",
984
				(unsigned long)sizeof(data), ntohs(icp->icmp_id), ntohs(icp->icmp_seq), icp->icmp_cksum, host->name);
986
				(unsigned long)sizeof(data), ntohs(icp->icmp_id), ntohs(icp->icmp_seq), icp->icmp_cksum, host->name);
985
	}
987
	}
986
	else {
988
	else {
987
		struct icmp6_hdr *icp6 = (struct icmp6_hdr*)buf;
989
		struct icmp6_hdr *icp6 = (struct icmp6_hdr*)buf;
990
		addrlen = sizeof(struct sockaddr_in6);
988
		memcpy(&icp6->icmp6_dataun.icmp6_un_data8[4], &data, sizeof(data));
991
		memcpy(&icp6->icmp6_dataun.icmp6_un_data8[4], &data, sizeof(data));
989
		icp6->icmp6_type = ICMP6_ECHO_REQUEST;
992
		icp6->icmp6_type = ICMP6_ECHO_REQUEST;
990
		icp6->icmp6_code = 0;
993
		icp6->icmp6_code = 0;
Lines 994-1000 Link Here
994
		// let checksum be calculated automatically
997
		// let checksum be calculated automatically
995
998
996
		if (debug > 2) {
999
		if (debug > 2) {
997
			printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n",
1000
			printf("Sending ICMP6 echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n",
998
				(unsigned long)sizeof(data), ntohs(icp6->icmp6_id),
1001
				(unsigned long)sizeof(data), ntohs(icp6->icmp6_id),
999
				ntohs(icp6->icmp6_seq), icp6->icmp6_cksum, host->name);
1002
				ntohs(icp6->icmp6_seq), icp6->icmp6_cksum, host->name);
1000
		}
1003
		}
Lines 1006-1012 Link Here
1006
1009
1007
	memset(&hdr, 0, sizeof(hdr));
1010
	memset(&hdr, 0, sizeof(hdr));
1008
	hdr.msg_name = (struct sockaddr *)&host->saddr_in;
1011
	hdr.msg_name = (struct sockaddr *)&host->saddr_in;
1009
	hdr.msg_namelen = sizeof(struct sockaddr_storage);
1012
	hdr.msg_namelen = addrlen;
1010
	hdr.msg_iov = &iov;
1013
	hdr.msg_iov = &iov;
1011
	hdr.msg_iovlen = 1;
1014
	hdr.msg_iovlen = 1;
1012
1015
Lines 1017-1036 Link Here
1017
	len = sendmsg(sock, &hdr, MSG_CONFIRM);
1020
	len = sendmsg(sock, &hdr, MSG_CONFIRM);
1018
#else
1021
#else
1019
	len = sendmsg(sock, &hdr, 0);
1022
	len = sendmsg(sock, &hdr, 0);
1023
/*	printf("without MSG_CONFIRM\n"); */
1020
#endif
1024
#endif
1021
1025
1022
	free(buf);
1023
1024
	if(len < 0 || (unsigned int)len != icmp_pkt_size) {
1026
	if(len < 0 || (unsigned int)len != icmp_pkt_size) {
1025
		if(debug) {
1027
		if(debug) {
1026
			char address[INET6_ADDRSTRLEN];
1028
			char address[INET6_ADDRSTRLEN];
1027
			parse_address((struct sockaddr_storage *)&host->saddr_in, address, sizeof(address));
1029
			parse_address((struct sockaddr_storage *)&host->saddr_in, address, sizeof(address));
1028
			printf("Failed to send ping to %s: %s\n", address, strerror(errno));
1030
			printf("Failed to send hurz ping to %s: %s\n", address, strerror(errno));
1029
		}
1031
		}
1030
		errno = 0;
1032
		errno = 0;
1031
		return -1;
1033
		return -1;
1032
	}
1034
	}
1033
1035
1036
	free(buf);
1037
1034
	icmp_sent++;
1038
	icmp_sent++;
1035
	host->icmp_sent++;
1039
	host->icmp_sent++;
1036
1040
Lines 1428-1433 Link Here
1428
	if(ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1)
1432
	if(ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1)
1429
		crash("Cannot determine IP address of interface %s", ifname);
1433
		crash("Cannot determine IP address of interface %s", ifname);
1430
	memcpy(&ip, &ifr.ifr_addr, sizeof(ip));
1434
	memcpy(&ip, &ifr.ifr_addr, sizeof(ip));
1435
printf("ifname: %s\n",ifname);
1431
	return ip.sin_addr.s_addr;
1436
	return ip.sin_addr.s_addr;
1432
#else
1437
#else
1433
	errno = 0;
1438
	errno = 0;

Return to bug 264342