[Nagios-devel] [patch] NRPE for big endian archs
Posted: Wed Aug 06, 2008 4:41 am
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>8) & 0x00FFFFFF) ^ crc32_table[(crc ^ this_char) & 0xFF];
+ this_char=(uint8_t)buffer[current_index];
+ crc= (crc> 24 ) ^ this_char];
}
return (crc ^ 0xFFFFFFFF);
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]