cacti-spine (0.8.7e-2) official/ping_reliability.patch

Summary

 branches/0.8.7/ping.c |   12 +++++++-----
 branches/0.8.7/ping.h |    2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)

    
download this patch

Patch contents

--- 0.8.7e/ping.c	2009-06-28 21:45:02.000000000 -0400
+++ ../branches/0.8.7/ping.c	2009-08-18 20:51:30.000000000 -0400
@@ -890,7 +890,7 @@
 	return(cleaned_hostname);
 }
 
-/*! \fn unsigned short get_checksum(void* buf, int len)
+/*! \fn unsigned short int get_checksum(void* buf, int len)
  *  \brief calculates a 16bit checksum of a packet buffer
  *  \param buf the input buffer to calculate the checksum of
  *  \param len the size of the input buffer
@@ -898,11 +898,12 @@
  *  \return 16bit checksum of an input buffer of size len.
  *
  */
-unsigned short get_checksum(void* buf, int len) {
+unsigned short int get_checksum(void* buf, int len) {
 	int      nleft = len;
 	int32_t  sum   = 0;
-	unsigned short answer;
-	unsigned short* w = (unsigned short*)buf;
+	unsigned short int answer;
+	unsigned short int* w = (unsigned short int*)buf;
+	unsigned short int odd_byte = 0;
 
 	while (nleft > 1) {
 		sum += *w++;
@@ -910,7 +911,8 @@
 	}
 
 	if (nleft == 1) {
-		sum += *(unsigned char*)w;
+   		*(unsigned char*)(&odd_byte) = *(unsigned char*)w;
+   		sum += odd_byte;
 	}
 
 	sum    = (sum >> 16) + (sum & 0xffff);
--- 0.8.7e/ping.h	2009-06-28 21:45:02.000000000 -0400
+++ ../branches/0.8.7/ping.h	2009-08-18 20:51:30.000000000 -0400
@@ -142,4 +142,4 @@
 extern char *remove_tcp_udp_from_hostname(char *hostname);
 extern void update_host_status(int status, host_t *host, ping_t *ping, int availability_method);
 extern int init_sockaddr(struct sockaddr_in *name, const char *hostname, unsigned short int port);
-extern unsigned short get_checksum(void* buf, int len);
+extern unsigned short int get_checksum(void* buf, int len);