2 * Implements a tvbuff for frame
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <epan/packet.h>
30 #include <epan/tvbuff-int.h>
31 #include <epan/tvbuff.h>
33 #include "frame_tvbuff.h"
35 /* XXX, to read data with wtap_seek_read() we need:
36 * cf->wth, fdata->file_off, fdata->cap_len
37 * add when ready to structure below
47 return sizeof(struct tvb_frame);
51 frame_offset(const tvbuff_t *tvb _U_, const guint counter)
56 static const struct tvb_ops tvb_frame_ops = {
57 frame_sizeof, /* size */
59 frame_offset, /* offset */
62 NULL, /* find_guint8 */
63 NULL, /* pbrk_guint8 */
66 /* based on tvb_new_real_data() */
68 frame_tvbuff_new(const frame_data *fd, const guint8 *buf)
72 tvb = tvb_new(&tvb_frame_ops);
75 * XXX - currently, the length arguments in
76 * tvbuff structure are signed, but the captured
77 * and reported length values are unsigned; this means
78 * that length values > 2^31 - 1 will appear as
81 * Captured length values that large will already
82 * have been filtered out by the Wiretap modules
83 * (the file will be reported as corrupted), to
84 * avoid trying to allocate large chunks of data.
86 * Reported length values will not have been
87 * filtered out, and should not be filtered out,
88 * as those lengths are not necessarily invalid.
90 * For now, we clip the reported length at G_MAXINT
92 * (XXX, is this still a problem?) There was an exception when we call
93 * tvb_new_real_data() now there's no one
97 tvb->length = fd->cap_len;
98 tvb->reported_length = fd->pkt_len > G_MAXINT ? G_MAXINT : fd->pkt_len;
99 tvb->initialized = TRUE;
102 * This is the top-level real tvbuff for this data source,
103 * so its data source tvbuff is itself.
111 frame_tvbuff_new_buffer(const frame_data *fd, Buffer *buf)
113 return frame_tvbuff_new(fd, buffer_start_ptr(buf));