aboutsummaryrefslogtreecommitdiffstats
path: root/text2pcap.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-11-24 07:52:05 +0000
committerGuy Harris <guy@alum.mit.edu>2001-11-24 07:52:05 +0000
commitf84bce97ccbf3ea9ae331019a3434265806465a1 (patch)
tree2068f22c1be17ad5f6be19ed3291641718ed6ca9 /text2pcap.c
parent0bc13df91eb514f8aecc4e5838aa03c45502898e (diff)
If the expected "next offset" doesn't match the offset we read, it may
merely mean that we mistakenly treated stuff from the text-dump part of the file we're reading as if it were hex byte data (e.g., if the first non-white-space part of the text dump was a 2-digit hex number). If the offset we read is less than the expected next offset, assume that's the problem, and throw away enough extra bytes to make the offset we read the expected next offset. "getopt()" will never, for any option that the "getopt()" string says takes an argument, leave "optarg" null; if no argument was specified, it'll return an error, so there's no need to check for a null "optarg". svn path=/trunk/; revision=4250
Diffstat (limited to 'text2pcap.c')
-rw-r--r--text2pcap.c54
1 files changed, 36 insertions, 18 deletions
diff --git a/text2pcap.c b/text2pcap.c
index d760828210..796ea48f83 100644
--- a/text2pcap.c
+++ b/text2pcap.c
@@ -6,14 +6,12 @@
*
* (c) Copyright 2001 Ashok Narayanan <ashokn@cisco.com>
*
- * $Id: text2pcap.c,v 1.4 2001/08/01 03:22:14 guy Exp $
+ * $Id: text2pcap.c,v 1.5 2001/11/24 07:52:05 guy Exp $
*
* 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
@@ -283,6 +281,15 @@ write_byte (char *str)
}
/*----------------------------------------------------------------------
+ * Remove bytes from the current packet
+ */
+static int
+unwrite_bytes (unsigned long nbytes)
+{
+ curr_offset -= nbytes;
+}
+
+/*----------------------------------------------------------------------
* Compute one's complement checksum (from RFC1071)
*/
static unsigned short
@@ -484,12 +491,26 @@ parse_token (token_t token, char *str)
start_new_packet();
state = READ_OFFSET;
} else if (num != curr_offset) {
- /* Bad offset; switch to INIT state */
- if (debug>=1)
- fprintf(stderr, "Inconsistent offset. Expecting %0lX, got %0lX. Ignoring rest of packet\n",
- curr_offset, num);
- write_current_packet();
- state = INIT;
+ /*
+ * The offset we read isn't the one we expected.
+ * This may only mean that we mistakenly interpreted
+ * some text as byte values (e.g., if the text dump
+ * of packet data included a number with spaces around
+ * it). If the offset is less than what we expected,
+ * assume that's the problem, and throw away the putative
+ * extra byte values.
+ */
+ if (num < curr_offset) {
+ unwrite_bytes(curr_offset - num);
+ state = READ_OFFSET;
+ } else {
+ /* Bad offset; switch to INIT state */
+ if (debug>=1)
+ fprintf(stderr, "Inconsistent offset. Expecting %0lX, got %0lX. Ignoring rest of packet\n",
+ curr_offset, num);
+ write_current_packet();
+ state = INIT;
+ }
} else
state = READ_OFFSET;
break;
@@ -614,27 +635,24 @@ parse_options (int argc, char *argv[])
case 'q': quiet = TRUE; debug = FALSE; break;
case 'l': pcap_link_type = atoi(optarg); break;
case 'o':
- if (!optarg || (optarg[0]!='h' && optarg[0] != 'o')) {
- fprintf(stderr, "Bad argument for '-e': %s\n",
- optarg ? optarg : "");
+ if (optarg[0]!='h' && optarg[0] != 'o') {
+ fprintf(stderr, "Bad argument for '-e': %s\n", optarg);
help(argv[0]);
}
offset_base = (optarg[0]=='o') ? 8 : 16;
break;
case 'e':
hdr_ethernet = TRUE;
- if (!optarg || sscanf(optarg, "%lx", &hdr_ethernet_proto) < 1) {
- fprintf(stderr, "Bad argument for '-e': %s\n",
- optarg ? optarg : "");
+ if (sscanf(optarg, "%lx", &hdr_ethernet_proto) < 1) {
+ fprintf(stderr, "Bad argument for '-e': %s\n", optarg);
help(argv[0]);
}
break;
case 'i':
hdr_ip = TRUE;
- if (!optarg || sscanf(optarg, "%ld", &hdr_ip_proto) < 1) {
- fprintf(stderr, "Bad argument for '-i': %s\n",
- optarg ? optarg : "");
+ if (sscanf(optarg, "%ld", &hdr_ip_proto) < 1) {
+ fprintf(stderr, "Bad argument for '-i': %s\n", optarg);
help(argv[0]);
}
hdr_ethernet = TRUE;