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
This commit is contained in:
parent
0bc13df91e
commit
f84bce97cc
54
text2pcap.c
54
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
|
||||
|
@ -282,6 +280,15 @@ write_byte (char *str)
|
|||
curr_offset ++;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
* Remove bytes from the current packet
|
||||
*/
|
||||
static int
|
||||
unwrite_bytes (unsigned long nbytes)
|
||||
{
|
||||
curr_offset -= nbytes;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
* Compute one's complement checksum (from RFC1071)
|
||||
*/
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue