MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / crc32-tvb.c
blob74b5abbb38bffcfeeaff775f2d3982a4307255ab
1 /* crc32-tvb.c
2 * CRC-32 tvbuff routines
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * Credits:
26 * Table from Solomon Peachy
27 * Routine from Chris Waters
30 #include "config.h"
32 #include <glib.h>
33 #include <epan/tvbuff.h>
34 #include <wsutil/crc32.h>
35 #include <epan/crc32-tvb.h>
38 guint32
39 crc32_ccitt_tvb(tvbuff_t *tvb, guint len)
41 const guint8* buf;
43 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
44 buf = tvb_get_ptr(tvb, 0, len);
46 return ( crc32_ccitt_seed(buf, len, CRC32_CCITT_SEED) );
49 guint32
50 crc32_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
52 const guint8* buf;
54 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
55 buf = tvb_get_ptr(tvb, offset, len);
57 return ( crc32_ccitt(buf, len) );
60 guint32
61 crc32_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint32 seed)
63 const guint8* buf;
65 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
66 buf = tvb_get_ptr(tvb, 0, len);
68 return ( crc32_ccitt_seed(buf, len, seed) );
71 guint32
72 crc32_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len,
73 guint32 seed)
75 const guint8* buf;
77 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
78 buf = tvb_get_ptr(tvb, offset, len);
80 return ( crc32_ccitt_seed(buf, len, seed) );
84 * IEEE 802.x version (Ethernet and 802.11, at least) - byte-swap
85 * the result of "crc32()".
87 * XXX - does this mean we should fetch the Ethernet and 802.11
88 * FCS with "tvb_get_letohl()" rather than "tvb_get_ntohl()",
89 * or is fetching it big-endian and byte-swapping the CRC done
90 * to cope with 802.x sending stuff out in reverse bit order?
92 guint32
93 crc32_802_tvb(tvbuff_t *tvb, guint len)
95 guint32 c_crc;
97 c_crc = crc32_ccitt_tvb(tvb, len);
99 /* Byte reverse. */
100 c_crc = GUINT32_SWAP_LE_BE(c_crc);
102 return ( c_crc );
105 guint32
106 crc32_mpeg2_tvb_offset_seed(tvbuff_t *tvb, guint offset,
107 guint len, guint32 seed)
109 const guint8* buf;
111 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
112 buf = tvb_get_ptr(tvb, offset, len);
114 return ( crc32_mpeg2_seed(buf, len, seed) );
117 guint32
118 crc32_mpeg2_tvb(tvbuff_t *tvb, guint len)
120 return ( crc32_mpeg2_tvb_offset_seed(tvb, 0, len, CRC32_MPEG2_SEED) );
123 guint32
124 crc32_mpeg2_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
126 return ( crc32_mpeg2_tvb_offset_seed(tvb, offset, len, CRC32_MPEG2_SEED) );
129 guint32
130 crc32_mpeg2_tvb_seed(tvbuff_t *tvb, guint len, guint32 seed)
132 return ( crc32_mpeg2_tvb_offset_seed(tvb, 0, len, seed) );
135 guint32 crc32_0x0AA725CF_tvb_offset_seed(tvbuff_t *tvb,
136 guint offset, guint len, guint32 seed)
138 const guint8 *buf;
140 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
141 buf = tvb_get_ptr(tvb, offset, len);
143 return crc32_0x0AA725CF_seed(buf, len, seed);