1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/** @file
*
* Structures that most TVB users should not be accessing directly.
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef __TVBUFF_INT_H__
#define __TVBUFF_INT_H__
struct tvbuff;
struct tvb_ops {
size_t tvb_size;
void (*tvb_free)(struct tvbuff *tvb);
unsigned (*tvb_offset)(const struct tvbuff *tvb, unsigned counter);
const uint8_t *(*tvb_get_ptr)(struct tvbuff *tvb, unsigned abs_offset, unsigned abs_length);
void *(*tvb_memcpy)(struct tvbuff *tvb, void *target, unsigned offset, unsigned length);
int (*tvb_find_uint8)(tvbuff_t *tvb, unsigned abs_offset, unsigned limit, uint8_t needle);
int (*tvb_ws_mempbrk_pattern_uint8)(tvbuff_t *tvb, unsigned abs_offset, unsigned limit, const ws_mempbrk_pattern* pattern, unsigned char *found_needle);
tvbuff_t *(*tvb_clone)(tvbuff_t *tvb, unsigned abs_offset, unsigned abs_length);
};
/*
* Tvbuff flags.
*/
#define TVBUFF_FRAGMENT 0x00000001 /* this is a fragment */
struct tvbuff {
/* Doubly linked list pointers */
tvbuff_t *next;
/* Record-keeping */
const struct tvb_ops *ops;
bool initialized;
unsigned flags;
struct tvbuff *ds_tvb; /**< data source top-level tvbuff */
/** Pointer to the data for this tvbuff.
* It might be null, which either means that 1) it's a
* zero-length tvbuff or 2) the tvbuff was lazily
* constructed, so that we don't allocate a buffer of
* backing data and fill it in unless we need that
* data, e.g. when tvb_get_ptr() is called.
*/
const uint8_t *real_data;
/** Amount of data that's available from the capture
* file. This is the length of virtual buffer (and/or
* real_data). It may be less than the reported
* length if this is from a packet that was cut short
* by the capture process.
*
* This must never be > reported_length or contained_length. */
unsigned length;
/** Amount of data that was reported as being in
* the packet or other data that this represents.
* As indicated above, it may be greater than the
* amount of data that's available. */
unsigned reported_length;
/** If this was extracted from a parent tvbuff,
* this is the amount of extracted data that
* was reported as being in the parent tvbuff;
* if this represents a blob of data in that
* tvbuff that has a length specified by data
* in that tvbuff, it might be greater than
* the amount of data that was actually there
* to extract, so it could be greater than
* reported_length.
*
* If this wasn't extracted from a parent tvbuff,
* this is the same as reported_length.
*
* This must never be > reported_length. */
unsigned contained_length;
/* Offset from beginning of first "real" tvbuff. */
int raw_offset;
};
WS_DLL_PUBLIC tvbuff_t *tvb_new(const struct tvb_ops *ops);
tvbuff_t *tvb_new_proxy(tvbuff_t *backing);
void tvb_add_to_chain(tvbuff_t *parent, tvbuff_t *child);
unsigned tvb_offset_from_real_beginning_counter(const tvbuff_t *tvb, const unsigned counter);
void tvb_check_offset_length(const tvbuff_t *tvb, const int offset, int const length_val, unsigned *offset_ptr, unsigned *length_ptr);
#endif
|