Ethereal-dev: [Ethereal-dev] Fix for bad CRC calculation in packet-iscsi.c

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Mark Burton <markb@xxxxxxxxxx>
Date: Thu, 29 Aug 2002 20:19:42 +0100 (BST)
Hello,

The attached patch reverses the byte ordering of the result of the
CRC32C calculation. Apparently, it was incorrect. Thanks to Dave
Wysochanski <davidw@xxxxxxxxxx> for pointing this out to me.

Cheers,

Mark


Index: packet-iscsi.c
===================================================================
RCS file: /cvsroot/ethereal/packet-iscsi.c,v
retrieving revision 1.37
diff -u -3 -p -r1.37 packet-iscsi.c
--- packet-iscsi.c	2002/08/20 22:33:16	1.37
+++ packet-iscsi.c	2002/08/29 19:09:37
@@ -568,12 +568,22 @@ static guint32 crc32Table[256] = {
 
 #define CRC32C_PRELOAD 0xffffffff
 
+/* 
+ * Byte swap fix contributed by Dave Wysochanski <davidw@xxxxxxxxxx>
+ */
+#define CRC32C_SWAP(crc32c_value) \
+		(((crc32c_value & 0xff000000) >> 24) | \
+		((crc32c_value & 0x00ff0000) >>	 8) | \
+		((crc32c_value & 0x0000ff00) <<	 8) | \
+		((crc32c_value & 0x000000ff) << 24))
+
 static guint32
 calculateCRC32(const void *buf, int len, guint32 crc) {
     guint8 *p = (guint8 *)buf;
+    crc = CRC32C_SWAP(crc);
     while(len-- > 0)
         crc = crc32Table[(crc ^ *p++) & 0xff] ^ (crc >> 8);
-    return crc;
+    return CRC32C_SWAP(crc);
 }
 
 /*