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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
37 #include <epan/tvbuff.h>
38 #include <wsutil/crc16.h>
39 #include <wsutil/crc16-plain.h>
42 guint16 crc16_ccitt_tvb(tvbuff_t *tvb, guint len)
46 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
47 buf = tvb_get_ptr(tvb, 0, len);
49 return crc16_ccitt(buf, len);
52 guint16 crc16_x25_ccitt_tvb(tvbuff_t *tvb, guint len)
56 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
57 buf = tvb_get_ptr(tvb, 0, len);
59 return crc16_x25_ccitt(buf, len);
62 guint16 crc16_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
66 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
67 buf = tvb_get_ptr(tvb, offset, len);
69 return crc16_ccitt(buf, len);
72 guint16 crc16_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint16 seed)
76 tvb_ensure_bytes_exist(tvb, 0, len); /* len == -1 not allowed */
77 buf = tvb_get_ptr(tvb, 0, len);
79 return crc16_ccitt_seed(buf, len, seed);
82 guint16 crc16_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 seed)
86 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
87 buf = tvb_get_ptr(tvb, offset, len);
89 return crc16_ccitt_seed(buf, len, seed);
92 guint16 crc16_plain_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
94 guint16 crc = crc16_plain_init();
97 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
98 buf = tvb_get_ptr(tvb, offset, len);
100 crc = crc16_plain_update(crc, buf, len);
102 return crc16_plain_finalize(crc);
105 guint16 crc16_plain_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 crc)
109 tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */
110 buf = tvb_get_ptr(tvb, offset, len);
112 crc = crc16_plain_update(crc, buf, len);
114 return crc16_plain_finalize(crc);