3 * Proto Tree TVBuff cursor
4 * Gilbert Ramirez <gram@alumni.rice.edu>
6 * $Id: ptvcursor.c,v 1.7 2002/08/28 21:00:41 jmayer Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 2000 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include "ptvcursor.h"
37 /* Allocates an initializes a ptvcursor_t with 3 variables:
38 * proto_tree, tvbuff, and offset. */
40 ptvcursor_new(proto_tree *tree, tvbuff_t *tvb, gint offset)
44 ptvc = g_new(ptvcursor_t, 1);
47 ptvc->offset = offset;
52 /* Gets data from tvbuff, adds it to proto_tree, increments offset,
53 * and returns proto_item* */
55 ptvcursor_add(ptvcursor_t *ptvc, int hf, gint length, gboolean endianness)
59 item = ptvcursor_add_no_advance(ptvc, hf, length, endianness);
60 ptvc->offset += proto_item_get_len(item);
64 /* Gets data from tvbuff, adds it to proto_tree, *DOES NOT* increment
65 * offset, and returns proto_item* */
67 ptvcursor_add_no_advance(ptvcursor_t* ptvc, int hf, gint length,
72 item = proto_tree_add_item(ptvc->tree, hf, ptvc->tvb, ptvc->offset,
78 /* Advance the ptvcursor's offset within its tvbuff without
79 * adding anything to the proto_tree. */
81 ptvcursor_advance(ptvcursor_t* ptvc, gint length)
83 ptvc->offset += length;
86 /* Frees memory for ptvcursor_t, but nothing deeper than that. */
88 ptvcursor_free(ptvcursor_t *ptvc)
94 ptvcursor_tvbuff(ptvcursor_t* ptvc)
99 /* Returns current offset. */
101 ptvcursor_current_offset(ptvcursor_t* ptvc)
107 ptvcursor_tree(ptvcursor_t* ptvc)
113 ptvcursor_set_tree(ptvcursor_t* ptvc, proto_tree *tree)