diff options
60 files changed, 493 insertions, 425 deletions
diff --git a/configure.in b/configure.in index aa2bae3883..417e120670 100644 --- a/configure.in +++ b/configure.in @@ -1988,7 +1988,6 @@ AC_OUTPUT( doc/Makefile docbook/Makefile epan/Makefile - epan/crc/Makefile epan/crypt/Makefile epan/doxygen.cfg epan/dfilter/Makefile diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index bbcad3ab23..86b78341f0 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -39,10 +39,6 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/wspython ) -set(CRC_FILES - crc/crc-16-plain.c -) - set(CRYPT_FILES crypt/airpdcap.c crypt/airpdcap_ccmp.c @@ -1209,12 +1205,9 @@ set(LIBWIRESHARK_FILES column.c column-utils.c conversation.c - crc10.c - crc16.c - crc32.c - crc6.c - crc8.c - crcdrm.c + crc16-tvb.c + crc32-tvb.c + crc8-tvb.c dissector_filters.c emem.c epan.c @@ -1310,7 +1303,6 @@ set(CLEAN_FILES #x11-declarations.h #x11-register-info.h ${LIBWIRESHARK_CLEAN_FILES} - ${CRC_FILES} ${CRYPT_FILES} ${DFILTER_CLEAN_FILES} ${FTYPE_FILES} @@ -1339,7 +1331,6 @@ add_library(epan ${LINK_MODE_LIB} #x11-declarations.h #x11-register-info.h ${LIBWIRESHARK_FILES} - ${CRC_FILES} ${CRYPT_FILES} ${DFILTER_FILES} ${FTYPE_FILES} diff --git a/epan/Makefile.am b/epan/Makefile.am index a0a224b64e..d624c49c01 100644 --- a/epan/Makefile.am +++ b/epan/Makefile.am @@ -46,7 +46,7 @@ wspython_dist_dir = wspython py_dissectors_dir = -DPYTHONDIR= endif -SUBDIRS = crc crypt ftypes dfilter dissectors $(wslua_dir) $(wspython_dir) +SUBDIRS = crypt ftypes dfilter dissectors $(wslua_dir) $(wspython_dir) DIST_SUBDIRS = $(SUBDIRS) $(wslua_dist_dir) $(wspython_dist_dir) @@ -133,7 +133,7 @@ MAINTAINERCLEANFILES = \ # libwireshark_la_LIBADD = \ libwireshark_generated.la \ - libwireshark_asmopt.la crc/libcrc.la crypt/libairpdcap.la \ + libwireshark_asmopt.la crypt/libairpdcap.la \ ftypes/libftypes.la dfilter/libdfilter.la dissectors/libdissectors.la \ dissectors/libdirtydissectors.la $(wslua_lib) $(wspython_lib) @SOCKET_LIBS@ @NSL_LIBS@ \ @C_ARES_LIBS@ @ADNS_LIBS@ @LIBGCRYPT_LIBS@ @LIBGNUTLS_LIBS@ \ @@ -143,7 +143,7 @@ libwireshark_la_LIBADD = \ libwireshark_la_DEPENDENCIES = \ libwireshark_generated.la \ - libwireshark_asmopt.la crc/libcrc.la crypt/libairpdcap.la \ + libwireshark_asmopt.la crypt/libairpdcap.la \ ftypes/libftypes.la dfilter/libdfilter.la dissectors/libdissectors.la \ dissectors/libdirtydissectors.la $(wslua_lib) $(wspython_lib) \ ${top_builddir}/wsutil/libwsutil.la \ diff --git a/epan/Makefile.common b/epan/Makefile.common index 63c35ad076..9ef81117ba 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -40,12 +40,9 @@ LIBWIRESHARK_SRC = \ column.c \ column-utils.c \ conversation.c \ - crc10.c \ - crc16.c \ - crc32.c \ - crc6.c \ - crc8.c \ - crcdrm.c \ + crc16-tvb.c \ + crc32-tvb.c \ + crc8-tvb.c \ dissector_filters.c \ emem.c \ epan.c \ @@ -150,12 +147,9 @@ LIBWIRESHARK_INCLUDES = \ column_info.h \ column-utils.h \ conversation.h \ - crc6.h \ - crc8.h \ - crc10.h \ - crc16.h \ - crc32.h \ - crcdrm.h \ + crc16-tvb.h \ + crc32-tvb.h \ + crc8-tvb.h \ diam_dict.h \ dissector_filters.h \ dtd.h \ diff --git a/epan/Makefile.nmake b/epan/Makefile.nmake index 4efc7924cc..8d9cf96324 100644 --- a/epan/Makefile.nmake +++ b/epan/Makefile.nmake @@ -52,7 +52,6 @@ libwireshark_LIBS = \ $(GEOIP_LIBS) \ ..\wsutil\libwsutil.lib \ ..\wiretap\wiretap-$(WTAP_VERSION).lib \ - crc\crc.lib \ crypt\airpdcap.lib \ ftypes\ftypes.lib \ dfilter\dfilter.lib \ @@ -77,17 +76,17 @@ DOXYGEN_DEP=doxygen !ENDIF !IFDEF ENABLE_LIBWIRESHARK -all: crc crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors libwireshark.dll +all: crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors libwireshark.dll !ELSE -all: crc crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors libwireshark.lib +all: crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors libwireshark.lib !ENDIF # For use when making libwireshark.dll libwireshark.lib: libwireshark.dll libwireshark.exp: libwireshark.dll -libwireshark.dll: ..\config.h $(LIBWIRESHARK_OBJECTS) libwireshark.def crc crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \ - crc\crc.lib crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib dissectors\dissectors.lib $(WSLUA_LIB) $(WSPYTHON_LIB) ..\image\libwireshark.res +libwireshark.dll: ..\config.h $(LIBWIRESHARK_OBJECTS) libwireshark.def crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \ + crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib dissectors\dissectors.lib $(WSLUA_LIB) $(WSPYTHON_LIB) ..\image\libwireshark.res @echo Linking libwireshark.dll $(link) $(dlllflags) $(conlibsdll) shell32.lib \ $(LOCAL_LDFLAGS) $(DLL_LDFLAGS) \ @@ -97,8 +96,8 @@ libwireshark.dll: ..\config.h $(LIBWIRESHARK_OBJECTS) libwireshark.def crc crypt dissectors\register.obj \ $(EXTRA_OBJECTS) -libwireshark.lib : ..\config.h $(LIBWIRESHARK_OBJECTS) crc crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \ - crc\crc.lib crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib $(WSLUA_LIB) $(WSPYTHON_LIB) dissectors\dissectors.lib +libwireshark.lib : ..\config.h $(LIBWIRESHARK_OBJECTS) crypt ftypes dfilter $(WSLUA_DIR) $(WSPYTHON_DIR) dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \ + crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib $(WSLUA_LIB) $(WSPYTHON_LIB) dissectors\dissectors.lib link /lib /out:libwireshark.lib $(LIBWIRESHARK_OBJECTS) \ $(EXTRA_OBJECTS) @@ -115,8 +114,6 @@ clean-local: if exist html rm -rf html clean: clean-local - cd crc - $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean cd ../crypt $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean cd ../ftypes @@ -149,8 +146,6 @@ distclean-local: clean-local dtd_grammar.out sminmpec.c distclean: distclean-local - cd crc - $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean cd ../crypt $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean cd ../ftypes @@ -168,8 +163,6 @@ distclean: distclean-local maintainer-clean-local: distclean-local maintainer-clean: maintainer-clean-local - cd crc - $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean cd ../crypt $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean cd ../ftypes @@ -184,11 +177,6 @@ maintainer-clean: maintainer-clean-local $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean cd .. -crc:: ..\config.h - cd crc - $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake - cd .. - crypt:: ..\config.h cd crypt $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake diff --git a/epan/crc/Makefile.am b/epan/crc/Makefile.am deleted file mode 100644 index 28ad880193..0000000000 --- a/epan/crc/Makefile.am +++ /dev/null @@ -1,54 +0,0 @@ -# Makefile.am -# Automake file for crc routines for Wireshark -# -# $Id$ -# -# Wireshark - Network traffic analyzer -# By Gerald Combs <gerald@wireshark.org> -# 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. - -INCLUDES = -I$(top_srcdir) - -include Makefile.common - -if HAVE_WARNINGS_AS_ERRORS -AM_CFLAGS = -Werror -endif - -noinst_LTLIBRARIES = libcrc.la - -CLEANFILES = \ - libcrc.a \ - libcrc.la \ - *~ - -DISTCLEANFILES = - -MAINTAINERCLEANFILES = \ - Makefile.in - -libcrc_la_SOURCES = \ - $(CRC_SRC) \ - $(CRC_INCLUDES) - -EXTRA_DIST = \ - Makefile.common \ - Makefile.nmake - -checkapi: - $(PERL) ../../tools/checkAPIs.pl -g termoutput \ - $(CRC_SRC) diff --git a/epan/crc/Makefile.common b/epan/crc/Makefile.common deleted file mode 100644 index 7aa9cb7512..0000000000 --- a/epan/crc/Makefile.common +++ /dev/null @@ -1,33 +0,0 @@ -# Makefile.common -# Contains the stuff from Makefile.am and Makefile.nmake that is -# a) common to both files and -# b) portable between both files -# -# $Id$ -# -# Wireshark - Network traffic analyzer -# By Gerald Combs <gerald@wireshark.org> -# 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. - -# crc-16-plain.c: pycrc.py --model crc-16 --algorithm table-driven --symbol-prefix crc16_plain_ --crc-type guint16 --include-file glib.h --generate c -o crc-16-plain.c -# crc-16-plain.h: pycrc.py --model crc-16 --algorithm table-driven --symbol-prefix crc16_plain_ --crc-type guint16 --include-file glib.h --generate h -o crc-16-plain.h - -CRC_SRC = \ - crc-16-plain.c - -CRC_INCLUDES = \ - crc-16-plain.h diff --git a/epan/crc/Makefile.nmake b/epan/crc/Makefile.nmake deleted file mode 100644 index 9b336d8040..0000000000 --- a/epan/crc/Makefile.nmake +++ /dev/null @@ -1,31 +0,0 @@ -## Makefile for building crc.lib with Microsoft C and nmake -## Use: $(MAKE) /$(MAKEFLAGS) -f makefile.nmake -# -# $Id$ - -include ..\..\config.nmake -include Makefile.common - -############### no need to modify below this line ######### - -CFLAGS=$(WARNINGS_ARE_ERRORS) $(STANDARD_CFLAGS) \ - /I../.. $(GLIB_CFLAGS) - -.c.obj:: - $(CC) $(CFLAGS) -Fd.\ -c $< - -CRC_OBJECTS = $(CRC_SRC:.c=.obj) - -crc.lib: $(CRC_OBJECTS) - link /lib /out:crc.lib $(CRC_OBJECTS) - -clean: - rm -f $(CRC_OBJECTS) crc.lib *.pdb - -distclean: clean - -maintainer-clean: distclean - -checkapi: - $(PERL) ../../tools/checkAPIs.pl -g termoutput \ - $(CRC_SRC) diff --git a/epan/crc16-tvb.c b/epan/crc16-tvb.c new file mode 100644 index 0000000000..d0271626f7 --- /dev/null +++ b/epan/crc16-tvb.c @@ -0,0 +1,106 @@ +/* crc16-tvb.c + * CRC-16 tvb routines + * + * 2004 Richard van der Hoff <richardv@mxtelecom.com> + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * 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. + * + * 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 + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <glib.h> +#include <epan/tvbuff.h> +#include <wsutil/crc16.h> +#include <wsutil/crc16-plain.h> + + +guint16 crc16_ccitt_tvb(tvbuff_t *tvb, guint len) +{ + const guint8 *buf; + + tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */ + buf = tvb_get_ptr(tvb, 0, len); + + return crc16_ccitt(buf, len); +} + +guint16 crc16_x25_ccitt_tvb(tvbuff_t *tvb, guint len) +{ + const guint8 *buf; + + tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */ + buf = tvb_get_ptr(tvb, 0, len); + + return crc16_x25_ccitt(buf, len); +} + +guint16 crc16_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len) +{ + const guint8 *buf; + + tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */ + 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_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */ + 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_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */ + buf = tvb_get_ptr(tvb, offset, len); + + return crc16_ccitt_seed(buf, len, seed); +} + +guint16 crc16_plain_tvb_offset(tvbuff_t *tvb, guint offset, guint len) +{ + guint16 crc = crc16_plain_init(); + const guint8 *buf; + + tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */ + buf = tvb_get_ptr(tvb, offset, len); + + crc = crc16_plain_update(crc, buf, len); + + return crc16_plain_finalize(crc); +} + diff --git a/epan/crc16.h b/epan/crc16-tvb.h index 0fb0548dc4..504bcd31a9 100644 --- a/epan/crc16.h +++ b/epan/crc16-tvb.h @@ -1,16 +1,14 @@ -/* crc16.h - * Declaration of CRC-16 routines and table +/* crc16-tvb.h + * Declaration of CRC-16 tvbuff routines * * 2004 Richard van der Hoff <richardv@mxtelecom.com> * * $Id$ * * Wireshark - Network traffic analyzer - * By Gerald Combs <gerald@xxxxxxxxxxxx> + * By Gerald Combs <gerald@wireshark.org> * 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 @@ -26,43 +24,13 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __CRC16_H_ -#define __CRC16_H_ +#ifndef __CRC16_TVB_H__ +#define __CRC16_TVB_H__ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -/* 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 X.25 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 X.25 CCITT checksum. */ -extern guint16 crc16_x25_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. @@ -123,4 +91,4 @@ extern guint16 crc16_plain_tvb_offset(tvbuff_t *tvb, guint offset, guint len); } #endif /* __cplusplus */ -#endif /* crc16.h */ +#endif /* crc16-tvb.h */ diff --git a/epan/crc32-tvb.c b/epan/crc32-tvb.c new file mode 100644 index 0000000000..91cd7c13f2 --- /dev/null +++ b/epan/crc32-tvb.c @@ -0,0 +1,107 @@ +/* crc32-tvb.c + * CRC-32 tvbuff routines + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * 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. + * + * Credits: + * + * Table from Solomon Peachy + * Routine from Chris Waters + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <glib.h> +#include <epan/tvbuff.h> +#include <wsutil/crc32.h> + + +guint32 +crc32_ccitt_tvb(tvbuff_t *tvb, guint len) +{ + const guint8* buf; + + tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */ + 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_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */ + 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_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */ + 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_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */ + 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-tvb.h index 7bc63bdde4..400920ee18 100644 --- a/epan/crc32.h +++ b/epan/crc32-tvb.h @@ -1,5 +1,5 @@ -/* crc32.h - * Declaration of CRC-32 routine and table +/* crc32-tvb.h + * Declaration of CRC-32 tvbuff routines * * $Id$ * @@ -7,8 +7,6 @@ * By Gerald Combs <gerald@wireshark.org> * 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 @@ -24,52 +22,13 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __CRC32_H_ -#define __CRC32_H_ +#ifndef __CRC32_TVB_H__ +#define __CRC32_TVB_H__ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -#define CRC32C_PRELOAD 0xffffffff - -/* - * Byte swap fix contributed by Dave Wysochanski <davidw@netapp.com>. - */ -#define CRC32C_SWAP(crc32c_value) \ - (((crc32c_value & 0xff000000) >> 24) | \ - ((crc32c_value & 0x00ff0000) >> 8) | \ - ((crc32c_value & 0x0000ff00) << 8) | \ - ((crc32c_value & 0x000000ff) << 24)) - -#define CRC32C(c,d) (c=(c>>8)^crc32c_table[(c^(d))&0xFF]) - -extern const guint32 crc32c_table[256]; - -/** Compute CRC32C checksum of a buffer of data. - @param buf The buffer containing the data. - @param len The number of bytes to include in the computation. - @param crc The preload value for the CRC32C computation. - @return The CRC32C checksum. */ -extern guint32 crc32c_calculate(const void *buf, int len, guint32 crc); - -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. @@ -113,4 +72,4 @@ extern guint32 crc32_802_tvb(tvbuff_t *tvb, guint len); } #endif /* __cplusplus */ -#endif /* crc32.h */ +#endif /* crc32-tvb.h */ diff --git a/epan/crc8.c b/epan/crc8-tvb.c index 630eda7f6c..f2fc0902b9 100644 --- a/epan/crc8.c +++ b/epan/crc8-tvb.c @@ -33,12 +33,12 @@ */ #ifdef HAVE_CONFIG_H - # include "config.h" +# include "config.h" #endif #include <glib.h> #include <epan/tvbuff.h> -#include <epan/crc8.h> +#include <epan/crc8-tvb.h> /** * Reversed CRC table diff --git a/epan/crc8.h b/epan/crc8-tvb.h index d8268ba9ab..cb4775c17c 100644 --- a/epan/crc8.h +++ b/epan/crc8-tvb.h @@ -41,4 +41,10 @@ * \param received_fcs The received FCS. * \return Returns TRUE if the checksum is correct, FALSE if it is not correct *****************************************************************************/ + +#ifndef __CRC8_TVB_H__ +#define __CRC8_TVB_H__ + extern gboolean check_fcs(tvbuff_t *p, guint8 len, guint8 offset, guint8 received_fcs); + +#endif /* __CRC8_TVB_H__ */ diff --git a/epan/crypt/airpdcap.c b/epan/crypt/airpdcap.c index 740a148c8b..1de4ade2a4 100644 --- a/epan/crypt/airpdcap.c +++ b/epan/crypt/airpdcap.c @@ -41,7 +41,7 @@ #endif #include <epan/tvbuff.h> -#include <epan/crc32.h> +#include <wsutil/crc32.h> #include <epan/strutil.h> #include <epan/emem.h> #include <epan/pint.h> diff --git a/epan/crypt/airpdcap_wep.c b/epan/crypt/airpdcap_wep.c index 45d02df7eb..6007f115ba 100644 --- a/epan/crypt/airpdcap_wep.c +++ b/epan/crypt/airpdcap_wep.c @@ -41,7 +41,7 @@ /* File includes */ #include <epan/tvbuff.h> -#include <epan/crc32.h> +#include <wsutil/crc32.h> #include "airpdcap_system.h" #include "airpdcap_int.h" diff --git a/epan/dissectors/packet-assa_r3.c b/epan/dissectors/packet-assa_r3.c index 0e5d379fa9..4921ef8070 100644 --- a/epan/dissectors/packet-assa_r3.c +++ b/epan/dissectors/packet-assa_r3.c @@ -3213,7 +3213,7 @@ static mfgFieldDissectorParser_t r3upstreammfgfield_dissect [] = /* * *************************************************************************** * - * Cannot use epan/crc routines as ccitt-x25 uses a starting value of 0xffff + * Cannot use wsutil/crc routines as ccitt-x25 uses a starting value of 0xffff * and we use 0x0000 (legacy compatibility). If an override method to set * the starting value existed, these could be replaced. */ diff --git a/epan/dissectors/packet-dcp-etsi.c b/epan/dissectors/packet-dcp-etsi.c index 32cef5d7f5..d60836182b 100644 --- a/epan/dissectors/packet-dcp-etsi.c +++ b/epan/dissectors/packet-dcp-etsi.c @@ -32,7 +32,7 @@ #include <epan/packet.h> #include <epan/reassemble.h> -#include <epan/crcdrm.h> +#include <wsutil/crcdrm.h> #include <epan/reedsolomon.h> #include <epan/emem.h> #include <string.h> diff --git a/epan/dissectors/packet-dmp.c b/epan/dissectors/packet-dmp.c index 44586de447..a7982d4fa6 100644 --- a/epan/dissectors/packet-dmp.c +++ b/epan/dissectors/packet-dmp.c @@ -50,7 +50,7 @@ #include <epan/prefs.h> #include <epan/emem.h> #include <epan/expert.h> -#include <epan/crc16.h> +#include <epan/crc16-tvb.h> #include <epan/asn1.h> #include <epan/strutil.h> #include <epan/uat.h> diff --git a/epan/dissectors/packet-eth.c b/epan/dissectors/packet-eth.c index 6c1c720767..09dfdb9a5e 100644 --- a/epan/dissectors/packet-eth.c +++ b/epan/dissectors/packet-eth.c @@ -38,7 +38,7 @@ #include "packet-llc.h" #include "packet-sll.h" #include "packet-usb.h" -#include <epan/crc32.h> +#include <epan/crc32-tvb.h> #include <epan/tap.h> #include <epan/expert.h> diff --git a/epan/dissectors/packet-fc.c b/epan/dissectors/packet-fc.c index 7aecad064d..b10cbd0d8c 100644 --- a/epan/dissectors/packet-fc.c +++ b/epan/dissectors/packet-fc.c @@ -53,7 +53,7 @@ #include "packet-fcbls.h" #include <epan/tap.h> #include <epan/emem.h> -#include <epan/crc32.h> +#include <epan/crc32-tvb.h> #include <epan/expert.h> #define FC_HEADER_SIZE 24 diff --git a/epan/dissectors/packet-fcoe.c b/epan/dissectors/packet-fcoe.c index 09094df5f6..9612bbd02d 100644 --- a/epan/dissectors/packet-fcoe.c +++ b/epan/dissectors/packet-fcoe.c @@ -40,7 +40,7 @@ #include <epan/packet.h> #include <epan/prefs.h> -#include <epan/crc32.h> +#include <epan/crc32-tvb.h> #include <epan/etypes.h> #include <epan/expert.h> diff --git a/epan/dissectors/packet-fcoib.c b/epan/dissectors/packet-fcoib.c index c4c298d818..933f01d9a2 100644 --- a/epan/dissectors/packet-fcoib.c +++ b/epan/dissectors/packet-fcoib.c @@ -33,7 +33,7 @@ #include <stdlib.h> #include <epan/packet.h> #include <epan/prefs.h> -#include <epan/crc32.h> +#include <epan/crc32-tvb.h> #include <epan/etypes.h> #include <epan/expert.h> #include <errno.h> diff --git a/epan/dissectors/packet-ieee80211.c b/epan/dissectors/packet-ieee80211.c index dfa5331b64..8fe8c1263a 100644 --- a/epan/dissectors/packet-ieee80211.c +++ b/epan/dissectors/packet-ieee80211.c @@ -116,7 +116,8 @@ #include <epan/etypes.h> #include <epan/greproto.h> #include <epan/oui.h> -#include <epan/crc32.h> +#include <wsutil/crc32.h> +#include <epan/crc32-tvb.h> #include <epan/tap.h> #include <epan/emem.h> #include <epan/crypt/wep-wpadefs.h> diff --git a/epan/dissectors/packet-ieee802154.c b/epan/dissectors/packet-ieee802154.c index 5c970fa6e4..362a603053 100644 --- a/epan/dissectors/packet-ieee802154.c +++ b/epan/dissectors/packet-ieee802154.c @@ -75,7 +75,7 @@ #include <epan/emem.h> #include <epan/packet.h> -#include <epan/crc16.h> +#include <epan/crc16-tvb.h> #include <epan/expert.h> #include <epan/addr_resolv.h> #include <epan/prefs.h> diff --git a/epan/dissectors/packet-iscsi.c b/epan/dissectors/packet-iscsi.c index bbbdcf877a..1bad474973 100644 --- a/epan/dissectors/packet-iscsi.c +++ b/epan/dissectors/packet-iscsi.c @@ -49,7 +49,7 @@ #include <epan/nstime.h> #include <epan/emem.h> #include <epan/range.h> -#include <epan/crc32.h> +#include <wsutil/crc32.h> /* the absolute values of these constants don't matter as long as * latter revisions of the protocol are assigned a larger number */ diff --git a/epan/dissectors/packet-iuup.c b/epan/dissectors/packet-iuup.c index e9ae3a0755..20d2b92991 100644 --- a/epan/dissectors/packet-iuup.c +++ b/epan/dissectors/packet-iuup.c @@ -40,8 +40,8 @@ #include <epan/prefs.h> #include <epan/emem.h> #include <epan/expert.h> -#include <epan/crc10.h> -#include <epan/crc6.h> +#include <wsutil/crc10.h> +#include <wsutil/crc6.h> typedef struct _iuup_rfci_t { diff --git a/epan/dissectors/packet-iwarp-mpa.c b/epan/dissectors/packet-iwarp-mpa.c index ec85288d90..62e4a81f8e 100644 --- a/epan/dissectors/packet-iwarp-mpa.c +++ b/epan/dissectors/packet-iwarp-mpa.c @@ -36,7 +36,7 @@ #include <epan/conversation.h> #include <epan/dissectors/packet-tcp.h> #include <epan/expert.h> -#include <epan/crc32.h> +#include <wsutil/crc32.h> /* DEFINES */ diff --git a/epan/dissectors/packet-lapd.c b/epan/dissectors/packet-lapd.c index 9453808d6f..dc970d8b72 100644 --- a/epan/dissectors/packet-lapd.c +++ b/epan/dissectors/packet-lapd.c @@ -46,7 +46,7 @@ #include <epan/packet.h> #include <epan/conversation.h> #include <epan/xdlc.h> -#include <epan/crc16.h> +#include <epan/crc16-tvb.h> #include <epan/prefs.h> #include <epan/lapd_sapi.h> diff --git a/epan/dissectors/packet-mtp2.c b/epan/dissectors/packet-mtp2.c index 24c0519810..f44bcc45ef 100644 --- a/epan/dissectors/packet-mtp2.c +++ b/epan/dissectors/packet-mtp2.c @@ -35,7 +35,7 @@ #include <glib.h> #include <epan/packet.h> #include <epan/prefs.h> -#include <epan/crc16.h> +#include <epan/crc16-tvb.h> #include <epan/expert.h> /* Initialize the protocol and registered fields */ diff --git a/epan/dissectors/packet-mux27010.c b/epan/dissectors/packet-mux27010.c index 5e6c6b6eaa..af9f4a90ac 100644 --- a/epan/dissectors/packet-mux27010.c +++ b/epan/dissectors/packet-mux27010.c @@ -30,7 +30,7 @@ #include <glib.h> #include <epan/packet.h> #include <epan/reassemble.h> -#include <epan/crc8.h> +#include <epan/crc8-tvb.h> #include <expert.h> #include <string.h> diff --git a/epan/dissectors/packet-nfs.c b/epan/dissectors/packet-nfs.c index a775228620..fa071842c2 100644 --- a/epan/dissectors/packet-nfs.c +++ b/epan/dissectors/packet-nfs.c @@ -33,6 +33,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <glib.h> #include "packet-rpc.h" #include "packet-nfs.h" @@ -40,12 +41,10 @@ #include <epan/packet.h> #include <epan/emem.h> #include <epan/strutil.h> -#include <epan/crc32.h> +#include <wsutil/crc32.h> #include <epan/expert.h> -#include <epan/crc16.h> -#include <glib.h> -#include <glib/gprintf.h> +#include <wsutil/crc16.h> static int proto_nfs = -1; static int hf_nfs_access_check = -1; diff --git a/epan/dissectors/packet-ntlmssp.c b/epan/dissectors/packet-ntlmssp.c index 8fcb676332..0fa3783b69 100644 --- a/epan/dissectors/packet-ntlmssp.c +++ b/epan/dissectors/packet-ntlmssp.c @@ -53,7 +53,7 @@ #include <epan/crypt/crypt-des.h> #include "packet-dcerpc.h" #include "packet-gssapi.h" -#include <epan/crc32.h> +#include <wsutil/crc32.h> #include "packet-ntlmssp.h" diff --git a/epan/dissectors/packet-ppp.c b/epan/dissectors/packet-ppp.c index 63145bb636..2dceec9ece 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 <epan/nlpid.h> -#include <epan/crc16.h> -#include <epan/crc32.h> +#include <epan/crc16-tvb.h> +#include <epan/crc32-tvb.h> #include <epan/ipproto.h> #include "packet-usb.h" #include "packet-sll.h" diff --git a/epan/dissectors/packet-radiotap.c b/epan/dissectors/packet-radiotap.c index 6a7f9e4cdb..fba0dacce7 100644 --- a/epan/dissectors/packet-radiotap.c +++ b/epan/dissectors/packet-radiotap.c @@ -33,7 +33,7 @@ #include <errno.h> #include <epan/packet.h> -#include <epan/crc32.h> +#include <epan/crc32-tvb.h> #include <epan/frequency-utils.h> #include <epan/tap.h> #include <epan/prefs.h> diff --git a/epan/dissectors/packet-sctp.c b/epan/dissectors/packet-sctp.c index 45bed6cadc..081f5ea8c1 100644 --- a/epan/dissectors/packet-sctp.c +++ b/epan/dissectors/packet-sctp.c @@ -65,7 +65,7 @@ #include <epan/emem.h> #include <epan/expert.h> #include <packet-frame.h> -#include <epan/crc32.h> +#include <wsutil/crc32.h> #include <epan/adler32.h> #define LT(x, y) ((gint32)((x) - (y)) < 0) diff --git a/epan/dissectors/packet-srp.c b/epan/dissectors/packet-srp.c index 415a3057db..7054a28601 100644 --- a/epan/dissectors/packet-srp.c +++ b/epan/dissectors/packet-srp.c @@ -32,8 +32,7 @@ #include <epan/bitswap.h> #include <epan/circuit.h> #include <epan/stream.h> -/* #include <epan/reassemble.h> */ -#include <epan/crc16.h> +#include <epan/crc16-tvb.h> /* Wireshark ID of the protocols */ static int proto_srp = -1; diff --git a/epan/dissectors/packet-synphasor.c b/epan/dissectors/packet-synphasor.c index 799b8ea80f..4178db562e 100644 --- a/epan/dissectors/packet-synphasor.c +++ b/epan/dissectors/packet-synphasor.c @@ -30,7 +30,7 @@ #include <glib.h> #include <epan/conversation.h> -#include <epan/crc16.h> +#include <epan/crc16-tvb.h> #include <epan/dissectors/packet-tcp.h> #include <epan/packet.h> #include <epan/prefs.h> diff --git a/epan/dissectors/packet-teamspeak2.c b/epan/dissectors/packet-teamspeak2.c index 8873becac4..eec8748787 100644 --- a/epan/dissectors/packet-teamspeak2.c +++ b/epan/dissectors/packet-teamspeak2.c @@ -29,7 +29,8 @@ #endif #include <epan/packet.h> -#include <epan/crc32.h> +#include <wsutil/crc32.h> +#include <epan/crc32-tvb.h> #include <epan/reassemble.h> #include <epan/conversation.h> #include <stdlib.h> diff --git a/epan/dissectors/packet-zrtp.c b/epan/dissectors/packet-zrtp.c index b9d00d8771..5ce53ceddb 100644 --- a/epan/dissectors/packet-zrtp.c +++ b/epan/dissectors/packet-zrtp.c @@ -34,7 +34,7 @@ #include <glib.h> #include <epan/packet.h> #include <epan/strutil.h> -#include <epan/crc32.h> +#include <wsutil/crc32.h> #include "packet-rtp.h" #include "packet-rtcp.h" diff --git a/epan/libwireshark.def b/epan/libwireshark.def index afedf81c6a..604a415ea0 100644 --- a/epan/libwireshark.def +++ b/epan/libwireshark.def @@ -114,14 +114,15 @@ copy_persconffile_profile copy_prefs crc16_ccitt_tvb crc16_plain_tvb_offset -crc32c_calculate -crc32_ccitt -crc32_ccitt_seed +crc16_ccitt_tvb_offset +crc16_ccitt_tvb_offset_seed +crc16_ccitt_tvb_seed +crc16_x25_ccitt_tvb +crc32_802_tvb crc32_ccitt_tvb crc32_ccitt_tvb_offset crc32_ccitt_tvb_seed crc32_ccitt_tvb_offset_seed -crc32_802_tvb create_dissector_handle create_persconffile_dir create_persconffile_profile diff --git a/epan/sigcomp-udvm.c b/epan/sigcomp-udvm.c index de28f7f6de..6e87a4adfc 100644 --- a/epan/sigcomp-udvm.c +++ b/epan/sigcomp-udvm.c @@ -44,7 +44,7 @@ #include "sigcomp-udvm.h" #include "sigcomp_state_hdlr.h" #include "crypt/crypt-sha1.h" -#include "crc16.h" +#include "wsutil/crc16.h" #include "except.h" #define SIGCOMP_INSTR_DECOMPRESSION_FAILURE 0 diff --git a/gtk/text_import.c b/gtk/text_import.c index 2fe6e34e44..69b67dd829 100644 --- a/gtk/text_import.c +++ b/gtk/text_import.c @@ -124,7 +124,7 @@ #include <assert.h> #include <epan/tvbuff.h> -#include <epan/crc32.h> +#include <wsutil/crc32.h> #include <epan/in_cksum.h> #ifdef NEED_STRPTIME_H diff --git a/plugins/irda/packet-sir.c b/plugins/irda/packet-sir.c index ad17b65771..bc8eb4c438 100644 --- a/plugins/irda/packet-sir.c +++ b/plugins/irda/packet-sir.c @@ -29,7 +29,7 @@ #endif #include <epan/packet.h> -#include <epan/crc16.h> +#include <epan/crc16-tvb.h> /** Serial infrared port. */ #define TCP_PORT_SIR 6417 diff --git a/plugins/profinet/packet-pn-rt.c b/plugins/profinet/packet-pn-rt.c index 50b42a347d..f189296619 100644 --- a/plugins/profinet/packet-pn-rt.c +++ b/plugins/profinet/packet-pn-rt.c @@ -43,7 +43,7 @@ #include <epan/etypes.h> #include <epan/expert.h> #include <epan/dissectors/packet-dcerpc.h> -#include <epan/crc16.h> +#include <epan/crc16-tvb.h> #include "packet-pn.h" diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 25eabb1d64..51d9c11fb4 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -35,6 +35,12 @@ set(WSUTIL_FILES # @INET_PTON_LO@ # inet_pton.c # @STRNCASECMP_LO@ # strncasecmp.c # @STRPTIME_LO@ # strptime.c + crc10.c + crc16.c + crc16-plain.c + crc32.c + crc6.c + crcdrm.c mpeg-audio.c privileges.c str_util.c diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common index cbe90655ac..019f50bfa7 100644 --- a/wsutil/Makefile.common +++ b/wsutil/Makefile.common @@ -29,6 +29,12 @@ # generated from YACC or Lex files (as Automake doesn't want them in # _SOURCES variables). LIBWSUTIL_SRC = \ + crc10.c \ + crc16.c \ + crc16-plain.c \ + crc32.c \ + crc6.c \ + crcdrm.c \ mpeg-audio.c \ privileges.c \ str_util.c \ @@ -36,6 +42,12 @@ LIBWSUTIL_SRC = \ # Header files that are not generated from other files LIBWSUTIL_INCLUDES = \ + crc6.h \ + crc10.h \ + crc16.h \ + crc16-plain.h \ + crc32.h \ + crcdrm.h \ mpeg-audio.h \ privileges.h \ str_util.h \ diff --git a/epan/crc10.c b/wsutil/crc10.c index 77d5068624..77d5068624 100644 --- a/epan/crc10.c +++ b/wsutil/crc10.c diff --git a/epan/crc10.h b/wsutil/crc10.h index a0b5a0fa09..f9e50dd476 100644 --- a/epan/crc10.h +++ b/wsutil/crc10.h @@ -23,5 +23,10 @@ * */ +#ifndef __CRC10_H__ +#define __CRC10_H__ + /* update the data block's CRC-10 remainder one byte at a time */ extern guint16 update_crc10_by_bytes(guint16 crc10, const guint8 *data_blk_ptr, int data_blk_size); + +#endif /* __CRC10_H__ */ diff --git a/epan/crc/crc-16-plain.c b/wsutil/crc16-plain.c index 863f939d4a..edbc21e476 100644 --- a/epan/crc/crc-16-plain.c +++ b/wsutil/crc16-plain.c @@ -1,5 +1,5 @@ /** - * \file crc-16-plain.c + * \file crc16-plain.c * Functions and types for CRC checks. * * Generated on Wed Mar 18 14:12:09 2009, @@ -18,7 +18,7 @@ * appears not to have it; we're using GLib types, instead. *****************************************************************************/ #include "glib.h" -#include "crc-16-plain.h" +#include "wsutil/crc16-plain.h" #include <stdlib.h> /** diff --git a/epan/crc/crc-16-plain.h b/wsutil/crc16-plain.h index 2ad0217066..f6593562af 100644 --- a/epan/crc/crc-16-plain.h +++ b/wsutil/crc16-plain.h @@ -1,5 +1,5 @@ /** - * \file crc-16-plain.h + * \file crc16-plain.h * Functions and types for CRC checks. * * Generated on Wed Mar 18 14:12:15 2009, diff --git a/epan/crc16.c b/wsutil/crc16.c index 5fcd105dca..2779530b5b 100644 --- a/epan/crc16.c +++ b/wsutil/crc16.c @@ -6,11 +6,9 @@ * $Id$ * * Wireshark - Network traffic analyzer - * By Gerald Combs <gerald@xxxxxxxxxxxx> + * By Gerald Combs <gerald@wireshark.org> * 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 @@ -38,9 +36,8 @@ #endif #include <glib.h> -#include <epan/tvbuff.h> -#include <epan/crc16.h> -#include <epan/crc/crc-16-plain.h> +#include <wsutil/crc16.h> +#include <wsutil/crc16-plain.h> /*****************************************************************/ @@ -206,49 +203,3 @@ guint16 crc16_ccitt_seed(const guint8 *buf, guint len, guint16 seed) ^ 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_x25_ccitt_tvb(tvbuff_t *tvb, guint len) -{ - const guint8* buf = tvb_get_ptr(tvb, 0, len); - - return crc16_x25_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); -} - -guint16 crc16_plain_tvb_offset(tvbuff_t *tvb, guint offset, guint len) -{ - guint16 crc = crc16_plain_init(); - - const guint8* buf = tvb_get_ptr(tvb, offset, len); - - crc = crc16_plain_update(crc, buf, len); - - return crc16_plain_finalize(crc); -} - diff --git a/wsutil/crc16.h b/wsutil/crc16.h new file mode 100644 index 0000000000..9ac1928b9e --- /dev/null +++ b/wsutil/crc16.h @@ -0,0 +1,68 @@ +/* crc16.h + * Declaration of CRC-16 routines and table + * + * 2004 Richard van der Hoff <richardv@mxtelecom.com> + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * 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 __CRC16_H__ +#define __CRC16_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* 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 X.25 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 X.25 CCITT checksum. */ +extern guint16 crc16_x25_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); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* crc16.h */ diff --git a/epan/crc32.c b/wsutil/crc32.c index 0fe2b29547..f01c5eb901 100644 --- a/epan/crc32.c +++ b/wsutil/crc32.c @@ -7,8 +7,6 @@ * By Gerald Combs <gerald@wireshark.org> * 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 @@ -34,8 +32,7 @@ #endif #include <glib.h> -#include <epan/tvbuff.h> -#include <epan/crc32.h> +#include <wsutil/crc32.h> /*****************************************************************/ /* */ @@ -173,7 +170,6 @@ const guint32 crc32_ccitt_table[256] = { 0x2d02ef8d }; -#define CRC32_CCITT_SEED 0xFFFFFFFF guint32 crc32c_calculate(const void *buf, int len, guint32 crc) @@ -203,73 +199,3 @@ crc32_ccitt_seed(const guint8 *buf, guint len, guint32 seed) return ( ~crc32 ); } - -guint32 -crc32_ccitt_tvb(tvbuff_t *tvb, guint len) -{ - const guint8* buf; - - tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */ - 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_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */ - 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_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */ - 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_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */ - 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/wsutil/crc32.h b/wsutil/crc32.h new file mode 100644 index 0000000000..90d77ae31f --- /dev/null +++ b/wsutil/crc32.h @@ -0,0 +1,76 @@ +/* crc32.h + * Declaration of CRC-32 routine and table + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * 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 __CRC32_H__ +#define __CRC32_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define CRC32_CCITT_SEED 0xFFFFFFFF +#define CRC32C_PRELOAD 0xffffffff + +/* + * Byte swap fix contributed by Dave Wysochanski <davidw@netapp.com>. + */ +#define CRC32C_SWAP(crc32c_value) \ + (((crc32c_value & 0xff000000) >> 24) | \ + ((crc32c_value & 0x00ff0000) >> 8) | \ + ((crc32c_value & 0x0000ff00) << 8) | \ + ((crc32c_value & 0x000000ff) << 24)) + +#define CRC32C(c,d) (c=(c>>8)^crc32c_table[(c^(d))&0xFF]) + +extern const guint32 crc32c_table[256]; + +/** Compute CRC32C checksum of a buffer of data. + @param buf The buffer containing the data. + @param len The number of bytes to include in the computation. + @param crc The preload value for the CRC32C computation. + @return The CRC32C checksum. */ +extern guint32 crc32c_calculate(const void *buf, int len, guint32 crc); + +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); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* crc32.h */ diff --git a/epan/crc6.c b/wsutil/crc6.c index 333a1a51cd..333a1a51cd 100644 --- a/epan/crc6.c +++ b/wsutil/crc6.c diff --git a/epan/crc6.h b/wsutil/crc6.h index c8abfb4ad4..d90853cf2e 100644 --- a/epan/crc6.h +++ b/wsutil/crc6.h @@ -22,5 +22,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#ifndef __CRC6_H__ +#define __CRC6_H__ + extern guint16 update_crc6_by_bytes(guint16 crc6, guint8 byte1, guint8 byte2); +#endif /* __CRC6_H__ */ diff --git a/epan/crcdrm.c b/wsutil/crcdrm.c index 345a232bb9..3f6438eff2 100644 --- a/epan/crcdrm.c +++ b/wsutil/crcdrm.c @@ -23,8 +23,9 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <stdlib.h> -#include "crcdrm.h" +#include <wsutil/crcdrm.h> unsigned long crc_drm(const char *data, size_t bytesize, unsigned short num_crc_bits, unsigned long crc_gen, int invert) diff --git a/epan/crcdrm.h b/wsutil/crcdrm.h index 195cee09d1..3497ef2004 100644 --- a/epan/crcdrm.h +++ b/wsutil/crcdrm.h @@ -23,10 +23,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef _CRCDRM_H - -#include <stdlib.h> +#ifndef __CRCDRM_H__ +#define __CRCDRM_H__ unsigned long crc_drm(const char *data, size_t bytesize, unsigned short num_crc_bits, unsigned long crc_gen, int invert); -#endif + +#endif /* __CRCDRM_H__ */ diff --git a/wsutil/libwsutil.def b/wsutil/libwsutil.def index 7aadd7e848..46a7c7e38c 100644 --- a/wsutil/libwsutil.def +++ b/wsutil/libwsutil.def @@ -9,6 +9,24 @@ ; EXPORTS +; crc6.c +update_crc6_by_bytes + +; crc10.c +update_crc10_by_bytes + +; crc16.c +crc16_ccitt +crc16_ccitt_seed +crc16_x25_ccitt + +; crc32.c +crc32_ccitt +crc32_ccitt_seed +crc32_ccitt_table DATA +crc32c_calculate +crc32c_table DATA + ; file_util.c getenv_utf8 ws_stdio_fopen |