summaryrefslogtreecommitdiff
path: root/epan
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2004-09-28 00:06:32 +0000
committerGuy Harris <guy@alum.mit.edu>2004-09-28 00:06:32 +0000
commitac98f225a8db46c1c6e29abfbed24c91544fa6e4 (patch)
tree59d5dec9184edbda7fc0e1335e7262c6d178b7af /epan
parentd3f5261971af423b220eda7f852e7511b0b571da (diff)
downloadwireshark-ac98f225a8db46c1c6e29abfbed24c91544fa6e4.tar.gz
Move various checksum routines and headers to epan.
svn path=/trunk/; revision=12117
Diffstat (limited to 'epan')
-rw-r--r--epan/Makefile.common12
-rw-r--r--epan/adler32.c59
-rw-r--r--epan/adler32.h42
-rw-r--r--epan/crc16.c182
-rw-r--r--epan/crc16.h86
-rw-r--r--epan/crc32.c174
-rw-r--r--epan/crc32.h82
-rw-r--r--epan/dissectors/packet-eth.c2
-rw-r--r--epan/dissectors/packet-gre.c2
-rw-r--r--epan/dissectors/packet-icmpv6.c2
-rw-r--r--epan/dissectors/packet-ieee80211.c2
-rw-r--r--epan/dissectors/packet-igmp.c2
-rw-r--r--epan/dissectors/packet-ip.c2
-rw-r--r--epan/dissectors/packet-ipvs-syncd.c2
-rw-r--r--epan/dissectors/packet-lmp.c2
-rw-r--r--epan/dissectors/packet-ospf.c2
-rw-r--r--epan/dissectors/packet-pgm.c2
-rw-r--r--epan/dissectors/packet-pim.c2
-rw-r--r--epan/dissectors/packet-ppp.c4
-rw-r--r--epan/dissectors/packet-rsvp.c2
-rw-r--r--epan/dissectors/packet-tcp.c2
-rw-r--r--epan/dissectors/packet-udp.c2
-rw-r--r--epan/dissectors/packet-vj.c2
-rw-r--r--epan/dissectors/packet-vrrp.c2
-rw-r--r--epan/in_cksum.c201
-rw-r--r--epan/in_cksum.h14
-rw-r--r--epan/plugins.c2
27 files changed, 867 insertions, 23 deletions
diff --git a/epan/Makefile.common b/epan/Makefile.common
index efb45b3c16..56413c5b79 100644
--- a/epan/Makefile.common
+++ b/epan/Makefile.common
@@ -26,6 +26,7 @@
LIBETHEREAL_SRC = \
addr_and_mask.c \
addr_resolv.c \
+ adler32.c \
atalk-utils.c \
base64.c \
bitswap.c \
@@ -33,6 +34,8 @@ LIBETHEREAL_SRC = \
circuit.c \
column-utils.c \
conversation.c \
+ crc16.c \
+ crc32.c \
crypt-des.c \
crypt-md4.c \
crypt-md5.c \
@@ -41,6 +44,7 @@ LIBETHEREAL_SRC = \
except.c \
filesystem.c \
frame_data.c \
+ in_cksum.c \
ipv4.c \
osi-utils.c \
packet.c \
@@ -59,6 +63,7 @@ LIBETHEREAL_INCLUDES = \
addr_and_mask.h \
addr_resolv.h \
address.h \
+ adler32.h \
atalk-utils.h \
base64.h \
bitswap.h \
@@ -67,6 +72,8 @@ LIBETHEREAL_INCLUDES = \
column_info.h \
conversation.h \
column-utils.h \
+ crc16.h \
+ crc32.h \
crypt-des.h \
crypt-md4.h \
crypt-md5.h \
@@ -78,6 +85,7 @@ LIBETHEREAL_INCLUDES = \
filesystem.h \
frame_data.h \
gdebug.h \
+ in_cksum.h \
ipv4.h \
ipv6-utils.h \
nstime.h \
@@ -100,15 +108,11 @@ LIBETHEREAL_INCLUDES = \
# dissector helpers (needed from the dissectors, but not a dissector itself)
DISSECTOR_SUPPORT_SRC = \
- ../adler32.c \
../afn.c \
../asn1.c \
../column.c \
- ../crc16.c \
- ../crc32.c \
../follow.c \
../h225-persistentdata.c \
- ../in_cksum.c \
../ipproto.c \
../ptvcursor.c \
../reassemble.c \
diff --git a/epan/adler32.c b/epan/adler32.c
new file mode 100644
index 0000000000..dc443b6ddb
--- /dev/null
+++ b/epan/adler32.c
@@ -0,0 +1,59 @@
+/* adler32.c
+ * Compute the Adler32 checksum (RFC 1950)
+ * 2003 Tomas Kukosa
+ * Based on code from RFC 1950 (Chapter 9. Appendix: Sample code)
+ *
+ * $Id$
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <string.h>
+
+#include <epan/adler32.h>
+
+#define BASE 65521 /* largest prime smaller than 65536 */
+
+/*--- update_adler32 --------------------------------------------------------*/
+unsigned long update_adler32(unsigned long adler, const unsigned char *buf, int len)
+{
+ unsigned long s1 = adler & 0xffff;
+ unsigned long s2 = (adler >> 16) & 0xffff;
+ int n;
+
+ for (n = 0; n < len; n++) {
+ s1 = (s1 + buf[n]) % BASE;
+ s2 = (s2 + s1) % BASE;
+ }
+ return (s2 << 16) + s1;
+}
+
+/*--- adler32 ---------------------------------------------------------------*/
+unsigned long adler32_bytes(unsigned char *buf, int len)
+{
+ return update_adler32(1L, buf, len);
+}
+
+/*--- adler32_str -----------------------------------------------------------*/
+unsigned long adler32_str(const char *buf)
+{
+ return update_adler32(1L, (unsigned char*)buf, strlen(buf));
+}
+
+/*---------------------------------------------------------------------------*/
diff --git a/epan/adler32.h b/epan/adler32.h
new file mode 100644
index 0000000000..4e0f051f4c
--- /dev/null
+++ b/epan/adler32.h
@@ -0,0 +1,42 @@
+/* adler32.h
+ * Compute the Adler32 checksum (RFC 1950)
+ * 2003 Tomas Kukosa
+ *
+ * $Id$
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef ADLER32_H
+#define ADLER32_H
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+unsigned long update_adler32(unsigned long adler, const unsigned char *buf, int len);
+unsigned long adler32_bytes(unsigned char *buf, int len);
+unsigned long adler32_str(const char *buf);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ADLER32_H */
+
diff --git a/epan/crc16.c b/epan/crc16.c
new file mode 100644
index 0000000000..a371ffe77c
--- /dev/null
+++ b/epan/crc16.c
@@ -0,0 +1,182 @@
+/* crc16.c
+ * CRC-16 routine
+ *
+ * 2004 Richard van der Hoff <richardv@mxtelecom.com>
+ *
+ * $Id$
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@xxxxxxxxxxxx>
+ * Copyright 1998 Gerald Combs
+ *
+ * Copied from README.developer
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * References:
+ * "A Painless Guide to CRC Error Detection Algorithms", Ross Williams
+ * http://www.repairfaq.org/filipg/LINK/F_crc_v3.html
+ *
+ * ITU-T Recommendation V.42 (2002), "Error-Correcting Procedures for
+ * DCEs using asynchronous-to-synchronous conversion", Para. 8.1.1.6.1
+ */
+
+#include <glib.h>
+#include <epan/tvbuff.h>
+#include <epan/crc16.h>
+
+
+/*****************************************************************/
+
+/*
+ * Table for the CCITT/ITU/CRC-16 16-bit CRC
+ *
+ * Polynomial is
+ *
+ * x^16 + x^12 + x^5 + 1
+ */
+
+/* */
+/* CRC LOOKUP TABLE */
+/* ================ */
+/* The following CRC lookup table was generated automagically */
+/* by the Rocksoft^tm Model CRC Algorithm Table Generation */
+/* Program V1.0 using the following model parameters: */
+/* */
+/* Width : 2 bytes. */
+/* Poly : 0x1021 */
+/* Reverse : TRUE. */
+/* */
+/* For more information on the Rocksoft^tm Model CRC Algorithm, */
+/* see the document titled "A Painless Guide to CRC Error */
+/* Detection Algorithms" by Ross Williams */
+/* (ross@xxxxxxxxxxxxxxxxxxxxxx). This document is likely to be */
+/* in the FTP archive "ftp.adelaide.edu.au/pub/rocksoft". */
+/* */
+/*****************************************************************/
+
+static const guint crc16_ccitt_table[256] =
+{
+ 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF,
+ 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7,
+ 0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E,
+ 0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876,
+ 0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD,
+ 0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5,
+ 0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C,
+ 0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974,
+ 0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB,
+ 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3,
+ 0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A,
+ 0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72,
+ 0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9,
+ 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1,
+ 0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738,
+ 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70,
+ 0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7,
+ 0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF,
+ 0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036,
+ 0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E,
+ 0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5,
+ 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD,
+ 0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134,
+ 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C,
+ 0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3,
+ 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB,
+ 0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232,
+ 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A,
+ 0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1,
+ 0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9,
+ 0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330,
+ 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78
+};
+
+static const guint16 crc16_ccitt_start = 0xFFFF;
+static const guint16 crc16_ccitt_xorout = 0xFFFF;
+
+/* two types of crcs are possible: unreflected (bits shift left) and
+ * reflected (bits shift right).
+ */
+#if 0
+static guint16 crc16_unreflected(const guint8 *buf, guint len,
+ guint16 crc_in, const guint table[])
+{
+ /* we use guints, rather than guint16s, as they are likely to be
+ faster. We just ignore the top 16 bits and let them do what they want. */
+ guint crc16 = (guint)crc_in;;
+
+ while( len-- != 0 )
+ crc16 = table[(crc16 ^ *buf++) & 0xff] ^ (crc16 << 8);
+
+ return (guint16)crc16;
+}
+#endif
+
+static guint16 crc16_reflected(const guint8 *buf, guint len,
+ guint16 crc_in, const guint table[])
+{
+ /* we use guints, rather than guint16s, as they are likely to be
+ faster. We just ignore the top 16 bits and let them do what they want.
+ XXX - does any time saved not zero-extending guint16's to 32 bits
+ into a register outweigh any increased cache footprint from the
+ larger CRC table? */
+ guint crc16 = (guint)crc_in;
+
+ while( len-- != 0 )
+ crc16 = table[(crc16 ^ *buf++) & 0xff] ^ (crc16 >> 8);
+
+ return (guint16)crc16;
+}
+
+guint16 crc16_ccitt(const guint8 *buf, guint len)
+{
+ return crc16_reflected(buf,len,crc16_ccitt_start,crc16_ccitt_table)
+ ^ crc16_ccitt_xorout;
+}
+
+guint16 crc16_ccitt_seed(const guint8 *buf, guint len, guint16 seed)
+{
+ return crc16_reflected(buf,len,seed,crc16_ccitt_table)
+ ^ crc16_ccitt_xorout;
+}
+
+guint16 crc16_ccitt_tvb(tvbuff_t *tvb, guint len)
+{
+ const guint8* buf = tvb_get_ptr(tvb, 0, len);
+
+ return crc16_ccitt(buf, len);
+}
+
+guint16 crc16_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
+{
+ const guint8* buf = tvb_get_ptr(tvb, offset, len);
+
+ return crc16_ccitt(buf, len);
+}
+
+guint16 crc16_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint16 seed)
+{
+ const guint8* buf = tvb_get_ptr(tvb, 0, len);
+
+ return crc16_ccitt_seed(buf, len, seed);
+}
+
+guint16 crc16_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 seed)
+{
+ const guint8* buf = tvb_get_ptr(tvb, offset, len);
+
+ return crc16_ccitt_seed(buf, len, seed);
+}
+
diff --git a/epan/crc16.h b/epan/crc16.h
new file mode 100644
index 0000000000..8df7b47a32
--- /dev/null
+++ b/epan/crc16.h
@@ -0,0 +1,86 @@
+/* crc16.h
+ * Declaration of CRC-16 routines and table
+ *
+ * 2004 Richard van der Hoff <richardv@mxtelecom.com>
+ *
+ * $Id$
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@xxxxxxxxxxxx>
+ * Copyright 1998 Gerald Combs
+ *
+ * Copied from README.developer
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+/* Calculate the CCITT/ITU/CRC-16 16-bit CRC
+
+ (parameters for this CRC are:
+ Polynomial: x^16 + x^12 + x^5 + 1 (0x1021);
+ Start value 0xFFFF;
+ XOR result with 0xFFFF;
+ First bit is LSB)
+*/
+
+/** Compute CRC16 CCITT checksum of a buffer of data.
+ @param buf The buffer containing the data.
+ @param len The number of bytes to include in the computation.
+ @return The CRC16 CCITT checksum. */
+extern guint16 crc16_ccitt(const guint8 *buf, guint len);
+
+/** Compute CRC16 CCITT checksum of a buffer of data. If computing the
+ * checksum over multiple buffers and you want to feed the partial CRC16
+ * back in, remember to take the 1's complement of the partial CRC16 first.
+ @param buf The buffer containing the data.
+ @param len The number of bytes to include in the computation.
+ @param seed The seed to use.
+ @return The CRC16 CCITT checksum (using the given seed). */
+extern guint16 crc16_ccitt_seed(const guint8 *buf, guint len, guint16 seed);
+
+/** Compute CRC16 CCITT checksum of a tv buffer.
+ @param tvb The tv buffer containing the data.
+ @param len The number of bytes to include in the computation.
+ @return The CRC16 CCITT checksum. */
+extern guint16 crc16_ccitt_tvb(tvbuff_t *tvb, guint len);
+
+/** Compute CRC16 CCITT checksum of a tv buffer.
+ @param tvb The tv buffer containing the data.
+ @param offset The offset into the tv buffer.
+ @param len The number of bytes to include in the computation.
+ @return The CRC16 CCITT checksum. */
+extern guint16 crc16_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len);
+
+/** Compute CRC16 CCITT checksum of a tv buffer. If computing the
+ * checksum over multiple tv buffers and you want to feed the partial CRC16
+ * back in, remember to take the 1's complement of the partial CRC16 first.
+ @param tvb The tv buffer containing the data.
+ @param len The number of bytes to include in the computation.
+ @param seed The seed to use.
+ @return The CRC16 CCITT checksum (using the given seed). */
+extern guint16 crc16_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint16 seed);
+
+/** Compute CRC16 CCITT checksum of a tv buffer. If computing the
+ * checksum over multiple tv buffers and you want to feed the partial CRC16
+ * back in, remember to take the 1's complement of the partial CRC16 first.
+ @param tvb The tv buffer containing the data.
+ @param offset The offset into the tv buffer.
+ @param len The number of bytes to include in the computation.
+ @param seed The seed to use.
+ @return The CRC16 CCITT checksum (using the given seed). */
+extern guint16 crc16_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset,
+ guint len, guint16 seed);
+
+
diff --git a/epan/crc32.c b/epan/crc32.c
new file mode 100644
index 0000000000..18362d7ca9
--- /dev/null
+++ b/epan/crc32.c
@@ -0,0 +1,174 @@
+/* crc32.c
+ * CRC-32 routine
+ *
+ * $Id$
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * Copied from README.developer
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Credits:
+ *
+ * Table from Solomon Peachy
+ * Routine from Chris Waters
+ */
+
+#include <glib.h>
+#include <epan/tvbuff.h>
+#include <epan/crc32.h>
+
+/*
+ * Table for the AUTODIN/HDLC/802.x CRC.
+ *
+ * Polynomial is
+ *
+ * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^8 + x^7 +
+ * x^5 + x^4 + x^2 + x + 1
+ */
+const guint32 crc32_ccitt_table[256] = {
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
+ 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
+ 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
+ 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
+ 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
+ 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+ 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
+ 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
+ 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
+ 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
+ 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
+ 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
+ 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
+ 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
+ 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
+ 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
+ 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+ 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
+ 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
+ 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
+ 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
+ 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
+ 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
+ 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
+ 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
+ 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
+ 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
+ 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+ 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
+ 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
+ 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
+ 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
+ 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
+ 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
+ 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
+ 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
+ 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
+ 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
+ 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+ 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
+ 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
+ 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
+ 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
+ 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
+ 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
+ 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
+ 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
+ 0x2d02ef8d
+};
+
+#define CRC32_CCITT_SEED 0xFFFFFFFF
+
+guint32
+crc32_ccitt(const guint8 *buf, guint len)
+{
+ return ( crc32_ccitt_seed(buf, len, CRC32_CCITT_SEED) );
+}
+
+guint32
+crc32_ccitt_seed(const guint8 *buf, guint len, guint32 seed)
+{
+ guint i;
+ guint32 crc32 = seed;
+
+ for (i = 0; i < len; i++)
+ crc32 = crc32_ccitt_table[(crc32 ^ buf[i]) & 0xff] ^ (crc32 >> 8);
+
+ return ( ~crc32 );
+}
+
+guint32
+crc32_ccitt_tvb(tvbuff_t *tvb, guint len)
+{
+ const guint8* buf = tvb_get_ptr(tvb, 0, len);
+
+ return ( crc32_ccitt_seed(buf, len, CRC32_CCITT_SEED) );
+}
+
+guint32
+crc32_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
+{
+ const guint8* buf = tvb_get_ptr(tvb, offset, len);
+
+ return ( crc32_ccitt(buf, len) );
+}
+
+guint32
+crc32_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint32 seed)
+{
+ const guint8* buf = tvb_get_ptr(tvb, 0, len);
+
+ return ( crc32_ccitt_seed(buf, len, seed) );
+}
+
+guint32
+crc32_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint32 seed)
+{
+ const guint8* buf = tvb_get_ptr(tvb, offset, len);
+
+ return ( crc32_ccitt_seed(buf, len, seed) );
+}
+
+/*
+ * IEEE 802.x version (Ethernet and 802.11, at least) - byte-swap
+ * the result of "crc32()".
+ *
+ * XXX - does this mean we should fetch the Ethernet and 802.11
+ * FCS with "tvb_get_letohl()" rather than "tvb_get_ntohl()",
+ * or is fetching it big-endian and byte-swapping the CRC done
+ * to cope with 802.x sending stuff out in reverse bit order?
+ */
+guint32
+crc32_802_tvb(tvbuff_t *tvb, guint len)
+{
+ guint32 c_crc;
+
+ c_crc = crc32_ccitt_tvb(tvb, len);
+
+ /* Byte reverse. */
+ c_crc = ((unsigned char)(c_crc>>0)<<24) |
+ ((unsigned char)(c_crc>>8)<<16) |
+ ((unsigned char)(c_crc>>16)<<8) |
+ ((unsigned char)(c_crc>>24)<<0);
+
+ return ( c_crc );
+}
diff --git a/epan/crc32.h b/epan/crc32.h
new file mode 100644
index 0000000000..291302c06e
--- /dev/null
+++ b/epan/crc32.h
@@ -0,0 +1,82 @@
+/* crc32.h
+ * Declaration of CRC-32 routine and table
+ *
+ * $Id$
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * Copied from README.developer
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+extern const guint32 crc32_ccitt_table[256];
+
+/** Compute CRC32 CCITT checksum of a buffer of data.
+ @param buf The buffer containing the data.
+ @param len The number of bytes to include in the computation.
+ @return The CRC32 CCITT checksum. */
+extern guint32 crc32_ccitt(const guint8 *buf, guint len);
+
+/** Compute CRC32 CCITT checksum of a buffer of data. If computing the
+ * checksum over multiple buffers and you want to feed the partial CRC32
+ * back in, remember to take the 1's complement of the partial CRC32 first.
+ @param buf The buffer containing the data.
+ @param len The number of bytes to include in the computation.
+ @param seed The seed to use.
+ @return The CRC32 CCITT checksum (using the given seed). */
+extern guint32 crc32_ccitt_seed(const guint8 *buf, guint len, guint32 seed);
+
+/** Compute CRC32 CCITT checksum of a tv buffer.
+ @param tvb The tv buffer containing the data.
+ @param len The number of bytes to include in the computation.
+ @return The CRC32 CCITT checksum. */
+extern guint32 crc32_ccitt_tvb(tvbuff_t *tvb, guint len);
+
+/** Compute CRC32 CCITT checksum of a tv buffer.
+ @param tvb The tv buffer containing the data.
+ @param offset The offset into the tv buffer.
+ @param len The number of bytes to include in the computation.
+ @return The CRC32 CCITT checksum. */
+extern guint32 crc32_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len);
+
+/** Compute CRC32 CCITT checksum of a tv buffer. If computing the
+ * checksum over multiple tv buffers and you want to feed the partial CRC32
+ * back in, remember to take the 1's complement of the partial CRC32 first.
+ @param tvb The tv buffer containing the data.
+ @param len The number of bytes to include in the computation.
+ @param seed The seed to use.
+ @return The CRC32 CCITT checksum (using the given seed). */
+extern guint32 crc32_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint32 seed);
+
+/** Compute CRC32 CCITT checksum of a tv buffer. If computing the
+ * checksum over multiple tv buffers and you want to feed the partial CRC32
+ * back in, remember to take the 1's complement of the partial CRC32 first.
+ @param tvb The tv buffer containing the data.
+ @param offset The offset into the tv buffer.
+ @param len The number of bytes to include in the computation.
+ @param seed The seed to use.
+ @return The CRC32 CCITT checksum (using the given seed). */
+extern guint32 crc32_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset,
+ guint len, guint32 seed);
+
+/** Compute IEEE 802.x CRC32 checksum of a tv buffer.
+ @param tvb The tv buffer containing the data.
+ @param len The number of bytes to include in the computation.
+ @return The IEEE 802.x CRC32 checksum. */
+extern guint32 crc32_802_tvb(tvbuff_t *tvb, guint len);
+
diff --git a/epan/dissectors/packet-eth.c b/epan/dissectors/packet-eth.c
index c8e1d5839a..8147c7ea12 100644
--- a/epan/dissectors/packet-eth.c
+++ b/epan/dissectors/packet-eth.c
@@ -36,7 +36,7 @@
#include "packet-ipx.h"
#include "packet-isl.h"
#include "packet-llc.h"
-#include "crc32.h"
+#include <epan/crc32.h>
#include "tap.h"
/* Interpret capture file as FW1 monitor file */
diff --git a/epan/dissectors/packet-gre.c b/epan/dissectors/packet-gre.c
index 6ed41b9f99..f1c090325f 100644
--- a/epan/dissectors/packet-gre.c
+++ b/epan/dissectors/packet-gre.c
@@ -30,7 +30,7 @@
#include <glib.h>
#include <epan/packet.h>
#include "packet-wccp.h"
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
#include "etypes.h"
#include "greproto.h"
#include "ipproto.h"
diff --git a/epan/dissectors/packet-icmpv6.c b/epan/dissectors/packet-icmpv6.c
index dece17b436..fd8675b593 100644
--- a/epan/dissectors/packet-icmpv6.c
+++ b/epan/dissectors/packet-icmpv6.c
@@ -48,7 +48,7 @@
#include <epan/packet.h>
#include "packet-ipv6.h"
#include "packet-dns.h"
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
#include <epan/addr_resolv.h>
#include "ipproto.h"
diff --git a/epan/dissectors/packet-ieee80211.c b/epan/dissectors/packet-ieee80211.c
index edfd8edfef..a42ca3e8dc 100644
--- a/epan/dissectors/packet-ieee80211.c
+++ b/epan/dissectors/packet-ieee80211.c
@@ -67,7 +67,7 @@
#include "packet-llc.h"
#include "packet-ieee80211.h"
#include "etypes.h"
-#include "crc32.h"
+#include <epan/crc32.h>
/* Defragment fragmented 802.11 datagrams */
static gboolean wlan_defragment = TRUE;
diff --git a/epan/dissectors/packet-igmp.c b/epan/dissectors/packet-igmp.c
index 11aaad97a1..fcec8a7569 100644
--- a/epan/dissectors/packet-igmp.c
+++ b/epan/dissectors/packet-igmp.c
@@ -109,7 +109,7 @@
#include <epan/packet.h>
#include "ipproto.h"
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
#include "packet-dvmrp.h"
#include "packet-pim.h"
#include "packet-mrdisc.h"
diff --git a/epan/dissectors/packet-ip.c b/epan/dissectors/packet-ip.c
index 0bdef0c3c8..9cb368abed 100644
--- a/epan/dissectors/packet-ip.c
+++ b/epan/dissectors/packet-ip.c
@@ -48,7 +48,7 @@
#include "arcnet_pids.h"
#include "packet-ip.h"
#include "packet-ipsec.h"
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
#include "nlpid.h"
#include "tap.h"
diff --git a/epan/dissectors/packet-ipvs-syncd.c b/epan/dissectors/packet-ipvs-syncd.c
index 928dcba807..97f7abe324 100644
--- a/epan/dissectors/packet-ipvs-syncd.c
+++ b/epan/dissectors/packet-ipvs-syncd.c
@@ -36,7 +36,7 @@
#include <epan/packet.h>
#include "ipproto.h"
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
static int proto_ipvs_syncd = -1;
static int hf_conn_count = -1;
diff --git a/epan/dissectors/packet-lmp.c b/epan/dissectors/packet-lmp.c
index 5d019a3f0d..4cc7902993 100644
--- a/epan/dissectors/packet-lmp.c
+++ b/epan/dissectors/packet-lmp.c
@@ -51,7 +51,7 @@
#include <epan/tvbuff.h>
#include <epan/packet.h>
#include <prefs.h>
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
#include "etypes.h"
#include "ipproto.h"
diff --git a/epan/dissectors/packet-ospf.c b/epan/dissectors/packet-ospf.c
index c9d9844bda..3cb24f068c 100644
--- a/epan/dissectors/packet-ospf.c
+++ b/epan/dissectors/packet-ospf.c
@@ -45,7 +45,7 @@
#include <glib.h>
#include <epan/packet.h>
#include "ipproto.h"
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
#include "packet-rsvp.h"
#define OSPF_VERSION_2 2
diff --git a/epan/dissectors/packet-pgm.c b/epan/dissectors/packet-pgm.c
index d37f1c6b2a..1e49807ab8 100644
--- a/epan/dissectors/packet-pgm.c
+++ b/epan/dissectors/packet-pgm.c
@@ -36,7 +36,7 @@
#include <epan/packet.h>
#include "afn.h"
#include "ipproto.h"
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
#include <epan/addr_resolv.h>
#include <epan/strutil.h>
#include <epan/prefs.h>
diff --git a/epan/dissectors/packet-pim.c b/epan/dissectors/packet-pim.c
index 485bb0ee33..124e2ab346 100644
--- a/epan/dissectors/packet-pim.c
+++ b/epan/dissectors/packet-pim.c
@@ -39,7 +39,7 @@
#include "ipproto.h"
#include "afn.h"
#include "packet-ipv6.h"
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
#define PIM_TYPE(x) ((x) & 0x0f)
#define PIM_VER(x) (((x) & 0xf0) >> 4)
diff --git a/epan/dissectors/packet-ppp.c b/epan/dissectors/packet-ppp.c
index 8216c9f9ab..e77f724b9d 100644
--- a/epan/dissectors/packet-ppp.c
+++ b/epan/dissectors/packet-ppp.c
@@ -43,8 +43,8 @@
#include "packet-ipx.h"
#include "packet-vines.h"
#include "nlpid.h"
-#include "crc16.h"
-#include "crc32.h"
+#include <epan/crc16.h>
+#include <epan/crc32.h>
#define ppp_min(a, b) ((a<b) ? a : b)
diff --git a/epan/dissectors/packet-rsvp.c b/epan/dissectors/packet-rsvp.c
index b665df03d6..3e213fe802 100644
--- a/epan/dissectors/packet-rsvp.c
+++ b/epan/dissectors/packet-rsvp.c
@@ -69,7 +69,7 @@
#include <epan/tvbuff.h>
#include <epan/packet.h>
#include <prefs.h>
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
#include "etypes.h"
#include "ipproto.h"
diff --git a/epan/dissectors/packet-tcp.c b/epan/dissectors/packet-tcp.c
index 4dbd0a1e41..3a229b40b1 100644
--- a/epan/dissectors/packet-tcp.c
+++ b/epan/dissectors/packet-tcp.c
@@ -29,7 +29,7 @@
#include <stdio.h>
#include <string.h>
#include <glib.h>
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
#include <epan/packet.h>
#include <epan/addr_resolv.h>
diff --git a/epan/dissectors/packet-udp.c b/epan/dissectors/packet-udp.c
index b2a0cfe565..209048fdd7 100644
--- a/epan/dissectors/packet-udp.c
+++ b/epan/dissectors/packet-udp.c
@@ -37,7 +37,7 @@
#include <epan/packet.h>
#include <epan/addr_resolv.h>
#include "ipproto.h"
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
#include <epan/prefs.h>
#include "packet-udp.h"
diff --git a/epan/dissectors/packet-vj.c b/epan/dissectors/packet-vj.c
index 309d53726f..6329b8a48a 100644
--- a/epan/dissectors/packet-vj.c
+++ b/epan/dissectors/packet-vj.c
@@ -70,7 +70,7 @@
#include "packet-ppp.h"
#include "ppptypes.h"
#include "ipproto.h"
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
/* Define relevant IP/TCP parameters */
#define IP_FIELD_TOT_LEN 2 /* Total length field in IP hdr */
diff --git a/epan/dissectors/packet-vrrp.c b/epan/dissectors/packet-vrrp.c
index e85c1c8cc4..a470f77815 100644
--- a/epan/dissectors/packet-vrrp.c
+++ b/epan/dissectors/packet-vrrp.c
@@ -33,7 +33,7 @@
#include <glib.h>
#include <epan/packet.h>
#include "ipproto.h"
-#include "in_cksum.h"
+#include <epan/in_cksum.h>
static gint proto_vrrp = -1;
static gint ett_vrrp = -1;
diff --git a/epan/in_cksum.c b/epan/in_cksum.c
new file mode 100644
index 0000000000..1170f9230a
--- /dev/null
+++ b/epan/in_cksum.c
@@ -0,0 +1,201 @@
+/* in_cksum.c
+ * 4.4-Lite-2 Internet checksum routine, modified to take a vector of
+ * pointers/lengths giving the pieces to be checksummed.
+ *
+ * $Id$
+ */
+
+/*
+ * Copyright (c) 1988, 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in_cksum.c 8.1 (Berkeley) 6/10/93
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <glib.h>
+
+#include <epan/in_cksum.h>
+
+/*
+ * Checksum routine for Internet Protocol family headers (Portable Version).
+ *
+ * This routine is very heavily used in the network
+ * code and should be modified for each CPU to be as fast as possible.
+ */
+
+#define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
+#define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);}
+
+int
+in_cksum(const vec_t *vec, int veclen)
+{
+ register const guint16 *w;
+ register int sum = 0;
+ register int mlen = 0;
+ int byte_swapped = 0;
+
+ union {
+ guint8 c[2];
+ guint16 s;
+ } s_util;
+ union {
+ guint16 s[2];
+ guint32 l;
+ } l_util;
+
+ for (; veclen != 0; vec++, veclen--) {
+ if (vec->len == 0)
+ continue;
+ w = (const guint16 *)vec->ptr;
+ if (mlen == -1) {
+ /*
+ * The first byte of this chunk is the continuation
+ * of a word spanning between this chunk and the
+ * last chunk.
+ *
+ * s_util.c[0] is already saved when scanning previous
+ * chunk.
+ */
+ s_util.c[1] = *(const guint8 *)w;
+ sum += s_util.s;
+ w = (const guint16 *)((const guint8 *)w + 1);
+ mlen = vec->len - 1;
+ } else
+ mlen = vec->len;
+ /*
+ * Force to even boundary.
+ */
+ if ((1 & (unsigned long) w) && (mlen > 0)) {
+ REDUCE;
+ sum <<= 8;
+ s_util.c[0] = *(const guint8 *)w;
+ w = (const guint16 *)((const guint8 *)w + 1);
+ mlen--;
+ byte_swapped = 1;
+ }
+ /*
+ * Unroll the loop to make overhead from
+ * branches &c small.
+ */
+ while ((mlen -= 32) >= 0) {
+ sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];
+ sum += w[4]; sum += w[5]; sum += w[6]; sum += w[7];
+ sum += w[8]; sum += w[9]; sum += w[10]; sum += w[11];
+ sum += w[12]; sum += w[13]; sum += w[14]; sum += w[15];
+ w += 16;
+ }
+ mlen += 32;
+ while ((mlen -= 8) >= 0) {
+ sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];
+ w += 4;
+ }
+ mlen += 8;
+ if (mlen == 0 && byte_swapped == 0)
+ continue;
+ REDUCE;
+ while ((mlen -= 2) >= 0) {
+ sum += *w++;
+ }
+ if (byte_swapped) {
+ REDUCE;
+ sum <<= 8;
+ byte_swapped = 0;
+ if (mlen == -1) {
+ s_util.c[1] = *(const guint8 *)w;
+ sum += s_util.s;
+ mlen = 0;
+ } else
+ mlen = -1;
+ } else if (mlen == -1)
+ s_util.c[0] = *(const guint8 *)w;
+ }
+ if (mlen == -1) {
+ /* The last mbuf has odd # of bytes. Follow the
+ standard (the odd byte may be shifted left by 8 bits
+ or not as determined by endian-ness of the machine) */
+ s_util.c[1] = 0;
+ sum += s_util.s;
+ }
+ REDUCE;
+ return (~sum & 0xffff);
+}
+
+/*
+ * Given the host-byte-order value of the checksum field in a packet
+ * header, and the network-byte-order computed checksum of the data
+ * that the checksum covers (including the checksum itself), compute
+ * what the checksum field *should* have been.
+ */
+guint16
+in_cksum_shouldbe(guint16 sum, guint16 computed_sum)
+{
+ guint32 shouldbe;
+
+ /*
+ * The value that should have gone into the checksum field
+ * is the negative of the value gotten by summing up everything
+ * *but* the checksum field.
+ *
+ * We can compute that by subtracting the value of the checksum
+ * field from the sum of all the data in the packet, and then
+ * computing the negative of that value.
+ *
+ * "sum" is the value of the checksum field, and "computed_sum"
+ * is the negative of the sum of all the data in the packets,
+ * so that's -(-computed_sum - sum), or (sum + computed_sum).
+ *
+ * All the arithmetic in question is one's complement, so the
+ * addition must include an end-around carry; we do this by
+ * doing the arithmetic in 32 bits (with no sign-extension),
+ * and then adding the upper 16 bits of the sum, which contain
+ * the carry, to the lower 16 bits of the sum, and then do it
+ * again in case *that* sum produced a carry.
+ *
+ * As RFC 1071 notes, the checksum can be computed without
+ * byte-swapping the 16-bit words; summing 16-bit words
+ * on a big-endian machine gives a big-endian checksum, which
+ * can be directly stuffed into the big-endian checksum fields
+ * in protocol headers, and summing words on a little-endian
+ * machine gives a little-endian checksum, which must be
+ * byte-swapped before being stuffed into a big-endian checksum
+ * field.
+ *
+ * "computed_sum" is a network-byte-order value, so we must put
+ * it in host byte order before subtracting it from the
+ * host-byte-order value from the header; the adjusted checksum
+ * will be in host byte order, which is what we'll return.
+ */
+ shouldbe = sum;
+ shouldbe += g_ntohs(computed_sum);
+ shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16);
+ shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16);
+ return shouldbe;
+}
diff --git a/epan/in_cksum.h b/epan/in_cksum.h
new file mode 100644
index 0000000000..53b274976f
--- /dev/null
+++ b/epan/in_cksum.h
@@ -0,0 +1,14 @@
+/* in_cksum.h
+ * Declaration of Internet checksum routine.
+ *
+ * $Id$
+ */
+
+typedef struct {
+ const guint8 *ptr;
+ int len;
+} vec_t;
+
+extern int in_cksum(const vec_t *vec, int veclen);
+
+extern guint16 in_cksum_shouldbe(guint16 sum, guint16 computed_sum);
diff --git a/epan/plugins.c b/epan/plugins.c
index b60eba9ff7..aaf852dfeb 100644
--- a/epan/plugins.c
+++ b/epan/plugins.c
@@ -73,7 +73,7 @@
#include <epan/dissectors/packet-rtp.h>
#include <epan/dissectors/packet-rtcp.h>
#include "xdlc.h"
-#include "crc16.h"
+#include <epan/crc16.h>
#include "report_err.h"
#include "plugins/plugin_table.h"
static plugin_address_table_t patable = {