Get rid of some GCC warnings about unused code.
[obnox/wireshark/wip.git] / epan / tvbuff.h
1 /* tvbuff.h
2  *
3  * Testy, Virtual(-izable) Buffer of guint8*'s
4  *
5  * "Testy" -- the buffer gets mad when an attempt is made to access data
6  *              beyond the bounds of the buffer. An exception is thrown.
7  *
8  * "Virtual" -- the buffer can have its own data, can use a subset of
9  *              the data of a backing tvbuff, or can be a composite of
10  *              other tvbuffs.
11  *
12  * $Id$
13  *
14  * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
15  *
16  * Ethereal - Network traffic analyzer
17  * By Gerald Combs <gerald@ethereal.com>
18  * Copyright 1998 Gerald Combs
19  *
20  * This program is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU General Public License
22  * as published by the Free Software Foundation; either version 2
23  * of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
33  */
34
35 #ifndef __TVBUFF_H__
36 #define __TVBUFF_H__
37
38 #include <glib.h>
39 #include <epan/ipv6-utils.h>
40 #include "exceptions.h"
41
42 /** @file
43  * "testy, virtual(-izable) buffer".  They are testy in that they get mad when
44  * an attempt is made to access data beyond the bounds of their array. In that
45  * case, they throw an exception.
46  * 
47  * They are virtualizable in that new tvbuff's can be made from other tvbuffs, 
48  * while only the original tvbuff may have data. That is, the new tvbuff has 
49  * virtual data.
50  */
51
52
53 /** The different types of tvbuff's */
54 typedef enum {
55         TVBUFF_REAL_DATA,
56         TVBUFF_SUBSET,
57         TVBUFF_COMPOSITE
58 } tvbuff_type;
59
60 typedef struct {
61         /* The backing tvbuff_t */
62         struct tvbuff   *tvb;
63
64         /* The offset/length of 'tvb' to which I'm privy */
65         guint           offset;
66         guint           length;
67
68 } tvb_backing_t;
69
70 typedef struct {
71         GSList          *tvbs;
72
73         /* Used for quick testing to see if this
74          * is the tvbuff that a COMPOSITE is
75          * interested in. */
76         guint           *start_offsets;
77         guint           *end_offsets;
78
79 } tvb_comp_t;
80
81 typedef void (*tvbuff_free_cb_t)(void*);
82
83 typedef struct tvbuff {
84         /* Record-keeping */
85         tvbuff_type             type;
86         gboolean                initialized;
87         guint                   usage_count;
88         struct tvbuff           *ds_tvb;  /* data source top-level tvbuff */
89
90         /* The tvbuffs in which this tvbuff is a member
91          * (that is, a backing tvbuff for a TVBUFF_SUBSET
92          * or a member for a TVB_COMPOSITE) */
93         GSList                  *used_in;
94
95         /* TVBUFF_SUBSET and TVBUFF_COMPOSITE keep track
96          * of the other tvbuff's they use */
97         union {
98                 tvb_backing_t   subset;
99                 tvb_comp_t      composite;
100         } tvbuffs;
101
102         /* We're either a TVBUFF_REAL_DATA or a
103          * TVBUFF_SUBSET that has a backing buffer that
104          * has real_data != NULL, or a TVBUFF_COMPOSITE
105          * which has flattened its data due to a call
106          * to tvb_get_ptr().
107          */
108         const guint8            *real_data;
109
110         /* Length of virtual buffer (and/or real_data). */
111         guint                   length;
112
113         /* Reported length. */
114         guint                   reported_length;
115
116         /* Offset from beginning of first TVBUFF_REAL. */
117         gint                    raw_offset;
118
119         /* Func to call when actually freed */
120         tvbuff_free_cb_t        free_cb;
121 } tvbuff_t;
122
123
124
125 /** TVBUFF_REAL_DATA contains a guint8* that points to real data.
126  * The data is allocated and contiguous.
127  *
128  * TVBUFF_SUBSET has a backing tvbuff. The TVBUFF_SUBSET is a "window"
129  * through which the program sees only a portion of the backing tvbuff.
130  *
131  * TVBUFF_COMPOSITE combines multiple tvbuffs sequentually to produce
132  * a larger byte array.
133  *
134  * tvbuff's of any type can be used as the backing-tvbuff of a
135  * TVBUFF_SUBSET or as the member of a TVBUFF_COMPOSITE.
136  * TVBUFF_COMPOSITEs can have member-tvbuffs of different types.
137  *
138  * Once a tvbuff is create/initialized/finalized, the tvbuff is read-only.
139  * That is, it cannot point to any other data. A new tvbuff must be created if
140  * you want a tvbuff that points to other data.
141  */
142
143
144 /** "class" initialization. Called once during execution of program
145  * so that tvbuff.c can initialize its data. */
146 extern void tvbuff_init(void);
147
148 /** "class" cleanup. Called once during execution of program
149  * so that tvbuff.c can clean up its data. */
150 extern void tvbuff_cleanup(void);
151
152
153 /** Returns a pointer to a newly initialized tvbuff. Note that
154  * tvbuff's of types TVBUFF_SUBSET and TVBUFF_COMPOSITE
155  * require further initialization via the appropriate functions */
156 extern tvbuff_t* tvb_new(tvbuff_type);
157
158 /** Marks a tvbuff for freeing. The guint8* data of a TVBUFF_REAL_DATA
159  * is *never* freed by the tvbuff routines. The tvbuff itself is actually freed
160  * once its usage count drops to 0.
161  *
162  * Usage counts increment for any time the tvbuff is
163  * used as a member of another tvbuff, i.e., as the backing buffer for
164  * a TVBUFF_SUBSET or as a member of a TVBUFF_COMPOSITE.
165  *
166  * Although you may call tvb_free(), the tvbuff may still be in use
167  * by other tvbuff's (TVBUFF_SUBSET or TVBUFF_COMPOSITE), so it is not
168  * safe, unless you know otherwise, to free your guint8* data. If you
169  * cannot be sure that your TVBUFF_REAL_DATA is not in use by another
170  * tvbuff, register a callback with tvb_set_free_cb(); when your tvbuff
171  * is _really_ freed, then your callback will be called, and at that time
172  * you can free your original data.
173  *
174  * The caller can artificially increment/decrement the usage count
175  * with tvbuff_increment_usage_count()/tvbuff_decrement_usage_count().
176  */
177 extern void tvb_free(tvbuff_t*);
178
179 /** Free the tvbuff_t and all tvbuff's created from it. */
180 extern void tvb_free_chain(tvbuff_t*);
181
182 /** Both return the new usage count, after the increment or decrement */
183 extern guint tvb_increment_usage_count(tvbuff_t*, guint count);
184
185 /** If a decrement causes the usage count to drop to 0, a the tvbuff
186  * is immediately freed. Be sure you know exactly what you're doing
187  * if you decide to use this function, as another tvbuff could
188  * still have a pointer to the just-freed tvbuff, causing corrupted data
189  * or a segfault in the future */
190 extern guint tvb_decrement_usage_count(tvbuff_t*, guint count);
191
192 /** Set a callback function to call when a tvbuff is actually freed
193  * (once the usage count drops to 0). One argument is passed to
194  * that callback --- a void* that points to the real data.
195  * Obviously, this only applies to a TVBUFF_REAL_DATA tvbuff. */
196 extern void tvb_set_free_cb(tvbuff_t*, tvbuff_free_cb_t);
197
198
199 /** Attach a TVBUFF_REAL_DATA tvbuff to a parent tvbuff. This connection
200  * is used during a tvb_free_chain()... the "child" TVBUFF_REAL_DATA acts
201  * as if is part of the chain-of-creation of the parent tvbuff, although it
202  * isn't. This is useful if you need to take the data from some tvbuff,
203  * run some operation on it, like decryption or decompression, and make a new
204  * tvbuff from it, yet want the new tvbuff to be part of the chain. The reality
205  * is that the new tvbuff *is* part of the "chain of creation", but in a way
206  * that these tvbuff routines is ignorant of. Use this function to make
207  * the tvbuff routines knowledgable of this fact. */
208 extern void tvb_set_child_real_data_tvbuff(tvbuff_t* parent, tvbuff_t* child);
209
210 /**Sets parameters for TVBUFF_REAL_DATA. Can throw ReportedBoundsError. */
211 extern void tvb_set_real_data(tvbuff_t*, const guint8* data, guint length,
212     gint reported_length);
213
214 /** Combination of tvb_new() and tvb_set_real_data(). Can throw ReportedBoundsError. */
215 extern tvbuff_t* tvb_new_real_data(const guint8* data, guint length,
216     gint reported_length);
217
218
219 /** Define the subset of the backing buffer to use.
220  *
221  * 'backing_offset' can be negative, to indicate bytes from
222  * the end of the backing buffer.
223  *
224  * 'backing_length' can be 0, although the usefulness of the buffer would
225  * be rather limited.
226  *
227  * 'backing_length' of -1 means "to the end of the backing buffer"
228  *
229  * Will throw BoundsError if 'backing_offset'/'length'
230  * is beyond the bounds of the backing tvbuff.
231  * Can throw ReportedBoundsError. */
232 extern void tvb_set_subset(tvbuff_t* tvb, tvbuff_t* backing,
233                 gint backing_offset, gint backing_length, gint reported_length);
234
235 /** Combination of tvb_new() and tvb_set_subset()
236  * Can throw ReportedBoundsError. */
237 extern tvbuff_t* tvb_new_subset(tvbuff_t* backing,
238                 gint backing_offset, gint backing_length, gint reported_length);
239
240
241 /** Both tvb_composite_append and tvb_composite_prepend can throw
242  * BoundsError if member_offset/member_length goes beyond bounds of
243  * the 'member' tvbuff. */
244
245 /** Append to the list of tvbuffs that make up this composite tvbuff */
246 extern void tvb_composite_append(tvbuff_t* tvb, tvbuff_t* member);
247
248 /** Prepend to the list of tvbuffs that make up this composite tvbuff */
249 extern void tvb_composite_prepend(tvbuff_t* tvb, tvbuff_t* member);
250
251 /** Helper function that calls tvb_new(TVBUFF_COMPOSITE).
252  * Provided only to maintain symmetry with other constructors */
253 extern tvbuff_t* tvb_new_composite(void);
254
255 /** Mark a composite tvbuff as initialized. No further appends or prepends
256  * occur, data access can finally happen after this finalization. */
257 extern void tvb_composite_finalize(tvbuff_t* tvb);
258
259
260 /* Get total length of buffer */
261 extern guint tvb_length(tvbuff_t*);
262
263 /** Computes bytes to end of buffer, from offset (which can be negative,
264  * to indicate bytes from end of buffer). Function returns -1 to
265  * indicate that offset is out of bounds. No exception is thrown. */
266 extern gint tvb_length_remaining(tvbuff_t*, gint offset);
267
268 /** Same as above, but throws an exception if the offset is out of bounds. */
269 extern guint tvb_ensure_length_remaining(tvbuff_t*, gint offset);
270
271 /* Checks (w/o throwing exception) that the bytes referred to by
272  * 'offset'/'length' actually exist in the buffer */
273 extern gboolean tvb_bytes_exist(tvbuff_t*, gint offset, gint length);
274
275 /** Checks that the bytes referred to by 'offset'/'length' actually exist
276  * in the buffer, and throws an exception if they aren't. */
277 extern void tvb_ensure_bytes_exist(tvbuff_t *tvb, gint offset, gint length);
278
279 /* Checks (w/o throwing exception) that offset exists in buffer */
280 extern gboolean tvb_offset_exists(tvbuff_t*, gint offset);
281
282 /* Get reported length of buffer */
283 extern guint tvb_reported_length(tvbuff_t*);
284
285 /** Computes bytes of reported packet data to end of buffer, from offset
286  * (which can be negative, to indicate bytes from end of buffer). Function
287  * returns -1 to indicate that offset is out of bounds. No exception is
288  * thrown. */
289 extern gint tvb_reported_length_remaining(tvbuff_t *tvb, gint offset);
290
291 /** Set the reported length of a tvbuff to a given value; used for protocols
292    whose headers contain an explicit length and where the calling
293    dissector's payload may include padding as well as the packet for
294    this protocol.
295
296    Also adjusts the data length. */
297 extern void tvb_set_reported_length(tvbuff_t*, guint);
298
299 extern int offset_from_real_beginning(tvbuff_t *tvb, int counter);
300
301 /* Returns the offset from the first byte of real data. */
302 #define TVB_RAW_OFFSET(tvb)                     \
303         ((tvb->raw_offset==-1)?(tvb->raw_offset = offset_from_real_beginning(tvb, 0)):tvb->raw_offset)
304
305 /************** START OF ACCESSORS ****************/
306 /* All accessors will throw an exception if appropriate */
307
308 extern guint8  tvb_get_guint8(tvbuff_t*, gint offset);
309
310 extern guint16 tvb_get_ntohs(tvbuff_t*, gint offset);
311 extern guint32 tvb_get_ntoh24(tvbuff_t*, gint offset);
312 extern guint32 tvb_get_ntohl(tvbuff_t*, gint offset);
313 extern guint64 tvb_get_ntoh64(tvbuff_t*, gint offset);
314 extern gfloat tvb_get_ntohieee_float(tvbuff_t*, gint offset);
315 extern gdouble tvb_get_ntohieee_double(tvbuff_t*, gint offset);
316
317 extern guint16 tvb_get_letohs(tvbuff_t*, gint offset);
318 extern guint32 tvb_get_letoh24(tvbuff_t*, gint offset);
319 extern guint32 tvb_get_letohl(tvbuff_t*, gint offset);
320 extern guint64 tvb_get_letoh64(tvbuff_t*, gint offset);
321 extern gfloat tvb_get_letohieee_float(tvbuff_t*, gint offset);
322 extern gdouble tvb_get_letohieee_double(tvbuff_t*, gint offset);
323
324 /**
325  * Fetch an IPv4 address, in network byte order.
326  * We do *not* convert it to host byte order; we leave it in
327  * network byte order, as that's what its callers expect. */
328 extern guint32 tvb_get_ipv4(tvbuff_t*, gint offset);
329
330 /* Fetch an IPv6 address. */
331 extern void tvb_get_ipv6(tvbuff_t*, gint offset, struct e_in6_addr *addr);
332
333 /** Returns target for convenience. Does not suffer from possible
334  * expense of tvb_get_ptr(), since this routine is smart enough
335  * to copy data in chunks if the request range actually exists in
336  * different TVBUFF_REAL_DATA tvbuffs. This function assumes that the
337  * target memory is already allocated; it does not allocate or free the
338  * target memory. */
339 extern guint8* tvb_memcpy(tvbuff_t*, guint8* target, gint offset, gint length);
340
341 /** It is the user's responsibility to g_free() the memory allocated by
342  * tvb_memdup(). Calls tvb_memcpy() */
343 extern guint8* tvb_memdup(tvbuff_t*, gint offset, gint length);
344
345 /* Same as above but the buffer returned from this function does not have to
346 * be freed. It will be automatically freed after the packet is dissected.
347 * Buffers allocated by this function are NOT persistent.
348 */
349 extern guint8* ep_tvb_memdup(tvbuff_t *tvb, gint offset, gint length);
350
351 /** WARNING! This function is possibly expensive, temporarily allocating
352  * another copy of the packet data. Furthermore, it's dangerous because once
353  * this pointer is given to the user, there's no guarantee that the user will
354  * honor the 'length' and not overstep the boundaries of the buffer.
355  *
356  * The returned pointer is data that is internal to the tvbuff, so do not
357  * attempt to free it. Don't modify the data, either, because another tvbuff
358  * that might be using this tvbuff may have already copied that portion of
359  * the data (sometimes tvbuff's need to make copies of data, but that's the
360  * internal implementation that you need not worry about). Assume that the
361  * guint8* points to read-only data that the tvbuff manages.
362  *
363  * Return a pointer into our buffer if the data asked for via 'offset'/'length'
364  * is contiguous (which might not be the case for TVBUFF_COMPOSITE). If the
365  * data is not contiguous, a tvb_memdup() is called for the entire buffer
366  * and the pointer to the newly-contiguous data is returned. This dynamically-
367  * allocated memory will be freed when the tvbuff is freed, after the
368  * tvbuff_free_cb_t() is called, if any. */
369 extern const guint8* tvb_get_ptr(tvbuff_t*, gint offset, gint length);
370
371 /** Find first occurence of any of the needles in tvbuff, starting at offset.
372  * Searches at most maxlength number of bytes; if maxlength is -1, searches
373  * to end of tvbuff.
374  * Returns the offset of the found needle, or -1 if not found.
375  * Will not throw an exception, even if maxlength exceeds boundary of tvbuff;
376  * in that case, -1 will be returned if the boundary is reached before
377  * finding needle. */
378 extern gint tvb_find_guint8(tvbuff_t*, gint offset, gint maxlength,
379     guint8 needle);
380
381 /** Find first occurence of any of the needles in tvbuff, starting at offset.
382  * Searches at most maxlength number of bytes. Returns the offset of the
383  * found needle, or -1 if not found. Will not throw an exception, even if
384  * maxlength exceeds boundary of tvbuff; in that case, -1 will be returned if
385  * the boundary is reached before finding needle. */
386 extern gint tvb_pbrk_guint8(tvbuff_t *, gint offset, gint maxlength,
387     guint8 *needles);
388
389 /** Find size of stringz (NUL-terminated string) by looking for terminating
390  * NUL.  The size of the string includes the terminating NUL.
391  *
392  * If the NUL isn't found, it throws the appropriate exception.
393  */
394 extern guint tvb_strsize(tvbuff_t *tvb, gint offset);
395
396 /** Find length of string by looking for end of zero terminated string, up to
397  * 'maxlength' characters'; if 'maxlength' is -1, searches to end
398  * of tvbuff.
399  * Returns -1 if 'maxlength' reached before finding EOS. */
400 extern gint tvb_strnlen(tvbuff_t*, gint offset, guint maxlength);
401
402 /** Convert a string from Unicode to ASCII.  At the moment we fake it by
403  * assuming all characters are ASCII  )-:  The len parameter is the number 
404  * of guint16's to convert from Unicode. 
405  *
406  * tvb_fake_unicode() returns a buffer allocated by g_malloc() and must
407  *                    be g_free() by the caller.
408  * tvb_get_ephemeral_faked_unicode() returns a buffer that does not need
409  *                    to be explicitely freed. Instead this buffer is
410  *                    automatically freed when ethereal starts dissecting
411  *                    the next packet.
412  */
413 extern char *tvb_fake_unicode(tvbuff_t *tvb, int offset, int len,
414                               gboolean little_endian);
415 extern char *tvb_get_ephemeral_faked_unicode(tvbuff_t *tvb, int offset, int len,
416                               gboolean little_endian);
417
418 /**
419  * Format the data in the tvb from offset for size ...
420  */
421 extern gchar * tvb_format_text(tvbuff_t *tvb, gint offset, gint size);
422
423 /**
424  * Like "tvb_format_text()", but for null-padded strings; don't show
425  * the null padding characters as "\000".
426  */
427 extern gchar *tvb_format_stringzpad(tvbuff_t *tvb, gint offset, gint size);
428
429
430 /**
431  * Given a tvbuff, an offset, and a length, allocate a buffer big enough
432  * to hold a non-null-terminated string of that length at that offset,
433  * plus a trailing zero, copy the string into it, and return a pointer
434  * to the string.
435  *
436  * Throws an exception if the tvbuff ends before the string does.
437  *
438  * tvb_get_string()  returns a string allocated by g_malloc() and therefore
439  *                   MUST be g_free() by the caller in order not to leak
440  *                   memory.
441  *
442  * tvb_get_ephemeral_string() returns a string that does not need to be freed,
443  *                   instead it will automatically be freed once the next
444  *                   packet is dissected.
445  */
446 extern guint8 *tvb_get_string(tvbuff_t *tvb, gint offset, gint length);
447 extern guint8 *tvb_get_ephemeral_string(tvbuff_t *tvb, gint offset, gint length);
448
449
450 /**
451  * Given a tvbuff and an offset, with the offset assumed to refer to
452  * a null-terminated string, find the length of that string (and throw
453  * an exception if the tvbuff ends before we find the null), allocate
454  * a buffer big enough to hold the string, copy the string into it,
455  * and return a pointer to the string.  Also return the length of the
456  * string (including the terminating null) through a pointer.
457  *
458  * tvb_get_stringz() returns a string allocated by g_malloc() and therefore
459  *                   MUST be g_free() by the caller in order not to leak
460  *                   memory.
461  *
462  * tvb_get_ephemeral_stringz() returns a string that does not need to be freed,
463  *                   instead it will automatically be freed once the next
464  *                   packet is dissected.
465  */
466 extern guint8 *tvb_get_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
467 extern guint8 *tvb_get_ephemeral_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
468
469 /** Looks for a stringz (NUL-terminated string) in tvbuff and copies
470  * no more than bufsize number of bytes, including terminating NUL, to buffer.
471  * Returns length of string (not including terminating NUL), or -1 if the string was
472  * truncated in the buffer due to not having reached the terminating NUL.
473  * In this way, it acts like g_snprintf().
474  *
475  * When processing a packet where the remaining number of bytes is less
476  * than bufsize, an exception is not thrown if the end of the packet
477  * is reached before the NUL is found. If no NUL is found before reaching
478  * the end of the short packet, -1 is still returned, and the string
479  * is truncated with a NUL, albeit not at buffer[bufsize - 1], but
480  * at the correct spot, terminating the string.
481  */
482 extern gint tvb_get_nstringz(tvbuff_t *tvb, gint offset, guint bufsize,
483     guint8* buffer);
484
485 /** Like tvb_get_nstringz(), but never returns -1. The string is guaranteed to
486  * have a terminating NUL. If the string was truncated when copied into buffer,
487  * a NUL is placed at the end of buffer to terminate it.
488  *
489  * bufsize MUST be greater than 0.
490  */
491 extern gint tvb_get_nstringz0(tvbuff_t *tvb, gint offset, guint bufsize,
492     guint8* buffer);
493
494 /**
495  * Given a tvbuff, an offset into the tvbuff, and a length that starts
496  * at that offset (which may be -1 for "all the way to the end of the
497  * tvbuff"), find the end of the (putative) line that starts at the
498  * specified offset in the tvbuff, going no further than the specified
499  * length.
500  *
501  * Return the length of the line (not counting the line terminator at
502  * the end), or, if we don't find a line terminator:
503  *
504  *      if "deseg" is true, return -1;
505  *
506  *      if "deseg" is false, return the amount of data remaining in
507  *      the buffer.
508  *
509  * Set "*next_offset" to the offset of the character past the line
510  * terminator, or past the end of the buffer if we don't find a line
511  * terminator.  (It's not set if we return -1.)
512  */
513 extern gint tvb_find_line_end(tvbuff_t *tvb, gint offset, int len,
514     gint *next_offset, gboolean desegment);
515
516 /**
517  * Given a tvbuff, an offset into the tvbuff, and a length that starts
518  * at that offset (which may be -1 for "all the way to the end of the
519  * tvbuff"), find the end of the (putative) line that starts at the
520  * specified offset in the tvbuff, going no further than the specified
521  * length.
522  *
523  * However, treat quoted strings inside the buffer specially - don't
524  * treat newlines in quoted strings as line terminators.
525  *
526  * Return the length of the line (not counting the line terminator at
527  * the end), or the amount of data remaining in the buffer if we don't
528  * find a line terminator.
529  *
530  * Set "*next_offset" to the offset of the character past the line
531  * terminator, or past the end of the buffer if we don't find a line
532  * terminator.
533  */
534 extern gint tvb_find_line_end_unquoted(tvbuff_t *tvb, gint offset, int len,
535     gint *next_offset);
536
537 /**
538  * Call strncmp after checking if enough chars left, returning 0 if
539  * it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
540  */
541 extern gint tvb_strneql(tvbuff_t *tvb, gint offset, const gchar *str,
542     gint size);
543
544 /**
545  * Call strncasecmp after checking if enough chars left, returning 0 if
546  * it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
547  */
548 extern gint tvb_strncaseeql(tvbuff_t *tvb, gint offset, const gchar *str,
549     gint size);
550
551 /**
552  * Call memcmp after checking if enough chars left, returning 0 if
553  * it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
554  */
555 extern gint tvb_memeql(tvbuff_t *tvb, gint offset, const guint8 *str,
556     gint size);
557
558 /**
559  * Format a bunch of data from a tvbuff as bytes, returning a pointer
560  * to the string with the formatted data, with "punct" as a byte
561  * separator.
562  */
563 extern gchar *tvb_bytes_to_str_punct(tvbuff_t *tvb, gint offset, gint len,
564     gchar punct);
565
566 /*
567  * Format a bunch of data from a tvbuff as bytes, returning a pointer
568  * to the string with the formatted data.
569  */
570 extern gchar *tvb_bytes_to_str(tvbuff_t *tvb, gint offset, gint len);
571
572 #define TVB_GET_DS_TVB(tvb)             \
573         (tvb->ds_tvb)
574
575 /** Locate a sub-tvbuff within another tvbuff, starting at position
576  * 'haystack_offset'. Returns the index of the beginning of 'needle' within
577  * 'haystack', or -1 if 'needle' is not found. The index is relative
578  * to the start of 'haystack', not 'haystack_offset'. */
579 extern gint tvb_find_tvb(tvbuff_t *haystack_tvb, tvbuff_t *needle_tvb,
580         gint haystack_offset);
581
582 /**
583  * Uncompresses a zlib compressed packet inside a tvbuff at offset with
584  * length comprlen.  Returns an uncompressed tvbuffer if uncompression
585  * succeeded or NULL if uncompression failed.
586  */
587 extern tvbuff_t* tvb_uncompress(tvbuff_t *tvb, int offset, int comprlen);
588
589 /************** END OF ACCESSORS ****************/
590
591 #endif /* __TVBUFF_H__ */