Mark an unused parameter as such
[metze/wireshark/wip.git] / epan / crc16-tvb.c
1 /* crc16-tvb.c
2  * CRC-16 tvb routines
3  *
4  * 2004 Richard van der Hoff <richardv@mxtelecom.com>
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
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.
16  *
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.
21  *
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.
25  *
26  * References:
27  *  "A Painless Guide to CRC Error Detection Algorithms", Ross Williams
28  *      http://www.repairfaq.org/filipg/LINK/F_crc_v3.html
29  *
30  *  ITU-T Recommendation V.42 (2002), "Error-Correcting Procedures for
31  *      DCEs using asynchronous-to-synchronous conversion", Para. 8.1.1.6.1
32  */
33
34 #include "config.h"
35
36 #include <glib.h>
37 #include <epan/tvbuff.h>
38 #include <wsutil/crc16.h>
39 #include <epan/crc16-tvb.h>
40 #include <wsutil/crc16-plain.h>
41
42
43 guint16 crc16_ccitt_tvb(tvbuff_t *tvb, guint len)
44 {
45     const guint8 *buf;
46
47     tvb_ensure_bytes_exist(tvb, 0, len);  /* len == -1 not allowed */
48     buf = tvb_get_ptr(tvb, 0, len);
49
50     return crc16_ccitt(buf, len);
51 }
52
53 guint16 crc16_x25_ccitt_tvb(tvbuff_t *tvb, guint len)
54 {
55     const guint8 *buf;
56
57     tvb_ensure_bytes_exist(tvb, 0, len);  /* len == -1 not allowed */
58     buf = tvb_get_ptr(tvb, 0, len);
59
60     return crc16_x25_ccitt(buf, len);
61 }
62
63 guint16 crc16_ccitt_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
64 {
65     const guint8 *buf;
66
67     tvb_ensure_bytes_exist(tvb, offset, len);  /* len == -1 not allowed */
68     buf = tvb_get_ptr(tvb, offset, len);
69
70     return crc16_ccitt(buf, len);
71 }
72
73 guint16 crc16_ccitt_tvb_seed(tvbuff_t *tvb, guint len, guint16 seed)
74 {
75     const guint8 *buf;
76
77     tvb_ensure_bytes_exist(tvb, 0, len);  /* len == -1 not allowed */
78     buf = tvb_get_ptr(tvb, 0, len);
79
80     return crc16_ccitt_seed(buf, len, seed);
81 }
82
83 guint16 crc16_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 seed)
84 {
85     const guint8 *buf;
86
87     tvb_ensure_bytes_exist(tvb, offset, len);  /* len == -1 not allowed */
88     buf = tvb_get_ptr(tvb, offset, len);
89
90     return crc16_ccitt_seed(buf, len, seed);
91 }
92
93 guint16 crc16_plain_tvb_offset(tvbuff_t *tvb, guint offset, guint len)
94 {
95     guint16 crc = crc16_plain_init();
96     const guint8 *buf;
97
98     tvb_ensure_bytes_exist(tvb, offset, len);  /* len == -1 not allowed */
99     buf = tvb_get_ptr(tvb, offset, len);
100
101     crc = crc16_plain_update(crc, buf, len);
102     
103     return crc16_plain_finalize(crc);
104 }
105
106 guint16 crc16_plain_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 crc)
107 {
108     const guint8 *buf;
109
110     tvb_ensure_bytes_exist(tvb, offset, len);  /* len == -1 not allowed */
111     buf = tvb_get_ptr(tvb, offset, len);
112
113     crc = crc16_plain_update(crc, buf, len);
114     
115     return crc16_plain_finalize(crc);
116 }
117
118 guint16 crc16_0x9949_tvb_offset_seed(tvbuff_t *tvb, guint offset, guint len, guint16 seed)
119 {
120     const guint8 *buf;
121
122     tvb_ensure_bytes_exist(tvb, offset, len);  /* len == -1 not allowed */
123     buf = tvb_get_ptr(tvb, offset, len);
124
125     return crc16_0x9949_seed(buf, len, seed);
126 }