2 * capture_file GUI-independent manipulation
3 * Vassilii Khachaturov <vassilii@tarunz.org>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <epan/packet.h>
37 cap_file_init(capture_file *cf)
39 /* Initialize the capture file struct */
40 cf->plist_start = NULL;
45 cf->user_saved = FALSE;
46 cf->is_tempfile = FALSE;
50 cf->snap = WTAP_MAX_PACKET_SIZE;
52 cf->last_found_num = 0;
53 cf->last_found_fd = NULL;
54 cf->redissecting = FALSE;
58 cap_file_add_fdata(capture_file *cf, frame_data *fdata)
60 frame_data *plist_end = cf->plist_end;
61 fdata->prev = plist_end;
62 if (plist_end != NULL)
63 plist_end->next = fdata;
65 cf->plist_start = fdata;
66 cf->plist_end = fdata;
70 * Find the frame_data for the specified frame number.
71 * Do some caching to make this work reasonably fast for
72 * forward and backward sequential passes through the packets.
75 cap_file_find_fdata(capture_file *cf, guint32 num)
80 /* There is no frame number 0 */
85 * Did we remember a frame number from a sequential pass through
88 if (cf->last_found_num != 0) {
90 * Yes. Is this that frame?
92 if (num == cf->last_found_num) {
93 /* Yes - return it. */
94 return cf->last_found_fd;
98 * No. Is it the frame just after that frame?
100 if (num == cf->last_found_num + 1) {
102 * Yes - if there is such a frame, remember it and return it.
104 fdata = cf->last_found_fd->next;
106 cf->last_found_num = num;
107 cf->last_found_fd = fdata;
109 return fdata; /* could be null, if there is no such frame */
113 * No. Is it the frame just before that frame?
115 if (num == cf->last_found_num - 1) {
117 * Yes - if there is such a frame, remember it and return it.
119 fdata = cf->last_found_fd->prev;
121 cf->last_found_num = num;
122 cf->last_found_fd = fdata;
124 return fdata; /* could be null, if there is no such frame */
128 for (fdata = cf->plist_start; fdata != NULL && fdata->num < num;
132 cf->last_found_num = num;
133 cf->last_found_fd = fdata;