[patch] NRPE for big endian archs

Klaus Kuehnhammer klaus at parq.net
Wed Aug 6 14:41:45 CEST 2008


Hi,

I've been asked to make the NRPE daemon work on a custom Coldfire board
(arch m68k), w/Nagios querying the daemon from a linux box.

I ran into some issues with the way CRC32 sums are calculated, as well as
the packet struct getting differently aligned on the host and board
(causing the buffer start to be off by 2 bytes depending on where the
word-align paddings goes and/or the compilers disagreeing on the struct
size).

The attached patches solve both problems for me, but break compatibility to
other builds on account of the changed packet struct. I can't think of a
quick way to avoid that at the moment.

changes: 
* explicitly pad packet to word boundaries and a multiple of 4 size
* don't rely on int casts in CRC32 calculation

hope this is of use to someone...

Klaus


diff -Naur nrpe-2.12-ori/include/common.h nrpe-2.12/include/common.h
--- nrpe-2.12-ori/include/common.h	2008-03-10 22:04:42.000000000 +0100
+++ nrpe-2.12/include/common.h	2008-08-06 14:18:34.000000000 +0200
@@ -67,5 +67,6 @@
 	int16_t   packet_type;
 	u_int32_t crc32_value;
 	int16_t   result_code;
+    int16_t   __padding;
 	char      buffer[MAX_PACKETBUFFER_LENGTH];
         }packet;
diff -Naur nrpe-2.12-ori/src/utils.c nrpe-2.12/src/utils.c
--- nrpe-2.12-ori/src/utils.c	2006-12-12 03:04:00.000000000 +0100
+++ nrpe-2.12/src/utils.c	2008-08-06 14:18:34.000000000 +0200
@@ -60,14 +60,14 @@
 /* calculates the CRC 32 value for a buffer */
 unsigned long calculate_crc32(char *buffer, int buffer_size){
 	register unsigned long crc;
-	int this_char;
+	uint8_t this_char;
 	int current_index;
 
 	crc=0xFFFFFFFF;
 
 	for(current_index=0;current_index<buffer_size;current_index++){
-		this_char=(int)buffer[current_index];
-		crc=((crc>>8) & 0x00FFFFFF) ^ crc32_table[(crc ^ this_char) & 0xFF];
+		this_char=(uint8_t)buffer[current_index];
+		crc= (crc<<8)  ^ crc32_table[(crc >> 24 ) ^ this_char];
 	        }
 
 	return (crc ^ 0xFFFFFFFF);


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/




More information about the Developers mailing list