1999-09-11 04:53:26 +00:00
|
|
|
/* ascend.c
|
|
|
|
*
|
2002-08-28 20:30:45 +00:00
|
|
|
* $Id: ascend.c,v 1.31 2002/08/28 20:30:44 jmayer Exp $
|
1999-09-11 04:53:26 +00:00
|
|
|
*
|
|
|
|
* Wiretap Library
|
2001-11-13 23:55:44 +00:00
|
|
|
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
|
2002-08-28 20:30:45 +00:00
|
|
|
*
|
1999-09-11 04:53:26 +00:00
|
|
|
* 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.
|
2002-08-28 20:30:45 +00:00
|
|
|
*
|
1999-09-11 04:53:26 +00:00
|
|
|
* 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.
|
2002-08-28 20:30:45 +00:00
|
|
|
*
|
1999-09-11 04:53:26 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2002-03-04 00:25:35 +00:00
|
|
|
|
1999-09-11 04:53:26 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2000-05-19 23:07:04 +00:00
|
|
|
#include "wtap-int.h"
|
1999-09-11 04:53:26 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "ascend.h"
|
1999-10-08 07:45:31 +00:00
|
|
|
#include "ascend-int.h"
|
2000-01-13 07:09:20 +00:00
|
|
|
#include "file_wrappers.h"
|
1999-09-11 04:53:26 +00:00
|
|
|
|
2002-03-04 00:25:35 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
2000-08-11 13:37:21 +00:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
1999-09-11 04:53:26 +00:00
|
|
|
#include <sys/stat.h>
|
2000-08-11 13:37:21 +00:00
|
|
|
#endif
|
2000-01-10 17:33:17 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
1999-09-11 04:53:26 +00:00
|
|
|
#include <unistd.h>
|
2000-01-10 17:33:17 +00:00
|
|
|
#endif
|
|
|
|
|
1999-09-11 04:53:26 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/* This module reads the output of the 'wandsession', 'wannext',
|
|
|
|
'wandisplay', and similar commands available on Lucent/Ascend access
|
|
|
|
equipment. The output is text, with a header line followed by the
|
|
|
|
packet data. Usage instructions for the commands can be found by
|
|
|
|
searching http://aos.ascend.com . Ascend likes to move their pages
|
|
|
|
around quite a bit, otherwise I'd put a more specific URL here.
|
|
|
|
|
|
|
|
Example 'wandsess' output data:
|
2002-08-28 20:30:45 +00:00
|
|
|
|
1999-09-11 04:53:26 +00:00
|
|
|
RECV-iguana:241:(task: B02614C0, time: 1975432.85) 49 octets @ 8003BD94
|
2002-08-28 20:30:45 +00:00
|
|
|
[0000]: FF 03 00 3D C0 06 CA 22 2F 45 00 00 28 6A 3B 40
|
|
|
|
[0010]: 00 3F 03 D7 37 CE 41 62 12 CF 00 FB 08 20 27 00
|
|
|
|
[0020]: 50 E4 08 DD D7 7C 4C 71 92 50 10 7D 78 67 C8 00
|
|
|
|
[0030]: 00
|
1999-09-11 04:53:26 +00:00
|
|
|
XMIT-iguana:241:(task: B04E12C0, time: 1975432.85) 53 octets @ 8009EB16
|
2002-08-28 20:30:45 +00:00
|
|
|
[0000]: FF 03 00 3D C0 09 1E 31 21 45 00 00 2C 2D BD 40
|
|
|
|
[0010]: 00 7A 06 D8 B1 CF 00 FB 08 CE 41 62 12 00 50 20
|
|
|
|
[0020]: 29 7C 4C 71 9C 9A 6A 93 A4 60 12 22 38 3F 10 00
|
|
|
|
[0030]: 00 02 04 05 B4
|
1999-09-11 04:53:26 +00:00
|
|
|
|
2000-05-10 22:20:26 +00:00
|
|
|
Example 'wdd' output data:
|
|
|
|
|
|
|
|
Date: 01/12/1990. Time: 12:22:33
|
|
|
|
Cause an attempt to place call to 14082750382
|
|
|
|
WD_DIALOUT_DISP: chunk 2515EE type IP.
|
|
|
|
(task: 251790, time: 994953.28) 44 octets @ 2782B8
|
|
|
|
[0000]: 00 C0 7B 71 45 6C 00 60 08 16 AA 51 08 00 45 00
|
|
|
|
[0010]: 00 2C 66 1C 40 00 80 06 53 F6 AC 14 00 18 CC 47
|
|
|
|
[0020]: C8 45 0A 31 00 50 3B D9 5B 75 00 00
|
|
|
|
|
|
|
|
(note that the capture whence this came dates back to January
|
|
|
|
*1999*; I presume that either the person who sent it to me
|
|
|
|
hadn't bothered keeping its internal clock set, or that its
|
|
|
|
internal clock or the date it displays in those messages
|
|
|
|
is only loosely connected to reality)
|
|
|
|
|
1999-09-11 04:53:26 +00:00
|
|
|
Note that a maximum of eight rows will be displayed (for a maximum of
|
|
|
|
128 bytes), no matter what the octet count is.
|
2002-08-28 20:30:45 +00:00
|
|
|
|
|
|
|
When reading a packet, the module prepends an ascend_pkt_hdr to the
|
1999-09-11 04:53:26 +00:00
|
|
|
data.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* How far into the file we should look for packet headers */
|
1999-10-28 01:42:43 +00:00
|
|
|
#define ASCEND_MAX_SEEK 100000
|
1999-09-11 04:53:26 +00:00
|
|
|
|
1999-09-13 03:49:04 +00:00
|
|
|
/* XXX Should we replace this with a more generalized array? */
|
1999-09-11 04:53:26 +00:00
|
|
|
/* Magic numbers for Ascend wandsession/wanopening/ether-display data */
|
1999-09-13 03:49:04 +00:00
|
|
|
static const char ascend_xmagic[] = { 'X', 'M', 'I', 'T', '-' };
|
|
|
|
static const char ascend_rmagic[] = { 'R', 'E', 'C', 'V', '-' };
|
|
|
|
static const char ascend_w1magic[] = { 'D', 'a', 't', 'e', ':', };
|
|
|
|
static const char ascend_w2magic[] = { 'W', 'D', '_', 'D', 'I', 'A', 'L', 'O', 'U', 'T', '_', 'D', 'I', 'S', 'P', ':' };
|
1999-09-11 04:53:26 +00:00
|
|
|
|
1999-09-13 03:49:04 +00:00
|
|
|
#define ASCEND_X_SIZE (sizeof ascend_xmagic / sizeof ascend_xmagic[0])
|
|
|
|
#define ASCEND_R_SIZE (sizeof ascend_rmagic / sizeof ascend_rmagic[0])
|
|
|
|
#define ASCEND_W1_SIZE (sizeof ascend_w1magic / sizeof ascend_w1magic[0])
|
|
|
|
#define ASCEND_W2_SIZE (sizeof ascend_w2magic / sizeof ascend_w2magic[0])
|
1999-09-11 04:53:26 +00:00
|
|
|
|
2001-10-04 08:30:36 +00:00
|
|
|
static gboolean ascend_read(wtap *wth, int *err, long *data_offset);
|
2002-03-05 08:40:27 +00:00
|
|
|
static gboolean ascend_seek_read (wtap *wth, long seek_off,
|
2002-03-05 05:58:41 +00:00
|
|
|
union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err);
|
2000-03-22 07:06:59 +00:00
|
|
|
static void ascend_close(wtap *wth);
|
1999-09-11 06:49:42 +00:00
|
|
|
|
1999-09-11 04:53:26 +00:00
|
|
|
/* Seeks to the beginning of the next packet, and returns the
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
byte offset at which the heade for that packet begins.
|
|
|
|
Returns -1 on failure.
|
|
|
|
|
|
|
|
If it finds a packet, then, if "wth->capture.ascend" is non-null,
|
|
|
|
it sets "wth->capture.ascend->next_packet_seek_start" to the point
|
|
|
|
at which the seek pointer should be set before this routine is called
|
|
|
|
to find the packet *after* the packet it finds. */
|
2002-03-04 00:25:35 +00:00
|
|
|
static long ascend_seek(wtap *wth, int max_seek, int *err)
|
1999-09-11 04:53:26 +00:00
|
|
|
{
|
2001-10-04 08:30:36 +00:00
|
|
|
int byte, bytes_read = 0;
|
|
|
|
long date_off = -1, cur_off, packet_off;
|
2001-07-13 00:55:58 +00:00
|
|
|
unsigned int r_level = 0, x_level = 0, w1_level = 0, w2_level = 0;
|
1999-09-11 04:53:26 +00:00
|
|
|
|
1999-09-22 07:37:46 +00:00
|
|
|
while (((byte = file_getc(wth->fh)) != EOF) && bytes_read < max_seek) {
|
1999-09-11 04:53:26 +00:00
|
|
|
if (byte == ascend_xmagic[x_level]) {
|
|
|
|
x_level++;
|
|
|
|
if (x_level >= ASCEND_X_SIZE) {
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
/* At what offset are we now? */
|
|
|
|
cur_off = file_tell(wth->fh);
|
2002-03-04 00:25:35 +00:00
|
|
|
if (cur_off == -1) {
|
|
|
|
/* Error. */
|
|
|
|
*err = file_error(wth->fh);
|
|
|
|
return -1;
|
|
|
|
}
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
|
|
|
|
/* Back up over the header we just read; that's where a read
|
|
|
|
of this packet should start. */
|
|
|
|
packet_off = cur_off - ASCEND_X_SIZE;
|
|
|
|
goto found;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
1999-09-13 03:49:04 +00:00
|
|
|
} else {
|
|
|
|
x_level = 0;
|
|
|
|
}
|
|
|
|
if (byte == ascend_rmagic[r_level]) {
|
1999-09-11 04:53:26 +00:00
|
|
|
r_level++;
|
|
|
|
if (r_level >= ASCEND_R_SIZE) {
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
/* At what offset are we now? */
|
|
|
|
cur_off = file_tell(wth->fh);
|
2002-03-04 00:25:35 +00:00
|
|
|
if (cur_off == -1) {
|
|
|
|
/* Error. */
|
|
|
|
*err = file_error(wth->fh);
|
|
|
|
return -1;
|
|
|
|
}
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
|
|
|
|
/* Back up over the header we just read; that's where a read
|
|
|
|
of this packet should start. */
|
|
|
|
packet_off = cur_off - ASCEND_R_SIZE;
|
|
|
|
goto found;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
1999-09-13 03:49:04 +00:00
|
|
|
} else {
|
|
|
|
r_level = 0;
|
|
|
|
}
|
|
|
|
if (byte == ascend_w1magic[w1_level]) {
|
|
|
|
w1_level++;
|
|
|
|
if (w1_level >= ASCEND_W1_SIZE) {
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
/* Get the offset at which the "Date:" header started. */
|
2002-03-04 00:25:35 +00:00
|
|
|
cur_off = file_tell(wth->fh);
|
|
|
|
if (cur_off == -1) {
|
|
|
|
/* Error. */
|
|
|
|
*err = file_error(wth->fh);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
date_off = cur_off - ASCEND_W1_SIZE;
|
1999-09-13 03:49:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
w1_level = 0;
|
|
|
|
}
|
|
|
|
if (byte == ascend_w2magic[w2_level]) {
|
|
|
|
w2_level++;
|
2000-11-12 04:57:39 +00:00
|
|
|
if (w2_level >= ASCEND_W2_SIZE) {
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
/* At what offset are we now? */
|
|
|
|
cur_off = file_tell(wth->fh);
|
2002-03-04 00:25:35 +00:00
|
|
|
if (cur_off == -1) {
|
|
|
|
/* Error. */
|
|
|
|
*err = file_error(wth->fh);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
if (date_off != -1) {
|
|
|
|
/* This packet has a date/time header; a read of it should
|
|
|
|
start at the beginning of *that* header. */
|
|
|
|
packet_off = date_off;
|
|
|
|
} else {
|
|
|
|
/* This packet has only a per-packet header.
|
|
|
|
Back up over that header, which we just read; that's where
|
|
|
|
a read of this packet should start. */
|
|
|
|
packet_off = cur_off - ASCEND_W2_SIZE;
|
|
|
|
}
|
|
|
|
goto found;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
1999-09-13 03:49:04 +00:00
|
|
|
w2_level = 0;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
|
|
|
bytes_read++;
|
|
|
|
}
|
2002-03-04 00:25:35 +00:00
|
|
|
if (byte != EOF || file_eof(wth->fh)) {
|
|
|
|
/* Either we didn't find the offset, or we got an EOF. */
|
|
|
|
*err = 0;
|
|
|
|
} else {
|
|
|
|
/* We (presumably) got an error (there's no equivalent to "ferror()"
|
|
|
|
in zlib, alas, so we don't have a wrapper to check for an error). */
|
|
|
|
*err = file_error(wth->fh);
|
|
|
|
}
|
1999-09-11 04:53:26 +00:00
|
|
|
return -1;
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
|
|
|
|
found:
|
|
|
|
/*
|
|
|
|
* The search for the packet after this one should start right
|
|
|
|
* after the header for this packet. (Ideally, it should
|
|
|
|
* start after the *data* for this one, but we haven't
|
|
|
|
* read that yet.)
|
|
|
|
*/
|
|
|
|
if (wth->capture.ascend != NULL)
|
|
|
|
wth->capture.ascend->next_packet_seek_start = cur_off + 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move to where the read for this packet should start, and return
|
|
|
|
* that seek offset.
|
|
|
|
*/
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->fh, packet_off, SEEK_SET, err) == -1)
|
2002-03-04 00:25:35 +00:00
|
|
|
return -1;
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
return packet_off;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ascend_open(wtap *wth, int *err)
|
|
|
|
{
|
2001-10-04 08:30:36 +00:00
|
|
|
long offset;
|
2000-11-11 03:15:07 +00:00
|
|
|
struct stat statbuf;
|
1999-09-11 04:53:26 +00:00
|
|
|
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
/* We haven't yet allocated a data structure for our private stuff;
|
|
|
|
set the pointer to null, so that "ascend_seek()" knows not to
|
|
|
|
fill it in. */
|
|
|
|
wth->capture.ascend = NULL;
|
|
|
|
|
2002-03-04 00:25:35 +00:00
|
|
|
offset = ascend_seek(wth, ASCEND_MAX_SEEK, err);
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
if (offset == -1) {
|
2002-03-04 00:25:35 +00:00
|
|
|
if (*err == 0)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return -1;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wth->data_offset = offset;
|
|
|
|
wth->file_encap = WTAP_ENCAP_ASCEND;
|
|
|
|
wth->file_type = WTAP_FILE_ASCEND;
|
|
|
|
wth->snapshot_length = ASCEND_MAX_PKT_LEN;
|
|
|
|
wth->subtype_read = ascend_read;
|
2000-05-18 09:09:50 +00:00
|
|
|
wth->subtype_seek_read = ascend_seek_read;
|
2000-03-22 07:06:59 +00:00
|
|
|
wth->subtype_close = ascend_close;
|
1999-09-11 04:53:26 +00:00
|
|
|
wth->capture.ascend = g_malloc(sizeof(ascend_t));
|
|
|
|
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
/* The first packet we want to read is the one that "ascend_seek()"
|
|
|
|
just found; start searching for it at the offset at which it
|
|
|
|
found it. */
|
|
|
|
wth->capture.ascend->next_packet_seek_start = offset;
|
|
|
|
|
2002-08-28 20:30:45 +00:00
|
|
|
/* MAXen and Pipelines report the time since reboot. In order to keep
|
1999-09-11 22:36:38 +00:00
|
|
|
from reporting packet times near the epoch, we subtract the first
|
|
|
|
packet's timestamp from the capture file's ctime, which gives us an
|
|
|
|
offset that we can apply to each packet.
|
|
|
|
*/
|
2002-03-04 00:25:35 +00:00
|
|
|
if (fstat(wtap_fd(wth), &statbuf) == -1) {
|
|
|
|
*err = errno;
|
|
|
|
g_free(wth->capture.ascend);
|
|
|
|
return -1;
|
|
|
|
}
|
2000-11-11 03:15:07 +00:00
|
|
|
wth->capture.ascend->inittime = statbuf.st_ctime;
|
1999-09-11 04:53:26 +00:00
|
|
|
wth->capture.ascend->adjusted = 0;
|
|
|
|
|
|
|
|
init_parse_ascend();
|
1999-09-11 22:36:38 +00:00
|
|
|
|
1999-09-11 04:53:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the next packet; called from wtap_loop(). */
|
2001-10-04 08:30:36 +00:00
|
|
|
static gboolean ascend_read(wtap *wth, int *err, long *data_offset)
|
1999-09-11 04:53:26 +00:00
|
|
|
{
|
2001-10-04 08:30:36 +00:00
|
|
|
long offset;
|
1999-09-11 04:53:26 +00:00
|
|
|
guint8 *buf = buffer_start_ptr(wth->frame_buffer);
|
|
|
|
ascend_pkthdr header;
|
|
|
|
|
1999-09-22 07:37:46 +00:00
|
|
|
/* (f)lex reads large chunks of the file into memory, so file_tell() doesn't
|
2002-08-28 20:30:45 +00:00
|
|
|
give us the correct location of the packet. Instead, we seek to the
|
"wtap_loop()" no longer has problems with packet offsets of 0, so we
don't need to work around that.
The offset, for a given packet, at which "ascend_seek()" should start
searching for that packet's header must be computed separately from the
offset, for that packet, at which "ascend_seek()" should start searching
for the *next* packet - if the file is a "wdd" capture, and the packet
has a "Date:" header and a WD_DIALOUT_DISP header, the search for that
packet should start at the beginning of the "Date:" header, but the
search for the next packet should start after the WD_DIALOUT_DISP
header, as if we start it after the "Date:" header, the search will stop
at the packet's own WD_DIALOUT_DISP header, as a packet could have a
WD_DIALOUT_DISP header but no "Date:" header.
svn path=/trunk/; revision=2620
2000-11-12 08:45:28 +00:00
|
|
|
offset after the header of the previous packet and try to find the next
|
|
|
|
packet. */
|
2002-03-04 00:25:35 +00:00
|
|
|
if (file_seek(wth->fh, wth->capture.ascend->next_packet_seek_start,
|
2002-06-07 07:27:35 +00:00
|
|
|
SEEK_SET, err) == -1)
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE;
|
2002-03-04 00:25:35 +00:00
|
|
|
offset = ascend_seek(wth, ASCEND_MAX_SEEK, err);
|
|
|
|
if (offset == -1)
|
|
|
|
return FALSE;
|
2000-05-18 09:09:50 +00:00
|
|
|
if (! parse_ascend(wth->fh, buf, &wth->pseudo_header.ascend, &header, 0)) {
|
1999-09-11 04:53:26 +00:00
|
|
|
*err = WTAP_ERR_BAD_RECORD;
|
2000-09-07 05:34:23 +00:00
|
|
|
return FALSE;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
|
|
|
|
1999-09-11 22:36:38 +00:00
|
|
|
buffer_assure_space(wth->frame_buffer, wth->snapshot_length);
|
1999-09-11 04:53:26 +00:00
|
|
|
|
|
|
|
if (! wth->capture.ascend->adjusted) {
|
|
|
|
wth->capture.ascend->adjusted = 1;
|
2000-11-11 03:15:07 +00:00
|
|
|
if (header.start_time != 0) {
|
|
|
|
/*
|
|
|
|
* Capture file contained a date and time.
|
|
|
|
* We do this only if this is the very first packet we've seen -
|
|
|
|
* i.e., if "wth->capture.ascend->adjusted" is false - because
|
|
|
|
* if we get a date and time after the first packet, we can't
|
|
|
|
* go back and adjust the time stamps of the packets we've already
|
|
|
|
* processed, and basing the time stamps of this and following
|
|
|
|
* packets on the time stamp from the file text rather than the
|
|
|
|
* ctime of the capture file means times before this and after
|
|
|
|
* this can't be compared.
|
|
|
|
*/
|
|
|
|
wth->capture.ascend->inittime = header.start_time;
|
|
|
|
}
|
|
|
|
if (wth->capture.ascend->inittime > header.secs)
|
|
|
|
wth->capture.ascend->inittime -= header.secs;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
|
|
|
wth->phdr.ts.tv_sec = header.secs + wth->capture.ascend->inittime;
|
|
|
|
wth->phdr.ts.tv_usec = header.usecs;
|
|
|
|
wth->phdr.caplen = header.caplen;
|
|
|
|
wth->phdr.len = header.len;
|
|
|
|
wth->phdr.pkt_encap = wth->file_encap;
|
|
|
|
wth->data_offset = offset;
|
1999-09-11 22:36:38 +00:00
|
|
|
|
2000-09-07 05:34:23 +00:00
|
|
|
*data_offset = offset;
|
|
|
|
return TRUE;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
|
|
|
|
2002-03-05 08:40:27 +00:00
|
|
|
static gboolean ascend_seek_read (wtap *wth, long seek_off,
|
2002-03-05 05:58:41 +00:00
|
|
|
union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err)
|
1999-09-11 04:53:26 +00:00
|
|
|
{
|
2002-06-07 07:27:35 +00:00
|
|
|
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
|
2002-03-05 08:40:27 +00:00
|
|
|
return FALSE;
|
2002-03-05 05:58:41 +00:00
|
|
|
if (! parse_ascend(wth->random_fh, pd, &pseudo_header->ascend, NULL, len)) {
|
|
|
|
*err = WTAP_ERR_BAD_RECORD;
|
2002-03-05 08:40:27 +00:00
|
|
|
return FALSE;
|
2002-03-05 05:58:41 +00:00
|
|
|
}
|
2002-03-05 08:40:27 +00:00
|
|
|
return TRUE;
|
1999-09-11 04:53:26 +00:00
|
|
|
}
|
2000-03-22 07:06:59 +00:00
|
|
|
|
|
|
|
static void ascend_close(wtap *wth)
|
|
|
|
{
|
|
|
|
g_free(wth->capture.ascend);
|
|
|
|
}
|