2 * Packet range routines (save, print, ...)
6 * Dick Gooris <gooris@lucent.com>
7 * Ulf Lamping <ulf.lamping@web.de>
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #include <epan/frame_data.h>
39 #include <epan/packet-range.h>
43 /* (re-)calculate the packet counts (except the user specified range) */
44 void packet_range_calc(packet_range_t *range) {
45 guint32 current_count;
48 guint32 displayed_mark_low;
49 guint32 displayed_mark_high;
53 range->selected_packet = 0L;
57 range->mark_range_cnt = 0L;
59 displayed_mark_low = 0L;
60 displayed_mark_high = 0L;
61 range->displayed_cnt = 0L;
62 range->displayed_marked_cnt = 0L;
63 range->displayed_mark_range_cnt=0L;
65 /* The next for-loop is used to obtain the amount of packets to be processed
66 * and is used to present the information in the Save/Print As widget.
67 * We have different types of ranges: All the packets, the number
68 * of packets of a marked range, a single packet, and a user specified
69 * packet range. The last one is not calculated here since this
70 * data must be entered in the widget by the user.
74 for(packet = cfile.plist; packet != NULL; packet = packet->next) {
76 if (cfile.current_frame == packet) {
77 range->selected_packet = current_count;
79 if (packet->flags.passed_dfilter) {
80 range->displayed_cnt++;
82 if (packet->flags.marked) {
83 if (packet->flags.passed_dfilter) {
84 range->displayed_marked_cnt++;
85 if (displayed_mark_low == 0) {
86 displayed_mark_low = current_count;
88 if (current_count > displayed_mark_high) {
89 displayed_mark_high = current_count;
94 mark_low = current_count;
96 if (current_count > mark_high) {
97 mark_high = current_count;
103 for(packet = cfile.plist; packet != NULL; packet = packet->next) {
106 if (current_count >= mark_low &&
107 current_count <= mark_high)
109 range->mark_range_cnt++;
112 if (current_count >= displayed_mark_low &&
113 current_count <= displayed_mark_high)
115 if (packet->flags.passed_dfilter) {
116 range->displayed_mark_range_cnt++;
121 /* in case we marked just one packet, we add 1. */
122 /*if (cfile.marked_count != 0) {
123 range->mark_range = mark_high - mark_low + 1;
126 /* in case we marked just one packet, we add 1. */
127 /*if (range->displayed_marked_cnt != 0) {
128 range->displayed_mark_range = displayed_mark_high - displayed_mark_low + 1;
133 /* (re-)calculate the user specified packet range counts */
134 void packet_range_calc_user(packet_range_t *range) {
135 guint32 current_count;
138 range->user_range_cnt = 0L;
139 range->displayed_user_range_cnt = 0L;
142 for(packet = cfile.plist; packet != NULL; packet = packet->next) {
145 if (value_is_in_range(&range->user_range, current_count)) {
146 range->user_range_cnt++;
147 if (packet->flags.passed_dfilter) {
148 range->displayed_user_range_cnt++;
155 /* init the range struct */
156 void packet_range_init(packet_range_t *range) {
158 range->process = range_process_all;
159 range->process_filtered = FALSE;
160 range_init(&range->user_range);
162 /* calculate all packet range counters */
163 packet_range_calc(range);
164 packet_range_calc_user(range);
167 /* init the processing run */
168 void packet_range_process_init(packet_range_t *range) {
169 /* "enumeration" values */
170 range->marked_range_active = FALSE;
171 range->selected_done = FALSE;
173 if (range->process_filtered == FALSE) {
174 range->marked_range_left = range->mark_range_cnt;
176 range->marked_range_left = range->displayed_mark_range_cnt;
180 /* do we have to process all packets? */
181 gboolean packet_range_process_all(packet_range_t *range) {
182 return range->process == range_process_all && !range->process_filtered;
185 /* do we have to process this packet? */
186 range_process_e packet_range_process_packet(packet_range_t *range, frame_data *fdata) {
188 switch(range->process) {
189 case(range_process_all):
191 case(range_process_selected):
192 if (range->selected_done) {
193 return range_processing_finished;
195 if (fdata->num != cfile.current_frame->num) {
196 return range_process_next;
198 range->selected_done = TRUE;
200 case(range_process_marked):
201 if (fdata->flags.marked == FALSE) {
202 return range_process_next;
205 case(range_process_marked_range):
206 if (range->marked_range_left == 0) {
207 return range_processing_finished;
209 if (fdata->flags.marked == TRUE) {
210 range->marked_range_active = TRUE;
212 if (range->marked_range_active == FALSE ) {
213 return range_process_next;
215 if (!range->process_filtered ||
216 (range->process_filtered && fdata->flags.passed_dfilter == TRUE))
218 range->marked_range_left--;
221 case(range_process_user_range):
222 if (value_is_in_range(&range->user_range, fdata->num) == FALSE) {
223 return range_process_next;
227 g_assert_not_reached();
230 /* this packet has to pass the display filter but didn't? -> try next */
231 if (range->process_filtered && fdata->flags.passed_dfilter == FALSE) {
232 return range_process_next;
235 /* We fell through the conditions above, so we accept this packet */
236 return range_process_this;
240 /******************** Range Entry Parser *********************************/
242 /* Converts a range string to a user range.
243 * The parameter 'es' points to the string to be converted, and is defined in
244 * the Save/Print-As widget.
247 void packet_range_convert_str(packet_range_t *range, const gchar *es)
249 range_convert_str(&range->user_range, es, cfile.count);
251 /* calculate new user specified packet range counts */
252 packet_range_calc_user(range);
253 } /* packet_range_convert_str */