2000-05-11 08:18:09 +00:00
|
|
|
/* tvbuff.h
|
|
|
|
*
|
|
|
|
* Testy, Virtual(-izable) Buffer of guint8*'s
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2000-05-11 08:18:09 +00:00
|
|
|
* "Testy" -- the buffer gets mad when an attempt is made to access data
|
2013-10-31 17:30:22 +00:00
|
|
|
* beyond the bounds of the buffer. An exception is thrown.
|
2000-05-11 08:18:09 +00:00
|
|
|
*
|
|
|
|
* "Virtual" -- the buffer can have its own data, can use a subset of
|
2013-10-31 17:30:22 +00:00
|
|
|
* the data of a backing tvbuff, or can be a composite of
|
|
|
|
* other tvbuffs.
|
2000-05-11 08:18:09 +00:00
|
|
|
*
|
2001-11-13 23:55:44 +00:00
|
|
|
* Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
|
2000-05-11 08:18:09 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2000-05-11 08:18:09 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2000-05-11 08:18:09 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2000-05-11 08:18:09 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 20:41:00 +00:00
|
|
|
*
|
2000-05-11 08:18:09 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2000-05-11 08:18:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TVBUFF_H__
|
|
|
|
#define __TVBUFF_H__
|
|
|
|
|
|
|
|
#include <glib.h>
|
2006-03-10 11:58:22 +00:00
|
|
|
#include <epan/guid-utils.h>
|
2013-09-22 15:50:55 +00:00
|
|
|
#include <epan/wmem/wmem.h>
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2011-12-29 00:08:47 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** @file
|
|
|
|
* "testy, virtual(-izable) buffer". They are testy in that they get mad when
|
|
|
|
* an attempt is made to access data beyond the bounds of their array. In that
|
|
|
|
* case, they throw an exception.
|
2009-08-11 17:53:39 +00:00
|
|
|
*
|
|
|
|
* They are virtualizable in that new tvbuff's can be made from other tvbuffs,
|
|
|
|
* while only the original tvbuff may have data. That is, the new tvbuff has
|
2005-01-07 12:00:01 +00:00
|
|
|
* virtual data.
|
|
|
|
*/
|
|
|
|
|
2011-05-27 03:06:50 +00:00
|
|
|
struct tvbuff;
|
|
|
|
typedef struct tvbuff tvbuff_t;
|
2003-12-02 10:23:18 +00:00
|
|
|
|
2013-11-10 12:31:17 +00:00
|
|
|
struct e_in6_addr; /* ipv6-utils.h */
|
2014-04-12 04:32:20 +00:00
|
|
|
struct nstime_t; /* nstime.h */
|
2013-11-10 12:31:17 +00:00
|
|
|
|
2013-05-30 22:20:21 +00:00
|
|
|
/** @defgroup tvbuff Testy, Virtual(-izable) Buffers
|
|
|
|
*
|
|
|
|
* Dissector use and management
|
2011-12-21 17:39:02 +00:00
|
|
|
*
|
|
|
|
* Consider a collection of tvbs as being a chain or stack of tvbs.
|
|
|
|
*
|
2012-03-16 15:43:56 +00:00
|
|
|
* When dissecting a frame:
|
|
|
|
* The top-level dissector (packet.c) pushes the initial tvb (containing
|
|
|
|
* the complete frame) onto the stack (starts the chain) and then calls
|
|
|
|
* a sub-dissector which in turn calls the next sub-dissector and so on.
|
|
|
|
* Each sub-dissector may chain additional tvbs (see below) to the tvb
|
|
|
|
* handed to that dissector. After dissection is complete and control has
|
|
|
|
* returned to the top-level dissector, the chain of tvbs (stack) is free'd
|
|
|
|
* via a call to tvb_free_chain() (in epan_dissect_cleanup()).
|
2011-12-21 17:39:02 +00:00
|
|
|
*
|
|
|
|
* A dissector:
|
2012-03-16 15:43:56 +00:00
|
|
|
* - Can chain new tvbs (subset, real, composite) to the
|
|
|
|
* tvb handed to the dissector using tvb_new_subset(),
|
When we're dissecting the beginning of a fragmented packet that we
haven't reassembled, we're probably moving sequentially through the
packet, which means that we'll run past the end of the fragment rather
than past the end of what would have been the reassembled packet had we
reassembled it.
I.e., there's little reason to care whether we're past the end of the
fragment but not past the end of the packet, or whether we're past the
end of the packet; in either case, we're past the end of the fragment,
and if somebody wants to know whether the packet is malformed by
stopping short of certain fields, they should enable reassembly.
So we get rid of the explicit fragment length in tvbuffs and, instead,
have a "this is a fragment" flag; if that flag is set, we throw
FragmentBoundsError rather than ReportedBoundsError if we run past the
end of the reported data.
(This also means we could flag the tvbuff even if we don't know how
large the reassembled packet will be, e.g. when doing IP reassembly.)
Replace tvb_new_subset_length_fragment() with tvb_new_subset_length()
and a new "set the "this is a fragment flag"" routine.
svn path=/trunk/; revision=48940
2013-04-20 02:53:57 +00:00
|
|
|
* tvb_new_subset_length(), tvb_new_subset_remaining(),
|
|
|
|
* tvb_new_child_real_data(), tvb_set_child_real_data_tvbuff(),
|
|
|
|
* tvb_composite_finalize(), and tvb_child_uncompress(). (Composite
|
|
|
|
* tvbs should reference only tvbs which are already part of the chain).
|
2012-03-16 15:43:56 +00:00
|
|
|
* - Must not save for later use (e.g., when dissecting another frame) a
|
|
|
|
* pointer to a tvb handed to the dissector; (A higher level function
|
|
|
|
* may very well free the chain thus leaving a dangling pointer).
|
|
|
|
* This (obviously) also applies to any tvbs chained to the tvb handed
|
|
|
|
* to the dissector.
|
|
|
|
* - Can create its own tvb chain (using tvb_new_real_data() which the
|
2013-05-30 22:20:21 +00:00
|
|
|
*
|
|
|
|
* dissector is free to manage as desired.
|
|
|
|
* @{
|
|
|
|
*/
|
2011-12-21 17:39:02 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** TVBUFF_REAL_DATA contains a guint8* that points to real data.
|
2000-05-11 08:18:09 +00:00
|
|
|
* The data is allocated and contiguous.
|
|
|
|
*
|
|
|
|
* TVBUFF_SUBSET has a backing tvbuff. The TVBUFF_SUBSET is a "window"
|
|
|
|
* through which the program sees only a portion of the backing tvbuff.
|
|
|
|
*
|
2013-10-31 17:30:22 +00:00
|
|
|
* TVBUFF_COMPOSITE combines multiple tvbuffs sequentially to produce
|
2000-05-11 08:18:09 +00:00
|
|
|
* a larger byte array.
|
|
|
|
*
|
|
|
|
* tvbuff's of any type can be used as the backing-tvbuff of a
|
|
|
|
* TVBUFF_SUBSET or as the member of a TVBUFF_COMPOSITE.
|
|
|
|
* TVBUFF_COMPOSITEs can have member-tvbuffs of different types.
|
|
|
|
*
|
|
|
|
* Once a tvbuff is create/initialized/finalized, the tvbuff is read-only.
|
|
|
|
* That is, it cannot point to any other data. A new tvbuff must be created if
|
|
|
|
* you want a tvbuff that points to other data.
|
2011-12-21 17:39:02 +00:00
|
|
|
*
|
2013-10-31 17:30:22 +00:00
|
|
|
* tvbuff's are normally chained together to allow efficient de-allocation of
|
|
|
|
* tvbuff's.
|
2000-05-11 08:18:09 +00:00
|
|
|
*/
|
|
|
|
|
2011-05-27 03:06:50 +00:00
|
|
|
typedef void (*tvbuff_free_cb_t)(void*);
|
|
|
|
|
2011-12-21 17:39:02 +00:00
|
|
|
/** Extracts 'number of bits' starting at 'bit offset'.
|
2013-08-31 15:30:07 +00:00
|
|
|
* Returns a pointer to a newly initialized g_malloc'd REAL_DATA
|
2011-12-21 17:39:02 +00:00
|
|
|
* tvbuff with the bits octet aligned.
|
2011-09-26 15:11:14 +00:00
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_new_octet_aligned(tvbuff_t *tvb,
|
|
|
|
guint32 bit_offset, gint32 no_of_bits);
|
2011-09-26 15:11:14 +00:00
|
|
|
|
2013-07-14 14:42:05 +00:00
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_new_chain(tvbuff_t *parent, tvbuff_t *backing);
|
|
|
|
|
2013-07-13 17:53:33 +00:00
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_clone(tvbuff_t *tvb);
|
|
|
|
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_clone_offset_len(tvbuff_t *tvb, guint offset,
|
|
|
|
guint len);
|
2013-07-13 17:53:33 +00:00
|
|
|
|
2011-12-21 17:39:02 +00:00
|
|
|
/** Free a tvbuff_t and all tvbuffs chained from it
|
|
|
|
* The tvbuff must be 'the 'head' (initial) tvb of a chain or
|
|
|
|
* must not be in a chain.
|
|
|
|
* If specified, a callback to free the tvbuff data will be invoked
|
|
|
|
* for each tvbuff free'd */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void tvb_free(tvbuff_t *tvb);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2011-12-21 17:39:02 +00:00
|
|
|
/** Free the tvbuff_t and all tvbuffs chained from it.
|
|
|
|
* The tvbuff must be 'the 'head' (initial) tvb of a chain or
|
|
|
|
* must not be in a chain.
|
|
|
|
* If specified, a callback to free the tvbuff data will be invoked
|
|
|
|
* for each tvbuff free'd */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void tvb_free_chain(tvbuff_t *tvb);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Set a callback function to call when a tvbuff is actually freed
|
2011-12-21 17:39:02 +00:00
|
|
|
* One argument is passed to that callback --- a void* that points
|
|
|
|
* to the real data. Obviously, this only applies to a
|
|
|
|
* TVBUFF_REAL_DATA tvbuff. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void tvb_set_free_cb(tvbuff_t *tvb, const tvbuff_free_cb_t func);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Attach a TVBUFF_REAL_DATA tvbuff to a parent tvbuff. This connection
|
2000-11-14 04:33:34 +00:00
|
|
|
* is used during a tvb_free_chain()... the "child" TVBUFF_REAL_DATA acts
|
2013-12-22 15:47:17 +00:00
|
|
|
* as if it is part of the chain-of-creation of the parent tvbuff, although it
|
2000-11-14 04:33:34 +00:00
|
|
|
* isn't. This is useful if you need to take the data from some tvbuff,
|
|
|
|
* run some operation on it, like decryption or decompression, and make a new
|
|
|
|
* tvbuff from it, yet want the new tvbuff to be part of the chain. The reality
|
|
|
|
* is that the new tvbuff *is* part of the "chain of creation", but in a way
|
2011-12-21 17:39:02 +00:00
|
|
|
* that these tvbuff routines are ignorant of. Use this function to make
|
2000-11-14 04:33:34 +00:00
|
|
|
* the tvbuff routines knowledgable of this fact. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void tvb_set_child_real_data_tvbuff(tvbuff_t *parent,
|
|
|
|
tvbuff_t *child);
|
2000-11-14 04:33:34 +00:00
|
|
|
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_new_child_real_data(tvbuff_t *parent,
|
|
|
|
const guint8 *data, const guint length, const gint reported_length);
|
2009-04-01 16:22:51 +00:00
|
|
|
|
2013-02-20 00:09:41 +00:00
|
|
|
/** Create a tvbuff backed by existing data. Can throw ReportedBoundsError.
|
2013-10-31 17:30:22 +00:00
|
|
|
* Normally, a callback to free the data should be registered using
|
|
|
|
* tvb_set_free_cb(); when this tvbuff is freed, then your callback will be
|
|
|
|
* called, and at that time you can free your original data. */
|
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_new_real_data(const guint8 *data,
|
|
|
|
const guint length, const gint reported_length);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2013-02-20 00:09:41 +00:00
|
|
|
/** Create a tvbuff that's a subset of another tvbuff.
|
2000-05-11 08:18:09 +00:00
|
|
|
*
|
2013-02-20 00:09:41 +00:00
|
|
|
* 'backing_offset', if positive, is the offset from the beginning of
|
|
|
|
* the backing tvbuff at which the new tvbuff's data begins, and, if
|
|
|
|
* negative, is the offset from the end of the backing tvbuff at which
|
|
|
|
* the new tvbuff's data begins.
|
2000-05-11 08:18:09 +00:00
|
|
|
*
|
2013-02-20 00:09:41 +00:00
|
|
|
* 'backing_length' is the length of the data to include in the new
|
|
|
|
* tvbuff, starting with the byte at 'backing_offset"; if -1, it
|
|
|
|
* means "to the end of the backing tvbuff". It can be 0, although
|
|
|
|
* the usefulness of the buffer would be rather limited.
|
2000-05-11 08:18:09 +00:00
|
|
|
*
|
|
|
|
* Will throw BoundsError if 'backing_offset'/'length'
|
2000-09-13 20:17:23 +00:00
|
|
|
* is beyond the bounds of the backing tvbuff.
|
|
|
|
* Can throw ReportedBoundsError. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_new_subset(tvbuff_t *backing,
|
|
|
|
const gint backing_offset, const gint backing_length,
|
|
|
|
const gint reported_length);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
When we're dissecting the beginning of a fragmented packet that we
haven't reassembled, we're probably moving sequentially through the
packet, which means that we'll run past the end of the fragment rather
than past the end of what would have been the reassembled packet had we
reassembled it.
I.e., there's little reason to care whether we're past the end of the
fragment but not past the end of the packet, or whether we're past the
end of the packet; in either case, we're past the end of the fragment,
and if somebody wants to know whether the packet is malformed by
stopping short of certain fields, they should enable reassembly.
So we get rid of the explicit fragment length in tvbuffs and, instead,
have a "this is a fragment" flag; if that flag is set, we throw
FragmentBoundsError rather than ReportedBoundsError if we run past the
end of the reported data.
(This also means we could flag the tvbuff even if we don't know how
large the reassembled packet will be, e.g. when doing IP reassembly.)
Replace tvb_new_subset_length_fragment() with tvb_new_subset_length()
and a new "set the "this is a fragment flag"" routine.
svn path=/trunk/; revision=48940
2013-04-20 02:53:57 +00:00
|
|
|
/**
|
|
|
|
* Similar to tvb_new_subset() but with captured length calculated
|
2013-04-18 19:22:24 +00:00
|
|
|
* to fit within the existing captured length and the specified
|
When we're dissecting the beginning of a fragmented packet that we
haven't reassembled, we're probably moving sequentially through the
packet, which means that we'll run past the end of the fragment rather
than past the end of what would have been the reassembled packet had we
reassembled it.
I.e., there's little reason to care whether we're past the end of the
fragment but not past the end of the packet, or whether we're past the
end of the packet; in either case, we're past the end of the fragment,
and if somebody wants to know whether the packet is malformed by
stopping short of certain fields, they should enable reassembly.
So we get rid of the explicit fragment length in tvbuffs and, instead,
have a "this is a fragment" flag; if that flag is set, we throw
FragmentBoundsError rather than ReportedBoundsError if we run past the
end of the reported data.
(This also means we could flag the tvbuff even if we don't know how
large the reassembled packet will be, e.g. when doing IP reassembly.)
Replace tvb_new_subset_length_fragment() with tvb_new_subset_length()
and a new "set the "this is a fragment flag"" routine.
svn path=/trunk/; revision=48940
2013-04-20 02:53:57 +00:00
|
|
|
* backing length (which is used as the reported length).
|
2013-02-20 08:10:14 +00:00
|
|
|
* Can throw ReportedBoundsError. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_new_subset_length(tvbuff_t *backing,
|
|
|
|
const gint backing_offset, const gint backing_length);
|
2013-02-20 08:10:14 +00:00
|
|
|
|
2013-10-31 17:30:22 +00:00
|
|
|
/** Similar to tvb_new_subset() but with backing_length and reported_length set
|
|
|
|
* to -1. Can throw ReportedBoundsError. */
|
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_new_subset_remaining(tvbuff_t *backing,
|
|
|
|
const gint backing_offset);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2013-03-01 23:53:11 +00:00
|
|
|
/*
|
|
|
|
* Both tvb_composite_append and tvb_composite_prepend can throw
|
2000-05-11 08:18:09 +00:00
|
|
|
* BoundsError if member_offset/member_length goes beyond bounds of
|
|
|
|
* the 'member' tvbuff. */
|
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Append to the list of tvbuffs that make up this composite tvbuff */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void tvb_composite_append(tvbuff_t *tvb, tvbuff_t *member);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Prepend to the list of tvbuffs that make up this composite tvbuff */
|
2013-10-31 17:30:22 +00:00
|
|
|
extern void tvb_composite_prepend(tvbuff_t *tvb, tvbuff_t *member);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2013-02-20 00:57:10 +00:00
|
|
|
/** Create an empty composite tvbuff. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_new_composite(void);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Mark a composite tvbuff as initialized. No further appends or prepends
|
2000-05-11 08:18:09 +00:00
|
|
|
* occur, data access can finally happen after this finalization. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void tvb_composite_finalize(tvbuff_t *tvb);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
|
|
|
|
2014-02-22 13:39:57 +00:00
|
|
|
/* Get amount of captured data in the buffer (which is *NOT* necessarily the
|
|
|
|
* length of the packet). You probably want tvb_reported_length instead. */
|
|
|
|
WS_DLL_PUBLIC guint tvb_captured_length(const tvbuff_t *tvb);
|
|
|
|
|
|
|
|
/* DEPRECATED, do not use in new code, call tvb_captured_length directly! */
|
|
|
|
#define tvb_length tvb_captured_length
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Computes bytes to end of buffer, from offset (which can be negative,
|
2013-11-03 18:02:17 +00:00
|
|
|
* to indicate bytes from end of buffer). Function returns 0 if offset is
|
2014-02-22 13:39:57 +00:00
|
|
|
* either at the end of the buffer or out of bounds. No exception is thrown.
|
|
|
|
* You probably want tvb_reported_length_remaining instead. */
|
|
|
|
WS_DLL_PUBLIC gint tvb_captured_length_remaining(const tvbuff_t *tvb, const gint offset);
|
|
|
|
|
|
|
|
/* DEPRECATED, do not use in new code, call tvb_captured_length_remaining directly! */
|
|
|
|
#define tvb_length_remaining tvb_captured_length_remaining
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Same as above, but throws an exception if the offset is out of bounds. */
|
2014-02-22 13:39:57 +00:00
|
|
|
WS_DLL_PUBLIC guint tvb_ensure_captured_length_remaining(const tvbuff_t *tvb,
|
2013-10-31 17:30:22 +00:00
|
|
|
const gint offset);
|
2002-02-01 04:34:17 +00:00
|
|
|
|
2014-02-22 13:39:57 +00:00
|
|
|
/* DEPRECATED, do not use in new code, call tvb_ensure_captured_length_remaining directly! */
|
|
|
|
#define tvb_ensure_length_remaining tvb_ensure_captured_length_remaining
|
|
|
|
|
Put "extern" in front of a pile of function declarations.
It makes no difference if they really are function declarations;
however, in plugins, when building on OSes that don't let
dynamically-loaded modules access functions in the main program (e.g.,
Windows), when compiling a plugin, <plugin_api.h> defines the names of
those functions as (*pointer_name), so they turn into declarations of
pointer variables pointing to the functions in question, and, on
platforms with a def/ref model in the linker, if a plugin has more than
one source file that gets linked into the plugin, the linker may get
upset at two definitions of the same variable.
svn path=/trunk/; revision=4114
2001-10-31 07:47:27 +00:00
|
|
|
/* Checks (w/o throwing exception) that the bytes referred to by
|
|
|
|
* 'offset'/'length' actually exist in the buffer */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gboolean tvb_bytes_exist(const tvbuff_t *tvb, const gint offset,
|
|
|
|
const gint length);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Checks that the bytes referred to by 'offset'/'length' actually exist
|
2002-05-13 01:24:47 +00:00
|
|
|
* in the buffer, and throws an exception if they aren't. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void tvb_ensure_bytes_exist(const tvbuff_t *tvb,
|
|
|
|
const gint offset, const gint length);
|
2002-05-13 01:24:47 +00:00
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
/* Checks (w/o throwing exception) that offset exists in buffer */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gboolean tvb_offset_exists(const tvbuff_t *tvb,
|
|
|
|
const gint offset);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
Add "tvb_reported_length()" to get the "reported length" of a tvbuff
(i.e., the amount of data that was in the packet, even if not all of it
was captured), for use when dissecting packets containing data that
fills the packet (we want the dissector to try to dissect all of it; if
it runs past the end of the captured data, we want it to throw an
exception so that we'll put a "Short Frame" note in the protocol tree).
This means we always want a tvbuff to have a real reported length value,
so we make it an unsigned integer, and don't bother checking it for -1,
as it should never be -1.
If the reported length passed in to "tvb_set_subset()" is -1, set the
reported length to the reported length of the tvbuff of which the new
tvbuff will be a subset minus the offset in that tvbuff of the subset,
so that "-1" means "what's left of the packet after we chop off the
header". This is necessary in order to ensure that all tvbuffs have a
real reported length value.
Have "dissect_packet()" set the reported length of the top-level tvbuff
to the reported length of the frame, so that we start out with a tvbuff
with a real reported length value.
Have "tvb_offset_exists()" return FALSE if the offset is past the end of
the tvbuff.
If the offset passed to it is postitive, have "compute_offset_length()"
check for that it's not more than one byte past the end of the tvbuff -
if it's just past the end, we don't want the check to fail, as we don't
want attempts to create a subset tvbuff containing zero bytes to fail;
that would be done if a captured packet was all header and no payload,
and we'd want the dissector of the payload, not the dissector of the
header, to throw an exception, as the problem isn't with the protocol
for the header, it's with the protocol for the payload.
Convert the ATM dissector, the SSCOP dissector, the Q.2931 dissector,
and the Q.931 dissector to use tvbuffs.
Make the LAPD dissector set up a tvbuff for the Q.931 dissector (it's
not converted yet).
svn path=/trunk/; revision=2023
2000-05-29 08:57:42 +00:00
|
|
|
/* Get reported length of buffer */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint tvb_reported_length(const tvbuff_t *tvb);
|
Add "tvb_reported_length()" to get the "reported length" of a tvbuff
(i.e., the amount of data that was in the packet, even if not all of it
was captured), for use when dissecting packets containing data that
fills the packet (we want the dissector to try to dissect all of it; if
it runs past the end of the captured data, we want it to throw an
exception so that we'll put a "Short Frame" note in the protocol tree).
This means we always want a tvbuff to have a real reported length value,
so we make it an unsigned integer, and don't bother checking it for -1,
as it should never be -1.
If the reported length passed in to "tvb_set_subset()" is -1, set the
reported length to the reported length of the tvbuff of which the new
tvbuff will be a subset minus the offset in that tvbuff of the subset,
so that "-1" means "what's left of the packet after we chop off the
header". This is necessary in order to ensure that all tvbuffs have a
real reported length value.
Have "dissect_packet()" set the reported length of the top-level tvbuff
to the reported length of the frame, so that we start out with a tvbuff
with a real reported length value.
Have "tvb_offset_exists()" return FALSE if the offset is past the end of
the tvbuff.
If the offset passed to it is postitive, have "compute_offset_length()"
check for that it's not more than one byte past the end of the tvbuff -
if it's just past the end, we don't want the check to fail, as we don't
want attempts to create a subset tvbuff containing zero bytes to fail;
that would be done if a captured packet was all header and no payload,
and we'd want the dissector of the payload, not the dissector of the
header, to throw an exception, as the problem isn't with the protocol
for the header, it's with the protocol for the payload.
Convert the ATM dissector, the SSCOP dissector, the Q.2931 dissector,
and the Q.931 dissector to use tvbuffs.
Make the LAPD dissector set up a tvbuff for the Q.931 dissector (it's
not converted yet).
svn path=/trunk/; revision=2023
2000-05-29 08:57:42 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Computes bytes of reported packet data to end of buffer, from offset
|
2000-12-27 12:48:27 +00:00
|
|
|
* (which can be negative, to indicate bytes from end of buffer). Function
|
2013-11-03 18:02:17 +00:00
|
|
|
* returns 0 if offset is either at the end of the buffer or out of bounds.
|
|
|
|
* No exception is thrown. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_reported_length_remaining(const tvbuff_t *tvb,
|
|
|
|
const gint offset);
|
2000-12-27 12:48:27 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Set the reported length of a tvbuff to a given value; used for protocols
|
Tvbuffify the IP, ICMP, TCP, UDP, OSI CLNP, OSI COTP, OSI CLTP, and OSI
ESIS dissectors.
Register the IP dissector and have dissectors that call it directly
(rather than through a port table) call it through a handle.
Add a routine "tvb_set_reported_length()" which a dissector can use if
it was handed a tvbuff that contains more data than is actually in its
part of the packet - for example, handing a padded Ethernet frame to IP;
the routine sets the reported length of the tvbuff (and also adjusts the
actual length, as appropriate). Then use it in IP.
Given that, "ethertype()" can determine how much of the Ethernet frame
was actually part of an IP datagram (and can do the same for other
protocols under Ethernet that use "tvb_set_reported_length()"; have it
return the actual length, and have "dissect_eth()" and "dissect_vlan()"
use that to mark trailer data in Ethernet II frames as well as in 802.3
frames.
svn path=/trunk/; revision=2658
2000-11-18 10:38:33 +00:00
|
|
|
whose headers contain an explicit length and where the calling
|
|
|
|
dissector's payload may include padding as well as the packet for
|
|
|
|
this protocol.
|
|
|
|
|
|
|
|
Also adjusts the data length. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void tvb_set_reported_length(tvbuff_t *tvb, const guint);
|
Tvbuffify the IP, ICMP, TCP, UDP, OSI CLNP, OSI COTP, OSI CLTP, and OSI
ESIS dissectors.
Register the IP dissector and have dissectors that call it directly
(rather than through a port table) call it through a handle.
Add a routine "tvb_set_reported_length()" which a dissector can use if
it was handed a tvbuff that contains more data than is actually in its
part of the packet - for example, handing a padded Ethernet frame to IP;
the routine sets the reported length of the tvbuff (and also adjusts the
actual length, as appropriate). Then use it in IP.
Given that, "ethertype()" can determine how much of the Ethernet frame
was actually part of an IP datagram (and can do the same for other
protocols under Ethernet that use "tvb_set_reported_length()"; have it
return the actual length, and have "dissect_eth()" and "dissect_vlan()"
use that to mark trailer data in Ethernet II frames as well as in 802.3
frames.
svn path=/trunk/; revision=2658
2000-11-18 10:38:33 +00:00
|
|
|
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC guint tvb_offset_from_real_beginning(const tvbuff_t *tvb);
|
2003-12-03 09:50:40 +00:00
|
|
|
|
2001-11-20 22:46:12 +00:00
|
|
|
/* Returns the offset from the first byte of real data. */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_raw_offset(tvbuff_t *tvb);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
When we're dissecting the beginning of a fragmented packet that we
haven't reassembled, we're probably moving sequentially through the
packet, which means that we'll run past the end of the fragment rather
than past the end of what would have been the reassembled packet had we
reassembled it.
I.e., there's little reason to care whether we're past the end of the
fragment but not past the end of the packet, or whether we're past the
end of the packet; in either case, we're past the end of the fragment,
and if somebody wants to know whether the packet is malformed by
stopping short of certain fields, they should enable reassembly.
So we get rid of the explicit fragment length in tvbuffs and, instead,
have a "this is a fragment" flag; if that flag is set, we throw
FragmentBoundsError rather than ReportedBoundsError if we run past the
end of the reported data.
(This also means we could flag the tvbuff even if we don't know how
large the reassembled packet will be, e.g. when doing IP reassembly.)
Replace tvb_new_subset_length_fragment() with tvb_new_subset_length()
and a new "set the "this is a fragment flag"" routine.
svn path=/trunk/; revision=48940
2013-04-20 02:53:57 +00:00
|
|
|
/** Set the "this is a fragment" flag. */
|
|
|
|
WS_DLL_PUBLIC void tvb_set_fragment(tvbuff_t *tvb);
|
|
|
|
|
|
|
|
WS_DLL_PUBLIC struct tvbuff *tvb_get_ds_tvb(tvbuff_t *tvb);
|
|
|
|
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
/************** START OF ACCESSORS ****************/
|
2002-05-13 01:24:47 +00:00
|
|
|
/* All accessors will throw an exception if appropriate */
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint8 tvb_get_guint8(tvbuff_t *tvb, const gint offset);
|
|
|
|
|
|
|
|
WS_DLL_PUBLIC guint16 tvb_get_ntohs(tvbuff_t *tvb, const gint offset);
|
|
|
|
WS_DLL_PUBLIC guint32 tvb_get_ntoh24(tvbuff_t *tvb, const gint offset);
|
|
|
|
WS_DLL_PUBLIC guint32 tvb_get_ntohl(tvbuff_t *tvb, const gint offset);
|
|
|
|
WS_DLL_PUBLIC guint64 tvb_get_ntoh40(tvbuff_t *tvb, const gint offset);
|
2013-12-17 16:50:33 +00:00
|
|
|
WS_DLL_PUBLIC gint64 tvb_get_ntohi40(tvbuff_t *tvb, const gint offset);
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint64 tvb_get_ntoh48(tvbuff_t *tvb, const gint offset);
|
2013-12-17 16:50:33 +00:00
|
|
|
WS_DLL_PUBLIC gint64 tvb_get_ntohi48(tvbuff_t *tvb, const gint offset);
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint64 tvb_get_ntoh56(tvbuff_t *tvb, const gint offset);
|
2013-12-17 16:50:33 +00:00
|
|
|
WS_DLL_PUBLIC gint64 tvb_get_ntohi56(tvbuff_t *tvb, const gint offset);
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint64 tvb_get_ntoh64(tvbuff_t *tvb, const gint offset);
|
|
|
|
WS_DLL_PUBLIC gfloat tvb_get_ntohieee_float(tvbuff_t *tvb, const gint offset);
|
|
|
|
WS_DLL_PUBLIC gdouble tvb_get_ntohieee_double(tvbuff_t *tvb,
|
|
|
|
const gint offset);
|
|
|
|
|
|
|
|
WS_DLL_PUBLIC guint16 tvb_get_letohs(tvbuff_t *tvb, const gint offset);
|
|
|
|
WS_DLL_PUBLIC guint32 tvb_get_letoh24(tvbuff_t *tvb, const gint offset);
|
|
|
|
WS_DLL_PUBLIC guint32 tvb_get_letohl(tvbuff_t *tvb, const gint offset);
|
|
|
|
WS_DLL_PUBLIC guint64 tvb_get_letoh40(tvbuff_t *tvb, const gint offset);
|
2013-12-17 16:50:33 +00:00
|
|
|
WS_DLL_PUBLIC gint64 tvb_get_letohi40(tvbuff_t *tvb, const gint offset);
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint64 tvb_get_letoh48(tvbuff_t *tvb, const gint offset);
|
2013-12-17 16:50:33 +00:00
|
|
|
WS_DLL_PUBLIC gint64 tvb_get_letohi48(tvbuff_t *tvb, const gint offset);
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint64 tvb_get_letoh56(tvbuff_t *tvb, const gint offset);
|
2013-12-17 16:50:33 +00:00
|
|
|
WS_DLL_PUBLIC gint64 tvb_get_letohi56(tvbuff_t *tvb, const gint offset);
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint64 tvb_get_letoh64(tvbuff_t *tvb, const gint offset);
|
|
|
|
WS_DLL_PUBLIC gfloat tvb_get_letohieee_float(tvbuff_t *tvb, const gint offset);
|
|
|
|
WS_DLL_PUBLIC gdouble tvb_get_letohieee_double(tvbuff_t *tvb,
|
|
|
|
const gint offset);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2014-02-09 03:09:41 +00:00
|
|
|
/*
|
|
|
|
* Fetch 16-bit and 32-bit values in host byte order.
|
|
|
|
* Used for some pseudo-headers in pcap/pcap-ng files, in which the
|
|
|
|
* headers are, when capturing, in the byte order of the host, and
|
|
|
|
* are converted to the byte order of the host reading the file
|
|
|
|
* when reading a capture file.
|
|
|
|
*/
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2014-04-03 03:59:19 +00:00
|
|
|
#define tvb_get_h_guint16 tvb_get_letohs
|
|
|
|
#define tvb_get_h_guint32 tvb_get_letohl
|
2014-02-09 03:09:41 +00:00
|
|
|
#elif G_BYTE_ORDER == G_BIG_ENDIAN
|
2014-04-03 03:59:19 +00:00
|
|
|
#define tvb_get_h_guint16 tvb_get_ntohs
|
|
|
|
#define tvb_get_h_guint32 tvb_get_ntohl
|
2014-02-09 03:09:41 +00:00
|
|
|
#else
|
|
|
|
#error "Unsupported byte order"
|
|
|
|
#endif
|
|
|
|
|
2014-04-12 04:32:20 +00:00
|
|
|
|
|
|
|
/* Fetch a time value from an ASCII-style string in the tvb.
|
|
|
|
*
|
|
|
|
* @param[in] offset The beginning offset in the tvb (cannot be negative)
|
|
|
|
* @param[in] length The field's length in the tvb (or -1 for remaining)
|
|
|
|
* @param[in] encoding The ENC_* that defines the format (e.g., ENC_ISO_8601_DATE_TIME)
|
|
|
|
* @param[in,out] ns The pre-allocated nstime_t that will be set to the decoded value
|
|
|
|
* @param[out] endoff if not NULL, should point to a gint that this
|
|
|
|
* routine will then set to be the offset to the character after
|
|
|
|
* the last character used in the conversion. This is useful because
|
|
|
|
* they may not consume the whole section.
|
|
|
|
*
|
|
|
|
* @return a pointer to the nstime_t passed-in, or NULL on failure; if no
|
|
|
|
* valid conversion could be performed, *endoff is set to 0, and errno will be
|
|
|
|
* EDOM or ERANGE, and the nstime_t* passed-in will be cleared.
|
|
|
|
*
|
|
|
|
* @note The conversion ignores leading spaces, and will succeed even if it does
|
|
|
|
* not consume the entire string. If you care about such things, always compare
|
|
|
|
* the *endoff to where you expect it to be (namely, offset+length).
|
|
|
|
*
|
|
|
|
* This routine will not throw an error unless the passed-in arguments are
|
|
|
|
* invalid (e.g., offset is beyond the tvb's length).
|
|
|
|
*
|
|
|
|
* @warning This only works for string encodings which encode ASCII characters in
|
|
|
|
* a single byte: ENC_ASCII, ENC_UTF_8, ENC_ISO_8859_*, etc. It does NOT work
|
|
|
|
* for purely multi-byte encodings such as ENC_UTF_16, ENC_UCS_*, etc.
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC
|
|
|
|
struct nstime_t* tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length,
|
|
|
|
const guint encoding, struct nstime_t* ns, gint *endoff);
|
|
|
|
|
2014-04-13 03:20:15 +00:00
|
|
|
/* Similar to above, but returns a GByteArray based on the case-insensitive
|
|
|
|
* hex-char strings with optional separators, and with optional leading spaces.
|
|
|
|
* The separators allowed are based on the ENC_SEP_* passed in the encoding param.
|
|
|
|
*
|
|
|
|
* The passed-in bytes is set to the values, and its pointer is also the return
|
|
|
|
* value or NULL on error. The GByteArray bytes must be pre-constructed with
|
|
|
|
* g_byte_array_new().
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC
|
|
|
|
GByteArray* tvb_get_string_bytes(tvbuff_t *tvb, const gint offset, const gint length,
|
|
|
|
const guint encoding, GByteArray* bytes, gint *endoff);
|
|
|
|
|
2005-09-10 19:43:41 +00:00
|
|
|
/**
|
|
|
|
* Fetch an IPv4 address, in network byte order.
|
|
|
|
* We do *not* convert it to host byte order; we leave it in
|
|
|
|
* network byte order, as that's what its callers expect. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint32 tvb_get_ipv4(tvbuff_t *tvb, const gint offset);
|
2005-09-10 19:43:41 +00:00
|
|
|
|
|
|
|
/* Fetch an IPv6 address. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void tvb_get_ipv6(tvbuff_t *tvb, const gint offset,
|
|
|
|
struct e_in6_addr *addr);
|
2005-09-10 19:43:41 +00:00
|
|
|
|
2006-03-10 11:58:22 +00:00
|
|
|
/* Fetch a GUID. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void tvb_get_ntohguid(tvbuff_t *tvb, const gint offset,
|
|
|
|
e_guid_t *guid);
|
|
|
|
WS_DLL_PUBLIC void tvb_get_letohguid(tvbuff_t *tvb, const gint offset,
|
|
|
|
e_guid_t *guid);
|
|
|
|
WS_DLL_PUBLIC void tvb_get_guid(tvbuff_t *tvb, const gint offset,
|
|
|
|
e_guid_t *guid, const guint representation);
|
2006-03-10 11:58:22 +00:00
|
|
|
|
2013-10-31 17:30:22 +00:00
|
|
|
/* Fetch a specified number of bits from bit offset in a tvb. All of these
|
|
|
|
* functions are equivalent, except for the type of the return value. Note
|
|
|
|
* that the parameter encoding (where supplied) is meaningless and ignored */
|
2012-02-28 16:29:07 +00:00
|
|
|
|
|
|
|
/* get 1 - 8 bits returned in a guint8 */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint8 tvb_get_bits8(tvbuff_t *tvb, guint bit_offset,
|
|
|
|
const gint no_of_bits);
|
2012-02-28 16:29:07 +00:00
|
|
|
/* get 1 - 16 bits returned in a guint16 */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint16 tvb_get_bits16(tvbuff_t *tvb, guint bit_offset,
|
|
|
|
const gint no_of_bits, const guint encoding);
|
2012-02-28 16:29:07 +00:00
|
|
|
/* get 1 - 32 bits returned in a guint32 */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint32 tvb_get_bits32(tvbuff_t *tvb, guint bit_offset,
|
|
|
|
const gint no_of_bits, const guint encoding);
|
2012-02-28 16:29:07 +00:00
|
|
|
/* get 1 - 64 bits returned in a guint64 */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint64 tvb_get_bits64(tvbuff_t *tvb, guint bit_offset,
|
|
|
|
const gint no_of_bits, const guint encoding);
|
2006-03-10 11:58:22 +00:00
|
|
|
|
2011-12-21 17:39:02 +00:00
|
|
|
/**
|
2013-10-31 17:30:22 +00:00
|
|
|
* This function has EXACTLY the same behavior as
|
2012-02-28 16:29:07 +00:00
|
|
|
* tvb_get_bits32()
|
2009-11-14 20:13:43 +00:00
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint32 tvb_get_bits(tvbuff_t *tvb, const guint bit_offset,
|
|
|
|
const gint no_of_bits, const guint encoding);
|
2009-11-14 20:13:43 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Returns target for convenience. Does not suffer from possible
|
2000-05-11 08:18:09 +00:00
|
|
|
* expense of tvb_get_ptr(), since this routine is smart enough
|
|
|
|
* to copy data in chunks if the request range actually exists in
|
2000-08-17 17:16:02 +00:00
|
|
|
* different TVBUFF_REAL_DATA tvbuffs. This function assumes that the
|
|
|
|
* target memory is already allocated; it does not allocate or free the
|
|
|
|
* target memory. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void *tvb_memcpy(tvbuff_t *tvb, void *target, const gint offset,
|
|
|
|
size_t length);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2014-02-26 22:25:38 +00:00
|
|
|
/** Given an allocator scope, a tvbuff, a byte offset, a byte length:
|
|
|
|
*
|
|
|
|
* allocate a buffer using the specified scope;
|
|
|
|
*
|
|
|
|
* copy the data from the tvbuff specified by the offset and length
|
|
|
|
* into that buffer, using tvb_memcpy();
|
|
|
|
*
|
|
|
|
* and return a pointer to the buffer.
|
|
|
|
*
|
|
|
|
* Throws an exception if the tvbuff ends before the data being copied does.
|
|
|
|
*
|
|
|
|
* If scope is set to NULL it is the user's responsibility to wmem_free()
|
|
|
|
* the memory allocated. Otherwise memory is automatically freed when the
|
|
|
|
* scope lifetime is reached.
|
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC void *tvb_memdup(wmem_allocator_t *scope, tvbuff_t *tvb,
|
|
|
|
const gint offset, size_t length);
|
2005-07-26 18:32:12 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** WARNING! This function is possibly expensive, temporarily allocating
|
2000-05-11 08:18:09 +00:00
|
|
|
* another copy of the packet data. Furthermore, it's dangerous because once
|
|
|
|
* this pointer is given to the user, there's no guarantee that the user will
|
|
|
|
* honor the 'length' and not overstep the boundaries of the buffer.
|
|
|
|
*
|
2009-08-11 17:53:39 +00:00
|
|
|
* If you're thinking of using tvb_get_ptr, STOP WHAT YOU ARE DOING
|
|
|
|
* IMMEDIATELY. Go take a break. Consider that tvb_get_ptr hands you
|
|
|
|
* a raw, unprotected pointer that you can easily use to create a
|
|
|
|
* security vulnerability or otherwise crash Wireshark. Then consider
|
|
|
|
* that you can probably find a function elsewhere in this file that
|
|
|
|
* does exactly what you want in a much more safe and robust manner.
|
|
|
|
*
|
2000-08-17 17:16:02 +00:00
|
|
|
* The returned pointer is data that is internal to the tvbuff, so do not
|
|
|
|
* attempt to free it. Don't modify the data, either, because another tvbuff
|
|
|
|
* that might be using this tvbuff may have already copied that portion of
|
|
|
|
* the data (sometimes tvbuff's need to make copies of data, but that's the
|
|
|
|
* internal implementation that you need not worry about). Assume that the
|
|
|
|
* guint8* points to read-only data that the tvbuff manages.
|
|
|
|
*
|
2000-05-11 08:18:09 +00:00
|
|
|
* Return a pointer into our buffer if the data asked for via 'offset'/'length'
|
|
|
|
* is contiguous (which might not be the case for TVBUFF_COMPOSITE). If the
|
|
|
|
* data is not contiguous, a tvb_memdup() is called for the entire buffer
|
|
|
|
* and the pointer to the newly-contiguous data is returned. This dynamically-
|
|
|
|
* allocated memory will be freed when the tvbuff is freed, after the
|
|
|
|
* tvbuff_free_cb_t() is called, if any. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC const guint8 *tvb_get_ptr(tvbuff_t *tvb, const gint offset,
|
|
|
|
const gint length);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2013-02-26 04:42:26 +00:00
|
|
|
/** Find first occurrence of needle in tvbuff, starting at offset. Searches
|
2012-10-26 16:09:01 +00:00
|
|
|
* at most maxlength number of bytes; if maxlength is -1, searches to
|
|
|
|
* end of tvbuff.
|
2000-11-10 09:15:57 +00:00
|
|
|
* Returns the offset of the found needle, or -1 if not found.
|
|
|
|
* Will not throw an exception, even if maxlength exceeds boundary of tvbuff;
|
|
|
|
* in that case, -1 will be returned if the boundary is reached before
|
|
|
|
* finding needle. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_find_guint8(tvbuff_t *tvb, const gint offset,
|
|
|
|
const gint maxlength, const guint8 needle);
|
2000-08-30 02:50:18 +00:00
|
|
|
|
2013-02-26 04:42:26 +00:00
|
|
|
/** Find first occurrence of any of the needles in tvbuff, starting at offset.
|
2000-11-10 06:50:37 +00:00
|
|
|
* Searches at most maxlength number of bytes. Returns the offset of the
|
2010-03-08 20:45:13 +00:00
|
|
|
* found needle, or -1 if not found and the found needle.
|
|
|
|
* Will not throw an exception, even if
|
2000-11-10 06:50:37 +00:00
|
|
|
* maxlength exceeds boundary of tvbuff; in that case, -1 will be returned if
|
|
|
|
* the boundary is reached before finding needle. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_pbrk_guint8(tvbuff_t *tvb, const gint offset,
|
|
|
|
const gint maxlength, const guint8 *needles, guchar *found_needle);
|
2000-11-10 06:50:37 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Find size of stringz (NUL-terminated string) by looking for terminating
|
2000-12-25 23:48:16 +00:00
|
|
|
* NUL. The size of the string includes the terminating NUL.
|
|
|
|
*
|
|
|
|
* If the NUL isn't found, it throws the appropriate exception.
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC guint tvb_strsize(tvbuff_t *tvb, const gint offset);
|
2000-12-25 23:48:16 +00:00
|
|
|
|
2012-05-14 00:49:05 +00:00
|
|
|
/** Find size of UCS-2 or UTF-16 stringz (NUL-terminated string) by
|
|
|
|
* looking for terminating 16-bit NUL. The size of the string includes
|
|
|
|
* the terminating NUL.
|
|
|
|
*
|
|
|
|
* If the NUL isn't found, it throws the appropriate exception.
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC guint tvb_unicode_strsize(tvbuff_t *tvb, const gint offset);
|
2012-05-14 00:49:05 +00:00
|
|
|
|
2005-09-21 20:11:55 +00:00
|
|
|
/** Find length of string by looking for end of zero terminated string, up to
|
2000-11-10 09:15:57 +00:00
|
|
|
* 'maxlength' characters'; if 'maxlength' is -1, searches to end
|
|
|
|
* of tvbuff.
|
|
|
|
* Returns -1 if 'maxlength' reached before finding EOS. */
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_strnlen(tvbuff_t *tvb, const gint offset,
|
|
|
|
const guint maxlength);
|
2000-11-10 09:15:57 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/**
|
2000-11-10 09:15:57 +00:00
|
|
|
* Format the data in the tvb from offset for size ...
|
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gchar *tvb_format_text(tvbuff_t *tvb, const gint offset,
|
|
|
|
const gint size);
|
2000-08-30 02:50:18 +00:00
|
|
|
|
2006-06-19 15:53:03 +00:00
|
|
|
/**
|
|
|
|
* Like "tvb_format_text()", but for 'wsp'; don't show
|
|
|
|
* the characters as C-style escapes.
|
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gchar *tvb_format_text_wsp(tvbuff_t *tvb, const gint offset,
|
|
|
|
const gint size);
|
2006-06-19 15:53:03 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/**
|
2004-03-23 18:06:29 +00:00
|
|
|
* Like "tvb_format_text()", but for null-padded strings; don't show
|
|
|
|
* the null padding characters as "\000".
|
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
extern gchar *tvb_format_stringzpad(tvbuff_t *tvb, const gint offset,
|
|
|
|
const gint size);
|
2004-03-23 18:06:29 +00:00
|
|
|
|
2009-04-24 08:08:37 +00:00
|
|
|
/**
|
|
|
|
* Like "tvb_format_text_wsp()", but for null-padded strings; don't show
|
|
|
|
* the null padding characters as "\000".
|
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
extern gchar *tvb_format_stringzpad_wsp(tvbuff_t *tvb, const gint offset,
|
|
|
|
const gint size);
|
2009-04-24 08:08:37 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/**
|
More tvbuff API deprecation, comment expansion, and documentation updates.
Do with tvb_get_stringz() what was done with tvb_get_string().
Redo the comments for the string get routines to try to give more detail
in a fashion that's a bit less hard to read.
Warn, in comments, of the problems with using
tvb_get_string()/tvb_get_stringz() (i.e., if your strings are non-ASCII,
all bytes with the 8th bit set are going be replaced by the Unicode
REPLACEMENT CHARACTER, and displayed as such).
Warn, in a comment, of the problems with tvb_get_const_stringz() (i.e.,
it gives you raw bytes, rather than guaranteed-to-be-valid UTF-8).
Update documentation and release notes appropriately.
Change-Id: Ibd3efb92a203861f507ce71bc8d04d19d9d38a93
Reviewed-on: https://code.wireshark.org/review/327
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-02-23 22:16:24 +00:00
|
|
|
* Given an allocator scope, a tvbuff, a byte offset, a byte length, and
|
|
|
|
* a string encoding, with the specified offset and length referring to
|
|
|
|
* a string in the specified encoding:
|
Add new routines:
tvb_get_string() - takes a tvbuff, an offset, and a length as
arguments, allocates a buffer big enough to hold a string with
the specified number of bytes plus an added null terminator
(i.e., length+1), copies the specified number of bytes from the
tvbuff, at the specified offset, to that buffer and puts in a
null terminator, and returns a pointer to that buffer (or throws
an exception before allocating the buffer if that many bytes
aren't available in the tvbuff);
tvb_get_stringz() - takes a tvbuff, an offset, and a pointer to
a "gint" as arguments, gets the size of the null-terminated
string starting at the specified offset in the tvbuff (throwing
an exception if the null terminator isn't found), allocates a
buffer big enough to hold that string, copies the string to that
buffer, and returns a pointer to that buffer and stores the
length of the string (including the terminating null) in the
variable pointed to by the "gint" pointer.
Replace many pieces of code allocating a buffer and copying a string
with calls to "tvb_get_string()" (for one thing, "tvb_get_string()"
doesn't require you to remember that the argument to
"tvb_get_nstringz0()" is the size of the buffer into which you're
copying the string, which might be the length of the string to be copied
*plus 1*).
Don't use fixed-length buffers for null-terminated strings (even if the
code that generates those packets has a #define to limit the length of
the string). Use "tvb_get_stringz()", instead.
In some cases where a value is fetched but is only used to pass an
argument to a "proto_tree_add_XXX" routine, use "proto_tree_add_item()"
instead.
svn path=/trunk/; revision=7859
2003-06-12 08:33:32 +00:00
|
|
|
*
|
More tvbuff API deprecation, comment expansion, and documentation updates.
Do with tvb_get_stringz() what was done with tvb_get_string().
Redo the comments for the string get routines to try to give more detail
in a fashion that's a bit less hard to read.
Warn, in comments, of the problems with using
tvb_get_string()/tvb_get_stringz() (i.e., if your strings are non-ASCII,
all bytes with the 8th bit set are going be replaced by the Unicode
REPLACEMENT CHARACTER, and displayed as such).
Warn, in a comment, of the problems with tvb_get_const_stringz() (i.e.,
it gives you raw bytes, rather than guaranteed-to-be-valid UTF-8).
Update documentation and release notes appropriately.
Change-Id: Ibd3efb92a203861f507ce71bc8d04d19d9d38a93
Reviewed-on: https://code.wireshark.org/review/327
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-02-23 22:16:24 +00:00
|
|
|
* allocate a buffer using the specified scope;
|
|
|
|
*
|
|
|
|
* convert the string from the specified encoding to UTF-8, possibly
|
|
|
|
* mapping some characters or invalid octet sequences to the Unicode
|
|
|
|
* REPLACEMENT CHARACTER, and put the resulting UTF-8 string, plus a
|
|
|
|
* trailing '\0', into that buffer;
|
2005-08-10 13:41:13 +00:00
|
|
|
*
|
More tvbuff API deprecation, comment expansion, and documentation updates.
Do with tvb_get_stringz() what was done with tvb_get_string().
Redo the comments for the string get routines to try to give more detail
in a fashion that's a bit less hard to read.
Warn, in comments, of the problems with using
tvb_get_string()/tvb_get_stringz() (i.e., if your strings are non-ASCII,
all bytes with the 8th bit set are going be replaced by the Unicode
REPLACEMENT CHARACTER, and displayed as such).
Warn, in a comment, of the problems with tvb_get_const_stringz() (i.e.,
it gives you raw bytes, rather than guaranteed-to-be-valid UTF-8).
Update documentation and release notes appropriately.
Change-Id: Ibd3efb92a203861f507ce71bc8d04d19d9d38a93
Reviewed-on: https://code.wireshark.org/review/327
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-02-23 22:16:24 +00:00
|
|
|
* and return a pointer to the buffer.
|
|
|
|
*
|
|
|
|
* Throws an exception if the tvbuff ends before the string does.
|
2009-03-27 19:40:23 +00:00
|
|
|
*
|
2014-02-22 13:39:57 +00:00
|
|
|
* If scope is set to NULL it is the user's responsibility to wmem_free()
|
2014-02-26 22:24:24 +00:00
|
|
|
* the memory allocated. Otherwise memory is automatically freed when the
|
|
|
|
* scope lifetime is reached.
|
Add new routines:
tvb_get_string() - takes a tvbuff, an offset, and a length as
arguments, allocates a buffer big enough to hold a string with
the specified number of bytes plus an added null terminator
(i.e., length+1), copies the specified number of bytes from the
tvbuff, at the specified offset, to that buffer and puts in a
null terminator, and returns a pointer to that buffer (or throws
an exception before allocating the buffer if that many bytes
aren't available in the tvbuff);
tvb_get_stringz() - takes a tvbuff, an offset, and a pointer to
a "gint" as arguments, gets the size of the null-terminated
string starting at the specified offset in the tvbuff (throwing
an exception if the null terminator isn't found), allocates a
buffer big enough to hold that string, copies the string to that
buffer, and returns a pointer to that buffer and stores the
length of the string (including the terminating null) in the
variable pointed to by the "gint" pointer.
Replace many pieces of code allocating a buffer and copying a string
with calls to "tvb_get_string()" (for one thing, "tvb_get_string()"
doesn't require you to remember that the argument to
"tvb_get_nstringz0()" is the size of the buffer into which you're
copying the string, which might be the length of the string to be copied
*plus 1*).
Don't use fixed-length buffers for null-terminated strings (even if the
code that generates those packets has a #define to limit the length of
the string). Use "tvb_get_stringz()", instead.
In some cases where a value is fetched but is only used to pass an
argument to a "proto_tree_add_XXX" routine, use "proto_tree_add_item()"
instead.
svn path=/trunk/; revision=7859
2003-06-12 08:33:32 +00:00
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC guint8 *tvb_get_string_enc(wmem_allocator_t *scope,
|
|
|
|
tvbuff_t *tvb, const gint offset, const gint length, const guint encoding);
|
2005-08-10 13:41:13 +00:00
|
|
|
|
More tvbuff API deprecation, comment expansion, and documentation updates.
Do with tvb_get_stringz() what was done with tvb_get_string().
Redo the comments for the string get routines to try to give more detail
in a fashion that's a bit less hard to read.
Warn, in comments, of the problems with using
tvb_get_string()/tvb_get_stringz() (i.e., if your strings are non-ASCII,
all bytes with the 8th bit set are going be replaced by the Unicode
REPLACEMENT CHARACTER, and displayed as such).
Warn, in a comment, of the problems with tvb_get_const_stringz() (i.e.,
it gives you raw bytes, rather than guaranteed-to-be-valid UTF-8).
Update documentation and release notes appropriately.
Change-Id: Ibd3efb92a203861f507ce71bc8d04d19d9d38a93
Reviewed-on: https://code.wireshark.org/review/327
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-02-23 22:16:24 +00:00
|
|
|
/*
|
|
|
|
* DEPRECATED, do not use in new code, call tvb_get_string_enc directly with
|
|
|
|
* the appropriate extension! Do not assume that ENC_ASCII will work
|
|
|
|
* with arbitrary string encodings; it will map all bytes with the 8th
|
|
|
|
* bit set to the Unicode REPLACEMENT CHARACTER, so it won't show non-ASCII
|
|
|
|
* characters as anything other than an ugly blob.
|
|
|
|
*/
|
2014-02-22 13:39:57 +00:00
|
|
|
#define tvb_get_string(SCOPE, TVB, OFFSET, LENGTH) \
|
|
|
|
tvb_get_string_enc(SCOPE, TVB, OFFSET, LENGTH, ENC_ASCII)
|
|
|
|
|
2014-01-01 14:33:19 +00:00
|
|
|
/**
|
More tvbuff API deprecation, comment expansion, and documentation updates.
Do with tvb_get_stringz() what was done with tvb_get_string().
Redo the comments for the string get routines to try to give more detail
in a fashion that's a bit less hard to read.
Warn, in comments, of the problems with using
tvb_get_string()/tvb_get_stringz() (i.e., if your strings are non-ASCII,
all bytes with the 8th bit set are going be replaced by the Unicode
REPLACEMENT CHARACTER, and displayed as such).
Warn, in a comment, of the problems with tvb_get_const_stringz() (i.e.,
it gives you raw bytes, rather than guaranteed-to-be-valid UTF-8).
Update documentation and release notes appropriately.
Change-Id: Ibd3efb92a203861f507ce71bc8d04d19d9d38a93
Reviewed-on: https://code.wireshark.org/review/327
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-02-23 22:16:24 +00:00
|
|
|
* Given an allocator scope, a tvbuff, a bit offset, and a length in
|
|
|
|
* 7-bit characters (not octets!), with the specified offset and
|
|
|
|
* length referring to a string in the 3GPP TS 23.038 7bits encoding:
|
|
|
|
*
|
|
|
|
* allocate a buffer using the specified scope;
|
|
|
|
*
|
|
|
|
* convert the string from the specified encoding to UTF-8, possibly
|
|
|
|
* mapping some characters or invalid octet sequences to the Unicode
|
|
|
|
* REPLACEMENT CHARACTER, and put the resulting UTF-8 string, plus a
|
|
|
|
* trailing '\0', into that buffer;
|
|
|
|
*
|
|
|
|
* and return a pointer to the buffer.
|
|
|
|
*
|
|
|
|
* Throws an exception if the tvbuff ends before the string does.
|
2014-01-01 14:33:19 +00:00
|
|
|
*
|
2014-02-26 22:14:16 +00:00
|
|
|
* If scope is set to NULL it is the user's responsibility to wmem_free()
|
2014-02-26 22:20:58 +00:00
|
|
|
* the memory allocated. Otherwise memory is automatically freed when the
|
|
|
|
* scope lifetime is reached.
|
2014-01-01 14:33:19 +00:00
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC gchar *tvb_get_ts_23_038_7bits_string(wmem_allocator_t *scope,
|
2014-04-13 16:53:29 +00:00
|
|
|
tvbuff_t *tvb, const gint bit_offset, gint no_of_chars);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given an allocator scope, a tvbuff, a bit offset, and a length in
|
|
|
|
* 7-bit characters (not octets!), with the specified offset and
|
|
|
|
* length referring to a string in the ASCII 7bits encoding:
|
|
|
|
*
|
|
|
|
* allocate a buffer using the specified scope;
|
|
|
|
*
|
|
|
|
* convert the string from the specified encoding to UTF-8, possibly
|
|
|
|
* mapping some characters or invalid octet sequences to the Unicode
|
|
|
|
* REPLACEMENT CHARACTER, and put the resulting UTF-8 string, plus a
|
|
|
|
* trailing '\0', into that buffer;
|
|
|
|
*
|
|
|
|
* and return a pointer to the buffer.
|
|
|
|
*
|
|
|
|
* Throws an exception if the tvbuff ends before the string does.
|
|
|
|
*
|
|
|
|
* If scope is set to NULL it is the user's responsibility to wmem_free()
|
|
|
|
* the memory allocated. Otherwise memory is automatically freed when the
|
|
|
|
* scope lifetime is reached.
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC gchar *tvb_get_ascii_7bits_string(wmem_allocator_t *scope,
|
2014-01-01 14:33:19 +00:00
|
|
|
tvbuff_t *tvb, const gint bit_offset, gint no_of_chars);
|
Add new routines:
tvb_get_string() - takes a tvbuff, an offset, and a length as
arguments, allocates a buffer big enough to hold a string with
the specified number of bytes plus an added null terminator
(i.e., length+1), copies the specified number of bytes from the
tvbuff, at the specified offset, to that buffer and puts in a
null terminator, and returns a pointer to that buffer (or throws
an exception before allocating the buffer if that many bytes
aren't available in the tvbuff);
tvb_get_stringz() - takes a tvbuff, an offset, and a pointer to
a "gint" as arguments, gets the size of the null-terminated
string starting at the specified offset in the tvbuff (throwing
an exception if the null terminator isn't found), allocates a
buffer big enough to hold that string, copies the string to that
buffer, and returns a pointer to that buffer and stores the
length of the string (including the terminating null) in the
variable pointed to by the "gint" pointer.
Replace many pieces of code allocating a buffer and copying a string
with calls to "tvb_get_string()" (for one thing, "tvb_get_string()"
doesn't require you to remember that the argument to
"tvb_get_nstringz0()" is the size of the buffer into which you're
copying the string, which might be the length of the string to be copied
*plus 1*).
Don't use fixed-length buffers for null-terminated strings (even if the
code that generates those packets has a #define to limit the length of
the string). Use "tvb_get_stringz()", instead.
In some cases where a value is fetched but is only used to pass an
argument to a "proto_tree_add_XXX" routine, use "proto_tree_add_item()"
instead.
svn path=/trunk/; revision=7859
2003-06-12 08:33:32 +00:00
|
|
|
|
2014-04-12 22:26:34 +00:00
|
|
|
/**
|
|
|
|
* Given an allocator scope, a tvbuff, a byte offset, a byte length, and
|
|
|
|
* a string encoding, with the specified offset and length referring to
|
|
|
|
* a null-padded string in the specified encoding:
|
|
|
|
*
|
|
|
|
* allocate a buffer using the specified scope;
|
|
|
|
*
|
|
|
|
* convert the string from the specified encoding to UTF-8, possibly
|
|
|
|
* mapping some characters or invalid octet sequences to the Unicode
|
|
|
|
* REPLACEMENT CHARACTER, and put the resulting UTF-8 string, plus a
|
|
|
|
* trailing '\0', into that buffer;
|
|
|
|
*
|
|
|
|
* and return a pointer to the buffer.
|
|
|
|
*
|
|
|
|
* Throws an exception if the tvbuff ends before the string does.
|
|
|
|
*
|
|
|
|
* If scope is set to NULL it is the user's responsibility to wmem_free()
|
|
|
|
* the memory allocated. Otherwise memory is automatically freed when the
|
|
|
|
* scope lifetime is reached.
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC guint8 *tvb_get_stringzpad(wmem_allocator_t *scope,
|
|
|
|
tvbuff_t *tvb, const gint offset, const gint length, const guint encoding);
|
|
|
|
|
More tvbuff API deprecation, comment expansion, and documentation updates.
Do with tvb_get_stringz() what was done with tvb_get_string().
Redo the comments for the string get routines to try to give more detail
in a fashion that's a bit less hard to read.
Warn, in comments, of the problems with using
tvb_get_string()/tvb_get_stringz() (i.e., if your strings are non-ASCII,
all bytes with the 8th bit set are going be replaced by the Unicode
REPLACEMENT CHARACTER, and displayed as such).
Warn, in a comment, of the problems with tvb_get_const_stringz() (i.e.,
it gives you raw bytes, rather than guaranteed-to-be-valid UTF-8).
Update documentation and release notes appropriately.
Change-Id: Ibd3efb92a203861f507ce71bc8d04d19d9d38a93
Reviewed-on: https://code.wireshark.org/review/327
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-02-23 22:16:24 +00:00
|
|
|
/**
|
|
|
|
* Given an allocator scope, a tvbuff, a byte offset, a pointer to a
|
|
|
|
* gint, and a string encoding, with the specified offset referring to
|
|
|
|
* a null-terminated string in the specified encoding:
|
|
|
|
*
|
|
|
|
* find the length of that string (and throw an exception if the tvbuff
|
|
|
|
* ends before we find the null);
|
|
|
|
*
|
|
|
|
* allocate a buffer using the specified scope;
|
|
|
|
*
|
|
|
|
* convert the string from the specified encoding to UTF-8, possibly
|
|
|
|
* mapping some characters or invalid octet sequences to the Unicode
|
|
|
|
* REPLACEMENT CHARACTER, and put the resulting UTF-8 string, plus a
|
|
|
|
* trailing '\0', into that buffer;
|
|
|
|
*
|
|
|
|
* if the pointer to the gint is non-null, set the gint to which it
|
|
|
|
* points to the length of the string;
|
|
|
|
*
|
|
|
|
* and return a pointer to the buffer.
|
|
|
|
*
|
|
|
|
* Throws an exception if the tvbuff ends before the string does.
|
|
|
|
*
|
|
|
|
* If scope is set to NULL it is the user's responsibility to wmem_free()
|
2014-02-26 22:24:24 +00:00
|
|
|
* the memory allocated. Otherwise memory is automatically freed when the
|
|
|
|
* scope lifetime is reached.
|
More tvbuff API deprecation, comment expansion, and documentation updates.
Do with tvb_get_stringz() what was done with tvb_get_string().
Redo the comments for the string get routines to try to give more detail
in a fashion that's a bit less hard to read.
Warn, in comments, of the problems with using
tvb_get_string()/tvb_get_stringz() (i.e., if your strings are non-ASCII,
all bytes with the 8th bit set are going be replaced by the Unicode
REPLACEMENT CHARACTER, and displayed as such).
Warn, in a comment, of the problems with tvb_get_const_stringz() (i.e.,
it gives you raw bytes, rather than guaranteed-to-be-valid UTF-8).
Update documentation and release notes appropriately.
Change-Id: Ibd3efb92a203861f507ce71bc8d04d19d9d38a93
Reviewed-on: https://code.wireshark.org/review/327
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-02-23 22:16:24 +00:00
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC guint8 *tvb_get_stringz_enc(wmem_allocator_t *scope,
|
|
|
|
tvbuff_t *tvb, const gint offset, gint *lengthp, const guint encoding);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DEPRECATED, do not use in new code, call tvb_get_string_enc directly with
|
|
|
|
* the appropriate extension! Do not assume that ENC_ASCII will work
|
|
|
|
* with arbitrary string encodings; it will map all bytes with the 8th
|
|
|
|
* bit set to the Unicode REPLACEMENT CHARACTER, so it won't show non-ASCII
|
|
|
|
* characters as anything other than an ugly blob.
|
|
|
|
*/
|
|
|
|
#define tvb_get_stringz(SCOPE, TVB, OFFSET, LENGTHP) \
|
|
|
|
tvb_get_stringz_enc(SCOPE, TVB, OFFSET, LENGTHP, ENC_ASCII)
|
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/**
|
Add new routines:
tvb_get_string() - takes a tvbuff, an offset, and a length as
arguments, allocates a buffer big enough to hold a string with
the specified number of bytes plus an added null terminator
(i.e., length+1), copies the specified number of bytes from the
tvbuff, at the specified offset, to that buffer and puts in a
null terminator, and returns a pointer to that buffer (or throws
an exception before allocating the buffer if that many bytes
aren't available in the tvbuff);
tvb_get_stringz() - takes a tvbuff, an offset, and a pointer to
a "gint" as arguments, gets the size of the null-terminated
string starting at the specified offset in the tvbuff (throwing
an exception if the null terminator isn't found), allocates a
buffer big enough to hold that string, copies the string to that
buffer, and returns a pointer to that buffer and stores the
length of the string (including the terminating null) in the
variable pointed to by the "gint" pointer.
Replace many pieces of code allocating a buffer and copying a string
with calls to "tvb_get_string()" (for one thing, "tvb_get_string()"
doesn't require you to remember that the argument to
"tvb_get_nstringz0()" is the size of the buffer into which you're
copying the string, which might be the length of the string to be copied
*plus 1*).
Don't use fixed-length buffers for null-terminated strings (even if the
code that generates those packets has a #define to limit the length of
the string). Use "tvb_get_stringz()", instead.
In some cases where a value is fetched but is only used to pass an
argument to a "proto_tree_add_XXX" routine, use "proto_tree_add_item()"
instead.
svn path=/trunk/; revision=7859
2003-06-12 08:33:32 +00:00
|
|
|
* Given a tvbuff and an offset, with the offset assumed to refer to
|
|
|
|
* a null-terminated string, find the length of that string (and throw
|
|
|
|
* an exception if the tvbuff ends before we find the null), allocate
|
|
|
|
* a buffer big enough to hold the string, copy the string into it,
|
|
|
|
* and return a pointer to the string. Also return the length of the
|
|
|
|
* string (including the terminating null) through a pointer.
|
2005-08-10 14:25:59 +00:00
|
|
|
*
|
More tvbuff API deprecation, comment expansion, and documentation updates.
Do with tvb_get_stringz() what was done with tvb_get_string().
Redo the comments for the string get routines to try to give more detail
in a fashion that's a bit less hard to read.
Warn, in comments, of the problems with using
tvb_get_string()/tvb_get_stringz() (i.e., if your strings are non-ASCII,
all bytes with the 8th bit set are going be replaced by the Unicode
REPLACEMENT CHARACTER, and displayed as such).
Warn, in a comment, of the problems with tvb_get_const_stringz() (i.e.,
it gives you raw bytes, rather than guaranteed-to-be-valid UTF-8).
Update documentation and release notes appropriately.
Change-Id: Ibd3efb92a203861f507ce71bc8d04d19d9d38a93
Reviewed-on: https://code.wireshark.org/review/327
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-02-23 22:16:24 +00:00
|
|
|
* This returns a constant (unmodifiable) string that does not need
|
|
|
|
* to be freed; instead, it will automatically be freed once the next
|
|
|
|
* packet is dissected.
|
2011-01-12 02:25:08 +00:00
|
|
|
*
|
More tvbuff API deprecation, comment expansion, and documentation updates.
Do with tvb_get_stringz() what was done with tvb_get_string().
Redo the comments for the string get routines to try to give more detail
in a fashion that's a bit less hard to read.
Warn, in comments, of the problems with using
tvb_get_string()/tvb_get_stringz() (i.e., if your strings are non-ASCII,
all bytes with the 8th bit set are going be replaced by the Unicode
REPLACEMENT CHARACTER, and displayed as such).
Warn, in a comment, of the problems with tvb_get_const_stringz() (i.e.,
it gives you raw bytes, rather than guaranteed-to-be-valid UTF-8).
Update documentation and release notes appropriately.
Change-Id: Ibd3efb92a203861f507ce71bc8d04d19d9d38a93
Reviewed-on: https://code.wireshark.org/review/327
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-02-23 22:16:24 +00:00
|
|
|
* It is slightly more efficient than the other routines, but does *NOT*
|
|
|
|
* do any translation to UTF-8 - the string consists of the raw octets
|
|
|
|
* of the string, in whatever encoding they happen to be in, and, if
|
|
|
|
* the string is not valid in that encoding, with invalid octet sequences
|
|
|
|
* as they are in the packet.
|
Add new routines:
tvb_get_string() - takes a tvbuff, an offset, and a length as
arguments, allocates a buffer big enough to hold a string with
the specified number of bytes plus an added null terminator
(i.e., length+1), copies the specified number of bytes from the
tvbuff, at the specified offset, to that buffer and puts in a
null terminator, and returns a pointer to that buffer (or throws
an exception before allocating the buffer if that many bytes
aren't available in the tvbuff);
tvb_get_stringz() - takes a tvbuff, an offset, and a pointer to
a "gint" as arguments, gets the size of the null-terminated
string starting at the specified offset in the tvbuff (throwing
an exception if the null terminator isn't found), allocates a
buffer big enough to hold that string, copies the string to that
buffer, and returns a pointer to that buffer and stores the
length of the string (including the terminating null) in the
variable pointed to by the "gint" pointer.
Replace many pieces of code allocating a buffer and copying a string
with calls to "tvb_get_string()" (for one thing, "tvb_get_string()"
doesn't require you to remember that the argument to
"tvb_get_nstringz0()" is the size of the buffer into which you're
copying the string, which might be the length of the string to be copied
*plus 1*).
Don't use fixed-length buffers for null-terminated strings (even if the
code that generates those packets has a #define to limit the length of
the string). Use "tvb_get_stringz()", instead.
In some cases where a value is fetched but is only used to pass an
argument to a "proto_tree_add_XXX" routine, use "proto_tree_add_item()"
instead.
svn path=/trunk/; revision=7859
2003-06-12 08:33:32 +00:00
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC const guint8 *tvb_get_const_stringz(tvbuff_t *tvb,
|
|
|
|
const gint offset, gint *lengthp);
|
Add new routines:
tvb_get_string() - takes a tvbuff, an offset, and a length as
arguments, allocates a buffer big enough to hold a string with
the specified number of bytes plus an added null terminator
(i.e., length+1), copies the specified number of bytes from the
tvbuff, at the specified offset, to that buffer and puts in a
null terminator, and returns a pointer to that buffer (or throws
an exception before allocating the buffer if that many bytes
aren't available in the tvbuff);
tvb_get_stringz() - takes a tvbuff, an offset, and a pointer to
a "gint" as arguments, gets the size of the null-terminated
string starting at the specified offset in the tvbuff (throwing
an exception if the null terminator isn't found), allocates a
buffer big enough to hold that string, copies the string to that
buffer, and returns a pointer to that buffer and stores the
length of the string (including the terminating null) in the
variable pointed to by the "gint" pointer.
Replace many pieces of code allocating a buffer and copying a string
with calls to "tvb_get_string()" (for one thing, "tvb_get_string()"
doesn't require you to remember that the argument to
"tvb_get_nstringz0()" is the size of the buffer into which you're
copying the string, which might be the length of the string to be copied
*plus 1*).
Don't use fixed-length buffers for null-terminated strings (even if the
code that generates those packets has a #define to limit the length of
the string). Use "tvb_get_stringz()", instead.
In some cases where a value is fetched but is only used to pass an
argument to a "proto_tree_add_XXX" routine, use "proto_tree_add_item()"
instead.
svn path=/trunk/; revision=7859
2003-06-12 08:33:32 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Looks for a stringz (NUL-terminated string) in tvbuff and copies
|
2003-04-30 02:35:28 +00:00
|
|
|
* no more than bufsize number of bytes, including terminating NUL, to buffer.
|
2013-10-31 17:30:22 +00:00
|
|
|
* Returns length of string (not including terminating NUL), or -1 if the
|
|
|
|
* string was truncated in the buffer due to not having reached the terminating
|
|
|
|
* NUL. In this way, it acts like g_snprintf().
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
*
|
|
|
|
* When processing a packet where the remaining number of bytes is less
|
2003-04-30 02:35:28 +00:00
|
|
|
* than bufsize, an exception is not thrown if the end of the packet
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
* is reached before the NUL is found. If no NUL is found before reaching
|
|
|
|
* the end of the short packet, -1 is still returned, and the string
|
2003-04-30 02:35:28 +00:00
|
|
|
* is truncated with a NUL, albeit not at buffer[bufsize - 1], but
|
tvb_get_nstringz() needs to terminate a string with a NUL if the
end of the tvbuff is reached before the maximum_length passed by the
caller is reached and before a terminating NUL is found. In this case,
tvb_get_nstringz() returns a -1, but if the string is not artificially
terminated with a NUL by tvb_get_nstringz(), the
caller has no idea where the string should end because 1) the
return value "-1" gives the impression that the string ends
at the end of the buffer but 2) the string does
not end at the end of the buffer, but somewhere in the middle, due
to the packet being shorter than expected.
tvb_get_nstringz() and tvb_get_nstringz0() were both modified.
The FT_STRINGZ case in proto_tree_add_item() is made simpler.
During regression testing, when investigating a regression that I later
corrected, I discovered that strings added through proto_tree_add_item
(FT_STRING, FT_STRINGZ, and FT_UINT_STRING) leaked memory due to double
allocation of the string. The proto_tree_add_string*() functions do
not leak memory, since they only copy the string once. The memory
leak was fixed by adding another argument to the static function
proto_tree_set_string() to let the string ftype code know to g_strdup()
the string or not.
svn path=/trunk/; revision=4891
2002-03-06 19:17:06 +00:00
|
|
|
* at the correct spot, terminating the string.
|
2000-08-30 02:50:18 +00:00
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_get_nstringz(tvbuff_t *tvb, const gint offset,
|
|
|
|
const guint bufsize, guint8 *buffer);
|
2000-08-30 02:50:18 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Like tvb_get_nstringz(), but never returns -1. The string is guaranteed to
|
2000-08-30 02:50:18 +00:00
|
|
|
* have a terminating NUL. If the string was truncated when copied into buffer,
|
|
|
|
* a NUL is placed at the end of buffer to terminate it.
|
2003-05-19 03:23:12 +00:00
|
|
|
*
|
|
|
|
* bufsize MUST be greater than 0.
|
2000-08-30 02:50:18 +00:00
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_get_nstringz0(tvbuff_t *tvb, const gint offset,
|
|
|
|
const guint bufsize, guint8 *buffer);
|
2000-05-11 08:18:09 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/**
|
2000-11-09 10:56:33 +00:00
|
|
|
* Given a tvbuff, an offset into the tvbuff, and a length that starts
|
|
|
|
* at that offset (which may be -1 for "all the way to the end of the
|
|
|
|
* tvbuff"), find the end of the (putative) line that starts at the
|
|
|
|
* specified offset in the tvbuff, going no further than the specified
|
|
|
|
* length.
|
|
|
|
*
|
2002-07-17 06:55:29 +00:00
|
|
|
* Return the length of the line (not counting the line terminator at
|
|
|
|
* the end), or, if we don't find a line terminator:
|
|
|
|
*
|
2013-10-31 17:30:22 +00:00
|
|
|
* if "deseg" is true, return -1;
|
2002-07-17 06:55:29 +00:00
|
|
|
*
|
2013-10-31 17:30:22 +00:00
|
|
|
* if "deseg" is false, return the amount of data remaining in
|
|
|
|
* the buffer.
|
2002-07-17 06:55:29 +00:00
|
|
|
*
|
|
|
|
* Set "*next_offset" to the offset of the character past the line
|
|
|
|
* terminator, or past the end of the buffer if we don't find a line
|
|
|
|
* terminator. (It's not set if we return -1.)
|
2000-11-09 10:56:33 +00:00
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_find_line_end(tvbuff_t *tvb, const gint offset, int len,
|
2010-04-03 18:18:50 +00:00
|
|
|
gint *next_offset, const gboolean desegment);
|
2000-09-07 15:29:40 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/**
|
2000-11-10 06:50:37 +00:00
|
|
|
* Given a tvbuff, an offset into the tvbuff, and a length that starts
|
|
|
|
* at that offset (which may be -1 for "all the way to the end of the
|
|
|
|
* tvbuff"), find the end of the (putative) line that starts at the
|
|
|
|
* specified offset in the tvbuff, going no further than the specified
|
|
|
|
* length.
|
|
|
|
*
|
|
|
|
* However, treat quoted strings inside the buffer specially - don't
|
|
|
|
* treat newlines in quoted strings as line terminators.
|
|
|
|
*
|
|
|
|
* Return the length of the line (not counting the line terminator at
|
|
|
|
* the end), or the amount of data remaining in the buffer if we don't
|
|
|
|
* find a line terminator.
|
|
|
|
*
|
|
|
|
* Set "*next_offset" to the offset of the character past the line
|
|
|
|
* terminator, or past the end of the buffer if we don't find a line
|
|
|
|
* terminator.
|
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_find_line_end_unquoted(tvbuff_t *tvb, const gint offset,
|
|
|
|
int len, gint *next_offset);
|
2000-11-10 06:50:37 +00:00
|
|
|
|
2007-12-09 17:41:16 +00:00
|
|
|
/**
|
|
|
|
* Copied from the mgcp dissector. (This function should be moved to /epan )
|
|
|
|
* tvb_skip_wsp - Returns the position in tvb of the first non-whitespace
|
|
|
|
* character following offset or offset + maxlength -1 whichever
|
|
|
|
* is smaller.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* tvb - The tvbuff in which we are skipping whitespace.
|
|
|
|
* offset - The offset in tvb from which we begin trying to skip whitespace.
|
|
|
|
* maxlength - The maximum distance from offset that we may try to skip
|
|
|
|
* whitespace.
|
|
|
|
*
|
|
|
|
* Returns: The position in tvb of the first non-whitespace
|
|
|
|
* character following offset or offset + maxlength -1 whichever
|
|
|
|
* is smaller.
|
|
|
|
*/
|
|
|
|
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_skip_wsp(tvbuff_t *tvb, const gint offset,
|
|
|
|
const gint maxlength);
|
2007-12-09 17:41:16 +00:00
|
|
|
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_skip_wsp_return(tvbuff_t *tvb, const gint offset);
|
2007-12-09 17:41:16 +00:00
|
|
|
|
2013-12-30 23:58:45 +00:00
|
|
|
int tvb_skip_guint8(tvbuff_t *tvb, int offset, const int maxlength, const guint8 ch);
|
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/**
|
2001-07-02 07:11:40 +00:00
|
|
|
* Call strncmp after checking if enough chars left, returning 0 if
|
|
|
|
* it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
|
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_strneql(tvbuff_t *tvb, const gint offset,
|
|
|
|
const gchar *str, const size_t size);
|
2000-09-07 15:29:40 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/**
|
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
|
|
|
* Call g_ascii_strncasecmp after checking if enough chars left, returning
|
|
|
|
* 0 if it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
|
2001-07-02 07:11:40 +00:00
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_strncaseeql(tvbuff_t *tvb, const gint offset,
|
|
|
|
const gchar *str, const size_t size);
|
2000-11-09 10:56:33 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/**
|
2001-07-02 07:11:40 +00:00
|
|
|
* Call memcmp after checking if enough chars left, returning 0 if
|
|
|
|
* it returns 0 (meaning "equal") and -1 otherwise, otherwise return -1.
|
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_memeql(tvbuff_t *tvb, const gint offset,
|
|
|
|
const guint8 *str, size_t size);
|
2001-07-02 07:11:40 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/**
|
2004-12-30 23:47:52 +00:00
|
|
|
* Format a bunch of data from a tvbuff as bytes, returning a pointer
|
|
|
|
* to the string with the formatted data, with "punct" as a byte
|
|
|
|
* separator.
|
|
|
|
*/
|
2013-12-19 15:49:09 +00:00
|
|
|
WS_DLL_PUBLIC gchar *tvb_bytes_to_ep_str_punct(tvbuff_t *tvb, const gint offset,
|
2013-10-31 17:30:22 +00:00
|
|
|
const gint len, const gchar punct);
|
2004-12-30 23:47:52 +00:00
|
|
|
|
2010-12-28 12:36:26 +00:00
|
|
|
/**
|
2000-11-13 07:19:37 +00:00
|
|
|
* Format a bunch of data from a tvbuff as bytes, returning a pointer
|
|
|
|
* to the string with the formatted data.
|
|
|
|
*/
|
2013-12-19 15:49:09 +00:00
|
|
|
WS_DLL_PUBLIC gchar *tvb_bytes_to_ep_str(tvbuff_t *tvb, const gint offset,
|
2013-10-31 17:30:22 +00:00
|
|
|
const gint len);
|
2000-11-13 07:19:37 +00:00
|
|
|
|
2010-12-28 12:36:26 +00:00
|
|
|
/**
|
|
|
|
* Given a tvbuff, an offset into the tvbuff, and a length that starts
|
|
|
|
* at that offset (which may be -1 for "all the way to the end of the
|
2011-01-12 02:25:08 +00:00
|
|
|
* tvbuff"), fetch BCD encoded digits from a tvbuff starting from either
|
2013-10-31 17:30:22 +00:00
|
|
|
* the low or high half byte, formatting the digits according to an input digit
|
|
|
|
* set, if NUL a default digit set of 0-9 returning "?" for overdecadic digits
|
|
|
|
* will be used. A pointer to the EP allocated string will be returned.
|
|
|
|
* Note a tvbuff content of 0xf is considered a 'filler' and will end the
|
|
|
|
* conversion.
|
2010-12-28 12:36:26 +00:00
|
|
|
*/
|
|
|
|
typedef struct dgt_set_t
|
|
|
|
{
|
2013-12-18 15:54:32 +00:00
|
|
|
const unsigned char out[16];
|
2010-12-28 12:36:26 +00:00
|
|
|
}
|
|
|
|
dgt_set_t;
|
|
|
|
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC const gchar *tvb_bcd_dig_to_wmem_packet_str(tvbuff_t *tvb,
|
|
|
|
const gint offset, const gint len, dgt_set_t *dgt, gboolean skip_first);
|
2001-03-23 14:44:04 +00:00
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/** Locate a sub-tvbuff within another tvbuff, starting at position
|
2003-08-27 15:23:11 +00:00
|
|
|
* 'haystack_offset'. Returns the index of the beginning of 'needle' within
|
|
|
|
* 'haystack', or -1 if 'needle' is not found. The index is relative
|
|
|
|
* to the start of 'haystack', not 'haystack_offset'. */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC gint tvb_find_tvb(tvbuff_t *haystack_tvb, tvbuff_t *needle_tvb,
|
2013-10-31 17:30:22 +00:00
|
|
|
const gint haystack_offset);
|
2003-08-27 15:23:11 +00:00
|
|
|
|
2013-12-21 14:33:54 +00:00
|
|
|
/* From tvbuff_zlib.c */
|
|
|
|
|
2005-01-07 12:00:01 +00:00
|
|
|
/**
|
2004-05-05 06:55:09 +00:00
|
|
|
* Uncompresses a zlib compressed packet inside a tvbuff at offset with
|
|
|
|
* length comprlen. Returns an uncompressed tvbuffer if uncompression
|
|
|
|
* succeeded or NULL if uncompression failed.
|
|
|
|
*/
|
2013-10-31 17:30:22 +00:00
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_uncompress(tvbuff_t *tvb, const int offset,
|
|
|
|
int comprlen);
|
2004-05-05 06:55:09 +00:00
|
|
|
|
2009-04-01 16:22:51 +00:00
|
|
|
/**
|
|
|
|
* Uncompresses a zlib compressed packet inside a tvbuff at offset with
|
2013-10-31 17:30:22 +00:00
|
|
|
* length comprlen. Returns an uncompressed tvbuffer attached to tvb if
|
|
|
|
* uncompression succeeded or NULL if uncompression failed.
|
2009-04-01 16:22:51 +00:00
|
|
|
*/
|
2014-04-06 17:25:36 +00:00
|
|
|
WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress(tvbuff_t *parent, tvbuff_t *tvb,
|
2013-10-31 17:30:22 +00:00
|
|
|
const int offset, int comprlen);
|
2009-04-01 16:22:51 +00:00
|
|
|
|
2013-12-21 14:33:54 +00:00
|
|
|
/* From tvbuff_base64.c */
|
|
|
|
|
|
|
|
/** Return a tvb that contains the binary representation of a base64
|
2013-12-22 15:47:17 +00:00
|
|
|
* string
|
2013-12-21 14:33:54 +00:00
|
|
|
*/
|
|
|
|
extern tvbuff_t* base64_to_tvb(tvbuff_t *parent, const char *base64);
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
/************** END OF ACCESSORS ****************/
|
|
|
|
|
2013-05-30 22:20:21 +00:00
|
|
|
/** @} */
|
|
|
|
|
2011-12-29 00:08:47 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
#endif /* __TVBUFF_H__ */
|
2013-10-31 17:30:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
2014-04-03 03:59:19 +00:00
|
|
|
* tab-width: 8
|
2013-10-31 17:30:22 +00:00
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
2014-04-03 03:59:19 +00:00
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
2013-10-31 17:30:22 +00:00
|
|
|
*/
|