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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
* $Id: ftype-tvbuff.c,v 1.9 2003/07/25 03:44:03 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 2001 Gerald Combs
*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <ftypes-int.h>
#include <epan/gdebug.h>
static void
value_new(fvalue_t *fv)
{
fv->value.tvb = NULL;
}
static void
value_set(fvalue_t *fv, gpointer value, gboolean already_copied)
{
g_assert(already_copied);
fv->value.tvb = value;
}
static gpointer
value_get(fvalue_t *fv)
{
return fv->value.tvb;
}
static guint
len(fvalue_t *fv)
{
if (fv->value.tvb)
return tvb_length(fv->value.tvb);
else
return 0;
}
static void
slice(fvalue_t *fv, GByteArray *bytes, guint offset, guint length)
{
const guint8* data;
if (fv->value.tvb) {
TRY {
data = tvb_get_ptr(fv->value.tvb, offset, length);
g_byte_array_append(bytes, data, length);
}
CATCH_ALL {
/* nothing */
}
ENDTRY;
}
}
void
ftype_register_tvbuff(void)
{
static ftype_t protocol_type = {
"FT_PROTOCOL",
"protocol",
0,
value_new,
NULL,
NULL, /* val_from_unparsed */
NULL, /* val_from_string */
NULL, /* val_to_string_repr */
NULL, /* len_string_repr */
value_set,
NULL,
NULL,
value_get,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
len,
slice,
};
ftype_register(FT_PROTOCOL, &protocol_type);
}
|