aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2004-09-04 01:32:13 +0000
committerGuy Harris <guy@alum.mit.edu>2004-09-04 01:32:13 +0000
commit3c7631aa32de7a630bd48eec5ef5b67f3c6cdb10 (patch)
treead801a014e03217ed71f957d22ad55b8bc00c9ac /epan
parent22c088b8ab19622f935953ab6e12456025564c4b (diff)
Split the pure range stuff out into separate files, exporting their own
functions. svn path=/trunk/; revision=11892
Diffstat (limited to 'epan')
-rw-r--r--epan/Makefile.common2
-rw-r--r--epan/libethereal.def6
-rw-r--r--epan/packet-range.c215
-rw-r--r--epan/packet-range.h15
-rw-r--r--epan/range.c260
-rw-r--r--epan/range.h56
6 files changed, 329 insertions, 225 deletions
diff --git a/epan/Makefile.common b/epan/Makefile.common
index 8ebf9a803d..fe3467f00e 100644
--- a/epan/Makefile.common
+++ b/epan/Makefile.common
@@ -41,6 +41,7 @@ LIBETHEREAL_SRC = \
packet-range.c \
plugins.c \
proto.c \
+ range.c \
sna-utils.c \
strutil.c \
timestamp.c \
@@ -75,6 +76,7 @@ LIBETHEREAL_INCLUDES = \
pint.h \
plugins.h \
proto.h \
+ range.h \
report_err.h \
slab.h \
sna-utils.h \
diff --git a/epan/libethereal.def b/epan/libethereal.def
index d3296d03ee..0f9865596d 100644
--- a/epan/libethereal.def
+++ b/epan/libethereal.def
@@ -414,6 +414,8 @@ proto_tree_children_foreach
proto_tree_get_parent
p_add_proto_data
p_get_proto_data
+range_convert_str
+range_init
RasMessage_vals DATA
read_prefs
read_prefs_file
@@ -505,8 +507,6 @@ UnregRequestReason_vals DATA
vals_pdu_type DATA
vals_status DATA
val_to_str
+value_is_in_range
write_prefs
xml_escape
-
-
-
diff --git a/epan/packet-range.c b/epan/packet-range.c
index c786afb3f9..c88717e966 100644
--- a/epan/packet-range.c
+++ b/epan/packet-range.c
@@ -40,10 +40,6 @@
#include "globals.h"
-
-static gboolean packet_is_in_range(packet_range_t *range, guint32 val);
-
-
/* (re-)calculate the packet counts (except the user specified range) */
void packet_range_calc(packet_range_t *range) {
guint32 current_count;
@@ -146,7 +142,7 @@ void packet_range_calc_user(packet_range_t *range) {
for(packet = cfile.plist; packet != NULL; packet = packet->next) {
current_count++;
- if (packet_is_in_range(range, current_count)) {
+ if (value_is_in_range(&range->user_range, current_count)) {
range->user_range_cnt++;
if (packet->flags.passed_dfilter) {
range->displayed_user_range_cnt++;
@@ -161,9 +157,7 @@ void packet_range_init(packet_range_t *range) {
range->process = range_process_all;
range->process_filtered = FALSE;
- range->nranges = 0;
- range->ranges[range->nranges].low = 0L;
- range->ranges[range->nranges].high = 0L;
+ range_init(&range->user_range);
/* calculate all packet range counters */
packet_range_calc(range);
@@ -225,7 +219,7 @@ range_process_e packet_range_process_packet(packet_range_t *range, frame_data *f
}
break;
case(range_process_user_range):
- if (packet_is_in_range(range, fdata->num) == FALSE) {
+ if (value_is_in_range(&range->user_range, fdata->num) == FALSE) {
return range_process_next;
}
break;
@@ -245,214 +239,15 @@ range_process_e packet_range_process_packet(packet_range_t *range, frame_data *f
/******************** Range Entry Parser *********************************/
-/* Converts a range string to a fast comparable array of ranges.
+/* Converts a range string to a user range.
* The parameter 'es' points to the string to be converted, and is defined in
* the Save/Print-As widget.
- *
- * This function fills the array ranges containing low and high values indexed
- * by a global variable nranges. After having called this function, the function
- * packet_is_in_range() determines whether a given (packet) number is within
- * the range or not.
- *
- * In case of a single packet number, we make a range where low is equal to high.
- * We strip any characters other than commas, digits, or hyphens. We take care
- * on wrongly entered ranges; opposite order will be taken care of.
- *
- * The following syntax is accepted :
- *
- * 1-20,30-40 Range from 1 to 20, and packets 30 to 40
- * -20,30 Range from 1 to 20, and packet 30
- * 20,30,40- Packet number 20, 30, and the range from 40 to the end
- * 20-10,30-25 Range from 10 to 20, and from 25 to 30
- * - All packets
*/
void packet_range_convert_str(packet_range_t *range, const gchar *es)
{
- gchar EntryStr[255], OrgStr[255], value[255], p;
- guint i, j=0;
- guint32 tmp, val;
- gboolean hyphenseen;
-
- /* Reset the number of ranges we are going to find */
- range->nranges = 0;
- range->ranges[range->nranges].low = 0L;
- range->ranges[range->nranges].high = 0L;
-
- /* Make a copy of the string, and check the validity of the input */
- strcpy(OrgStr,es);
- if (strlen(OrgStr) == 0 ) {
- return;
- }
-
- /* Only keep digits, commas, and hyphens. */
- for (i=0; i<=strlen(OrgStr); i++) {
- if ( isdigit((guchar)OrgStr[i]) || OrgStr[i] == '-' || OrgStr[i] == ',' ) {
- EntryStr[j++] = OrgStr[i];
- }
- }
- EntryStr[j] = '\0';
-
- /* Remove any starting commas */
- strcpy(OrgStr,EntryStr);
- i = 0;
- while (OrgStr[i] == ',') {
- i++;
- }
- strcpy(EntryStr,OrgStr+i);
-
- /* Remove any double commas */
- strcpy(OrgStr,EntryStr);
- p = ',';
- j = 0;
- for (i=0; i<=strlen(OrgStr); i++) {
- if ( OrgStr[i] != ',' || p != ',') {
- EntryStr[j++] = OrgStr[i];
- }
- p = OrgStr[i];
- }
- EntryStr[j] = '\0';
-
- /* Remove any double hyphens */
- strcpy(OrgStr,EntryStr);
- p = '-';
- j = 0;
- for (i=0; i<=strlen(OrgStr); i++) {
- if (OrgStr[i] != '-' || p != '-' || i == 0) {
- EntryStr[j++] = OrgStr[i];
- }
- p = OrgStr[i];
- }
- EntryStr[j] = '\0';
-
- /* Remove any trailing commas */
- i = strlen(EntryStr) - 1;
- while (EntryStr[i] == ',') {
- EntryStr[i] = '\0';
- i--;
- }
-
- /* The entry string is now filtered, and ready for further parsing */
- /* printf("Function : packet_range_convert_str EntryStr = %s\n",EntryStr); */
-
- /* Now we are going to process the ranges separately until we get a comma,
- * or end of string.
- *
- * We build a structure array called ranges of high and low values. After the
- * following loop, we have the nranges variable which tells how many ranges
- * were found. The number of individual ranges is limited to 'MaxRanges'
- */
-
- j = 0;
- hyphenseen = FALSE;
- for (i=0; i<=strlen(EntryStr);i++) {
-
- /* Copy the digit string until a no-digit character is seen */
- if (isdigit((guchar)EntryStr[i])) {
- value[j++] = EntryStr[i];
- continue;
- }
-
- /* Terminate the digit string, and convert it */
- value[j] = '\0';
- val=atol(value);
- j=0;
-
- /* In case we see a hyphen, store the value we read in the low part
- * of ranges. In case it is a trailer hyphen, store the low value, and
- * set the high value to the maximum of packets captured.
- */
- if (EntryStr[i] == '-') {
- /* If this is a trailer hyphen, then treat it in a different
- * way, then the high value is the maximum number of packets counted
- * and we are ready
- */
- if (i == strlen(EntryStr)-1) {
- range->ranges[range->nranges].low = val;
- range->ranges[range->nranges].high = cfile.count;
- range->nranges++;
- break;
- } else {
- /* Store the low value of the range */
- range->ranges[range->nranges].low = val;
- }
- hyphenseen=TRUE;
- continue;
- }
-
- /* In case we see a comma, or end of string */
- if (EntryStr[i] == ',' || i == strlen(EntryStr)) {
- if (hyphenseen) {
- /* Normal treatment: store the high value range in ranges */
- range->ranges[range->nranges].high = val;
- } else {
- /* We did not see a hyphen and we get a comma, then this must
- * be a single packet number */
- range->ranges[range->nranges].low = val;
- range->ranges[range->nranges].high = val;
- }
- hyphenseen=FALSE;
- }
-
- /* Increase the index for the number of ranges we found, and protect
- * against wildly outside array bound jumps */
- range->nranges++;
- if (range->nranges > MaxRange) {
- range->nranges--;
- }
- }
- range->nranges--;
-
- /* Now we are going through the low and high values, and check
- * whether they are in a proper order. Low should be equal or lower
- * than high. So, go through the loop and swap if needed.
- */
- for (i=0; i <= range->nranges; i++) {
- if (range->ranges[i].low > range->ranges[i].high) {
- tmp = range->ranges[i].low;
- range->ranges[i].low = range->ranges[i].high;
- range->ranges[i].high = tmp;
- }
- }
-
- /* In case we want to know what the result ranges are :
- *
- * for (i=0; i <= nranges; i++) {
- * printf("Function : packet_range_convert_str L=%u \t H=%u\n",ranges[i].low,ranges[i].high);
- * }
- *
- */
+ range_convert_str(&range->user_range, es, cfile.count);
/* calculate new user specified packet range counts */
packet_range_calc_user(range);
} /* packet_range_convert_str */
-
-/* This function returns TRUE if a given value is within one of the ranges
- * stored in the ranges array.
- */
-static gboolean packet_is_in_range(packet_range_t *range, guint32 val)
-{
- guint i;
-
- for (i=0; i <= range->nranges; i++) {
- if (val >= range->ranges[i].low && val <= range->ranges[i].high)
- return TRUE;
- }
- return(FALSE);
-}
-
-#if 0
-/* This is a debug function to check the range functionality */
-static void packet_is_in_range_check(packet_range_t *range, guint32 val)
-{
-
- /* Print the result for a given value */
- printf("Function : packet_is_in_range_check Number %u\t",val);
-
- if (packet_is_in_range(range, val)) {
- printf("is in range\n");
- } else {
- printf("is not in range\n");
- }
-}
-#endif
diff --git a/epan/packet-range.h b/epan/packet-range.h
index 24789c2743..3007d215c8 100644
--- a/epan/packet-range.h
+++ b/epan/packet-range.h
@@ -32,6 +32,8 @@
#include <epan/frame_data.h>
+#include <epan/range.h>
+
extern guint32 curr_selected_frame;
typedef enum {
@@ -42,23 +44,13 @@ typedef enum {
range_process_user_range
} packet_range_e;
-/* Range parser variables */
-#define MaxRange 30
-
-typedef struct range_admin_tag {
- guint32 low;
- guint32 high;
-} range_admin_t;
-
-
typedef struct packet_range_tag {
/* values coming from the UI */
packet_range_e process; /* which range to process */
gboolean process_filtered; /* captured or filtered packets */
/* user specified range(s) */
- guint nranges; /* number of entries in ranges (0 based) */
- range_admin_t ranges[MaxRange];
+ range_t user_range;
/* calculated values */
guint32 selected_packet; /* the currently selected packet */
@@ -102,5 +94,4 @@ extern range_process_e packet_range_process_packet(packet_range_t *range, frame_
/* convert user given string to the internal user specified range representation */
extern void packet_range_convert_str(packet_range_t *range, const gchar *es);
-
#endif /* __PACKET_RANGE_H__ */
diff --git a/epan/range.c b/epan/range.c
new file mode 100644
index 0000000000..cd6eb7f2e5
--- /dev/null
+++ b/epan/range.c
@@ -0,0 +1,260 @@
+/* range.c
+ * Range routines
+ *
+ * $Id$
+ *
+ * Dick Gooris <gooris@lucent.com>
+ * Ulf Lamping <ulf.lamping@web.de>
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 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 <string.h>
+#include <ctype.h>
+
+#include <glib.h>
+
+#include <epan/frame_data.h>
+
+#include <epan/range.h>
+
+#include "globals.h"
+
+/* init the range struct */
+void range_init(range_t *range) {
+
+ range->nranges = 0;
+ range->ranges[range->nranges].low = 0L;
+ range->ranges[range->nranges].high = 0L;
+}
+
+/******************** Range Entry Parser *********************************/
+
+/* Converts a range string to a fast comparable array of ranges.
+ * The parameter 'es' points to the string to be converted.
+ * The parameter 'max_value' specifies the maximum value in a
+ * range.
+ *
+ * This function fills the array ranges containing low and high values indexed
+ * by a global variable nranges. After having called this function, the
+ * function value_is_in_range() determines whether a given number is within
+ * the range or not.
+ *
+ * In case of a single number, we make a range where low is equal to high.
+ * We strip any characters other than commas, digits, or hyphens. We take care
+ * on wrongly entered ranges; opposite order will be taken care of.
+ *
+ * The following syntax is accepted :
+ *
+ * 1-20,30-40 Range from 1 to 20, and packets 30 to 40
+ * -20,30 Range from 1 to 20, and packet 30
+ * 20,30,40- 20, 30, and the range from 40 to the end
+ * 20-10,30-25 Range from 10 to 20, and from 25 to 30
+ * - All values
+ */
+
+void range_convert_str(range_t *range, const gchar *es, guint32 max_value)
+{
+ gchar EntryStr[255], OrgStr[255], value[255], p;
+ guint i, j=0;
+ guint32 tmp, val;
+ gboolean hyphenseen;
+
+ /* Reset the number of ranges we are going to find */
+ range->nranges = 0;
+ range->ranges[range->nranges].low = 0L;
+ range->ranges[range->nranges].high = 0L;
+
+ /* Make a copy of the string, and check the validity of the input */
+ strcpy(OrgStr,es);
+ if (strlen(OrgStr) == 0 ) {
+ return;
+ }
+
+ /* Only keep digits, commas, and hyphens. */
+ for (i=0; i<=strlen(OrgStr); i++) {
+ if ( isdigit((guchar)OrgStr[i]) || OrgStr[i] == '-' || OrgStr[i] == ',' ) {
+ EntryStr[j++] = OrgStr[i];
+ }
+ }
+ EntryStr[j] = '\0';
+
+ /* Remove any starting commas */
+ strcpy(OrgStr,EntryStr);
+ i = 0;
+ while (OrgStr[i] == ',') {
+ i++;
+ }
+ strcpy(EntryStr,OrgStr+i);
+
+ /* Remove any double commas */
+ strcpy(OrgStr,EntryStr);
+ p = ',';
+ j = 0;
+ for (i=0; i<=strlen(OrgStr); i++) {
+ if ( OrgStr[i] != ',' || p != ',') {
+ EntryStr[j++] = OrgStr[i];
+ }
+ p = OrgStr[i];
+ }
+ EntryStr[j] = '\0';
+
+ /* Remove any double hyphens */
+ strcpy(OrgStr,EntryStr);
+ p = '-';
+ j = 0;
+ for (i=0; i<=strlen(OrgStr); i++) {
+ if (OrgStr[i] != '-' || p != '-' || i == 0) {
+ EntryStr[j++] = OrgStr[i];
+ }
+ p = OrgStr[i];
+ }
+ EntryStr[j] = '\0';
+
+ /* Remove any trailing commas */
+ i = strlen(EntryStr) - 1;
+ while (EntryStr[i] == ',') {
+ EntryStr[i] = '\0';
+ i--;
+ }
+
+ /* The entry string is now filtered, and ready for further parsing */
+ /* printf("Function : range_convert_str EntryStr = %s\n",EntryStr); */
+
+ /* Now we are going to process the ranges separately until we get a comma,
+ * or end of string.
+ *
+ * We build a structure array called ranges of high and low values. After the
+ * following loop, we have the nranges variable which tells how many ranges
+ * were found. The number of individual ranges is limited to 'MaxRanges'
+ */
+
+ j = 0;
+ hyphenseen = FALSE;
+ for (i=0; i<=strlen(EntryStr);i++) {
+
+ /* Copy the digit string until a no-digit character is seen */
+ if (isdigit((guchar)EntryStr[i])) {
+ value[j++] = EntryStr[i];
+ continue;
+ }
+
+ /* Terminate the digit string, and convert it */
+ value[j] = '\0';
+ val=atol(value);
+ j=0;
+
+ /* In case we see a hyphen, store the value we read in the low part
+ * of ranges. In case it is a trailer hyphen, store the low value, and
+ * set the high value to the maximum of packets captured.
+ */
+ if (EntryStr[i] == '-') {
+ /* If this is a trailer hyphen, then treat it in a different
+ * way, then the high value is the maximum value and we are ready
+ */
+ if (i == strlen(EntryStr)-1) {
+ range->ranges[range->nranges].low = val;
+ range->ranges[range->nranges].high = max_value;
+ range->nranges++;
+ break;
+ } else {
+ /* Store the low value of the range */
+ range->ranges[range->nranges].low = val;
+ }
+ hyphenseen=TRUE;
+ continue;
+ }
+
+ /* In case we see a comma, or end of string */
+ if (EntryStr[i] == ',' || i == strlen(EntryStr)) {
+ if (hyphenseen) {
+ /* Normal treatment: store the high value range in ranges */
+ range->ranges[range->nranges].high = val;
+ } else {
+ /* We did not see a hyphen and we get a comma, then this must
+ * be a single number */
+ range->ranges[range->nranges].low = val;
+ range->ranges[range->nranges].high = val;
+ }
+ hyphenseen=FALSE;
+ }
+
+ /* Increase the index for the number of ranges we found, and protect
+ * against wildly outside array bound jumps */
+ range->nranges++;
+ if (range->nranges > MaxRange) {
+ range->nranges--;
+ }
+ }
+ range->nranges--;
+
+ /* Now we are going through the low and high values, and check
+ * whether they are in a proper order. Low should be equal or lower
+ * than high. So, go through the loop and swap if needed.
+ */
+ for (i=0; i <= range->nranges; i++) {
+ if (range->ranges[i].low > range->ranges[i].high) {
+ tmp = range->ranges[i].low;
+ range->ranges[i].low = range->ranges[i].high;
+ range->ranges[i].high = tmp;
+ }
+ }
+
+ /* In case we want to know what the result ranges are :
+ *
+ * for (i=0; i <= nranges; i++) {
+ * printf("Function : range_convert_str L=%u \t H=%u\n",ranges[i].low,ranges[i].high);
+ * }
+ *
+ */
+} /* range_convert_str */
+
+/* This function returns TRUE if a given value is within one of the ranges
+ * stored in the ranges array.
+ */
+gboolean value_is_in_range(range_t *range, guint32 val)
+{
+ guint i;
+
+ for (i=0; i <= range->nranges; i++) {
+ if (val >= range->ranges[i].low && val <= range->ranges[i].high)
+ return TRUE;
+ }
+ return(FALSE);
+}
+
+#if 0
+/* This is a debug function to check the range functionality */
+static void value_is_in_range_check(range_t *range, guint32 val)
+{
+
+ /* Print the result for a given value */
+ printf("Function : value_is_in_range_check Number %u\t",val);
+
+ if (value_is_in_range(range, val)) {
+ printf("is in range\n");
+ } else {
+ printf("is not in range\n");
+ }
+}
+#endif
diff --git a/epan/range.h b/epan/range.h
new file mode 100644
index 0000000000..7dc46eb0cf
--- /dev/null
+++ b/epan/range.h
@@ -0,0 +1,56 @@
+/* range.h
+ * Range routines
+ *
+ * $Id$
+ *
+ * Dick Gooris <gooris@lucent.com>
+ * Ulf Lamping <ulf.lamping@web.de>
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 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.
+ */
+
+#ifndef __RANGE_H__
+#define __RANGE_H__
+
+#include <glib.h>
+
+#include <epan/frame_data.h>
+
+/* Range parser variables */
+#define MaxRange 30
+
+typedef struct range_admin_tag {
+ guint32 low;
+ guint32 high;
+} range_admin_t;
+
+typedef struct range {
+ /* user specified range(s) */
+ guint nranges; /* number of entries in ranges (0 based) */
+ range_admin_t ranges[MaxRange];
+} range_t;
+
+extern void range_init(range_t *range);
+
+extern void range_convert_str(range_t *range, const gchar *es,
+ guint32 max_value);
+
+extern gboolean value_is_in_range(range_t *range, guint32 val);
+
+#endif /* __RANGE_H__ */