4 * 2004 Richard van der Hoff <richardv@mxtelecom.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 * "A Painless Guide to CRC Error Detection Algorithms", Ross Williams
28 * http://www.repairfaq.org/filipg/LINK/F_crc_v3.html
30 * ITU-T Recommendation V.42 (2002), "Error-Correcting Procedures for
31 * DCEs using asynchronous-to-synchronous conversion", Para. 8.1.1.6.1
39 #include <epan/tvbuff.h>
40 #include <wsutil/crc16.h>
41 #include <wsutil/crc16-plain.h>
44 guint16 crc16_ccitt_tvb(tvbuff_t *tvb, guint len)
48 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
49 buf = tvb_get_ptr(tvb, 0, len);
51 return crc16_ccitt(buf, len);
54 guint16 crc16_x25_ccitt_tvb(tvbuff_t *tvb, guint len)
58 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
59 buf = tvb_get_ptr(tvb, 0, len);
61 return crc16_x25_ccitt(buf, len);
64 guint16 crc16_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
68 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
69 buf = tvb_get_ptr(tvb, offset, len);
71 return crc16_ccitt(buf, len);
74 guint16 crc16_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint16 seed)
78 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
79 buf = tvb_get_ptr(tvb, 0, len);
81 return crc16_ccitt_seed(buf, len, seed);
84 guint16 crc16_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 seed)
88 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
89 buf = tvb_get_ptr(tvb, offset, len);
91 return crc16_ccitt_seed(buf, len, seed);
94 guint16 crc16_plain_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
96 guint16 crc = crc16_plain_init();
99 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
100 buf = tvb_get_ptr(tvb, offset, len);
102 crc = crc16_plain_update(crc, buf, len);
104 return crc16_plain_finalize(crc);