2013-07-14 07:42:19 +00:00
|
|
|
/* tvbuff_real.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2013-07-14 07:42:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "tvbuff.h"
|
|
|
|
#include "tvbuff-int.h"
|
|
|
|
#include "proto.h" /* XXX - only used for DISSECTOR_ASSERT, probably a new header file? */
|
2013-11-10 15:59:37 +00:00
|
|
|
#include "exceptions.h"
|
2013-07-14 07:42:19 +00:00
|
|
|
|
|
|
|
struct tvb_real {
|
|
|
|
struct tvbuff tvb;
|
|
|
|
|
|
|
|
/** Func to call when actually freed */
|
|
|
|
tvbuff_free_cb_t free_cb;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
real_free(tvbuff_t *tvb)
|
|
|
|
{
|
|
|
|
struct tvb_real *real_tvb = (struct tvb_real *) tvb;
|
|
|
|
|
|
|
|
if (real_tvb->free_cb) {
|
|
|
|
/*
|
|
|
|
* XXX - do this with a union?
|
|
|
|
*/
|
|
|
|
real_tvb->free_cb((gpointer)tvb->real_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
real_offset(const tvbuff_t *tvb _U_, const guint counter)
|
|
|
|
{
|
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct tvb_ops tvb_real_ops = {
|
2013-08-04 22:02:42 +00:00
|
|
|
sizeof(struct tvb_real), /* size */
|
|
|
|
|
2013-07-14 07:42:19 +00:00
|
|
|
real_free, /* free */
|
|
|
|
real_offset, /* offset */
|
|
|
|
NULL, /* get_ptr */
|
|
|
|
NULL, /* memcpy */
|
|
|
|
NULL, /* find_guint8 */
|
|
|
|
NULL, /* pbrk_guint8 */
|
|
|
|
NULL, /* clone */
|
|
|
|
};
|
|
|
|
|
|
|
|
tvbuff_t *
|
|
|
|
tvb_new_real_data(const guint8* data, const guint length, const gint reported_length)
|
|
|
|
{
|
|
|
|
tvbuff_t *tvb;
|
|
|
|
struct tvb_real *real_tvb;
|
|
|
|
|
|
|
|
THROW_ON(reported_length < -1, ReportedBoundsError);
|
|
|
|
|
|
|
|
tvb = tvb_new(&tvb_real_ops);
|
|
|
|
|
2018-04-20 03:18:10 +00:00
|
|
|
tvb->real_data = data;
|
|
|
|
tvb->length = length;
|
|
|
|
tvb->reported_length = reported_length;
|
|
|
|
tvb->contained_length = reported_length;
|
|
|
|
tvb->initialized = TRUE;
|
2013-07-14 07:42:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the top-level real tvbuff for this data source,
|
|
|
|
* so its data source tvbuff is itself.
|
|
|
|
*/
|
|
|
|
tvb->ds_tvb = tvb;
|
|
|
|
|
|
|
|
real_tvb = (struct tvb_real *) tvb;
|
|
|
|
real_tvb->free_cb = NULL;
|
|
|
|
|
|
|
|
return tvb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tvb_set_free_cb(tvbuff_t *tvb, const tvbuff_free_cb_t func)
|
|
|
|
{
|
|
|
|
struct tvb_real *real_tvb = (struct tvb_real *) tvb;
|
|
|
|
|
|
|
|
DISSECTOR_ASSERT(tvb);
|
|
|
|
DISSECTOR_ASSERT(tvb->ops == &tvb_real_ops);
|
|
|
|
real_tvb->free_cb = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tvb_set_child_real_data_tvbuff(tvbuff_t *parent, tvbuff_t *child)
|
|
|
|
{
|
|
|
|
DISSECTOR_ASSERT(parent && child);
|
|
|
|
DISSECTOR_ASSERT(parent->initialized);
|
|
|
|
DISSECTOR_ASSERT(child->initialized);
|
|
|
|
DISSECTOR_ASSERT(child->ops == &tvb_real_ops);
|
|
|
|
tvb_add_to_chain(parent, child);
|
|
|
|
}
|
2013-07-23 17:23:51 +00:00
|
|
|
|
|
|
|
tvbuff_t *
|
|
|
|
tvb_new_child_real_data(tvbuff_t *parent, const guint8* data, const guint length, const gint reported_length)
|
|
|
|
{
|
|
|
|
tvbuff_t *tvb = tvb_new_real_data(data, length, reported_length);
|
|
|
|
|
|
|
|
tvb_set_child_real_data_tvbuff(parent, tvb);
|
|
|
|
|
|
|
|
return tvb;
|
|
|
|
}
|
2014-10-10 14:41:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|