3 * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include "tvbuff-int.h"
16 #include "proto.h" /* XXX - only used for DISSECTOR_ASSERT, probably a new header file? */
17 #include "exceptions.h"
22 /** Func to call when actually freed */
23 tvbuff_free_cb_t free_cb
;
27 real_free(tvbuff_t
*tvb
)
29 struct tvb_real
*real_tvb
= (struct tvb_real
*) tvb
;
31 if (real_tvb
->free_cb
) {
33 * XXX - do this with a union?
35 real_tvb
->free_cb((void *)tvb
->real_data
);
40 real_offset(const tvbuff_t
*tvb _U_
, const unsigned counter
)
45 static const struct tvb_ops tvb_real_ops
= {
46 sizeof(struct tvb_real
), /* size */
49 real_offset
, /* offset */
52 NULL
, /* find_uint8 */
53 NULL
, /* pbrk_uint8 */
58 tvb_new_real_data(const uint8_t* data
, const unsigned length
, const int reported_length
)
61 struct tvb_real
*real_tvb
;
63 THROW_ON(reported_length
< -1, ReportedBoundsError
);
65 tvb
= tvb_new(&tvb_real_ops
);
67 tvb
->real_data
= data
;
69 tvb
->reported_length
= reported_length
;
70 tvb
->contained_length
= reported_length
;
71 tvb
->initialized
= true;
74 * This is the top-level real tvbuff for this data source,
75 * so its data source tvbuff is itself.
79 real_tvb
= (struct tvb_real
*) tvb
;
80 real_tvb
->free_cb
= NULL
;
86 tvb_set_free_cb(tvbuff_t
*tvb
, const tvbuff_free_cb_t func
)
88 struct tvb_real
*real_tvb
= (struct tvb_real
*) tvb
;
90 DISSECTOR_ASSERT(tvb
);
91 DISSECTOR_ASSERT(tvb
->ops
== &tvb_real_ops
);
92 real_tvb
->free_cb
= func
;
96 tvb_set_child_real_data_tvbuff(tvbuff_t
*parent
, tvbuff_t
*child
)
98 DISSECTOR_ASSERT(parent
&& child
);
99 DISSECTOR_ASSERT(parent
->initialized
);
100 DISSECTOR_ASSERT(child
->initialized
);
101 DISSECTOR_ASSERT(child
->ops
== &tvb_real_ops
);
102 tvb_add_to_chain(parent
, child
);
106 tvb_new_child_real_data(tvbuff_t
*parent
, const uint8_t* data
, const unsigned length
, const int reported_length
)
108 tvbuff_t
*tvb
= tvb_new_real_data(data
, length
, reported_length
);
110 tvb_set_child_real_data_tvbuff(parent
, tvb
);
116 * Editor modelines - https://www.wireshark.org/tools/modelines.html
121 * indent-tabs-mode: t
124 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
125 * :indentSize=8:tabSize=8:noTabs=false: