/* ngsniffer.c
*
- * $Id: ngsniffer.c,v 1.79 2002/04/30 08:48:27 guy Exp $
+ * $Id: ngsniffer.c,v 1.85 2002/08/28 20:30:45 jmayer Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
- *
+ *
* 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.
static int skip_header_records(wtap *wth, int *err, gint16 version);
static gboolean ngsniffer_read(wtap *wth, int *err, long *data_offset);
static gboolean ngsniffer_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size,
+ union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
int *err);
static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random,
guint16 *typep, guint16 *lengthp, int *err);
static void set_pseudo_header_frame6(union wtap_pseudo_header *pseudo_header,
struct frame6_rec *frame6);
static gboolean ngsniffer_read_rec_data(wtap *wth, gboolean is_random,
- u_char *pd, int length, int *err);
+ guchar *pd, int length, int *err);
static void fix_pseudo_header(wtap *wth,
union wtap_pseudo_header *pseudo_header);
static void ngsniffer_sequential_close(wtap *wth);
static void ngsniffer_close(wtap *wth);
static gboolean ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
- const union wtap_pseudo_header *pseudo_header, const u_char *pd, int *err);
+ const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err);
static gboolean ngsniffer_dump_close(wtap_dumper *wdh, int *err);
static int SnifferDecompress( unsigned char * inbuf, size_t inlen,
unsigned char * outbuf, size_t outlen, int *err );
* "ngsniffer_read()".
*/
if (wth->random_fh != NULL) {
- if (file_seek(wth->random_fh, wth->data_offset, SEEK_SET) == -1) {
- *err = file_error(wth->random_fh);
+ if (file_seek(wth->random_fh, wth->data_offset, SEEK_SET, err) == -1)
return -1;
- }
}
/* This is a ngsniffer file */
* which implies data. Seek backwards over the
* two bytes we read, and return.
*/
- if (file_seek(wth->fh, -2, SEEK_CUR) == -1) {
- *err = file_error(wth->fh);
+ if (file_seek(wth->fh, -2, SEEK_CUR, err) == -1)
return -1;
- }
return 0;
}
*/
if (length > sizeof buffer) {
if (file_seek(wth->fh, length - sizeof buffer,
- SEEK_CUR) == -1) {
- *err = file_error(wth->fh);
+ SEEK_CUR, err) == -1)
return -1;
- }
}
/*
* XXX - what about LAPB and LAPD? At least one
- * X.25 capture has a type of NET_HDLC, but one
+ * X.25 capture has a type of NET_HDLC, but one
* might also consider LAPD to be an HDLC
* variant; if it also has a type of NET_HDLC,
* we'd have to look at some other data to
} else {
/* Nope, just skip over the data. */
- if (file_seek(wth->fh, length, SEEK_CUR) == -1) {
- *err = file_error(wth->fh);
+ if (file_seek(wth->fh, length, SEEK_CUR, err) == -1)
return -1;
- }
}
wth->data_offset += length;
}
struct frame6_rec frame6;
double t;
guint16 time_low, time_med, time_high, true_size, size;
- u_char *pd;
+ guchar *pd;
for (;;) {
/*
}
static gboolean ngsniffer_seek_read(wtap *wth, long seek_off,
- union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size,
+ union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
int *err)
{
int ret;
}
static gboolean ngsniffer_read_rec_data(wtap *wth, gboolean is_random,
- u_char *pd, int length, int *err)
+ guchar *pd, int length, int *err)
{
int bytes_read;
g_free(data);
}
+/* Close stuff used by the random I/O stream, if any, and free up any
+ private data structures. (If there's a "sequential_close" routine
+ for a capture file type, it'll be called before the "close" routine
+ is called, so we don't have to free the sequential buffer here.) */
static void ngsniffer_close(wtap *wth)
{
- if (wth->capture.ngsniffer->seq.buf != NULL)
- g_free(wth->capture.ngsniffer->seq.buf);
if (wth->capture.ngsniffer->rand.buf != NULL)
g_free(wth->capture.ngsniffer->rand.buf);
if (wth->capture.ngsniffer->first_blob != NULL) {
/* Returns TRUE on success, FALSE on failure; sets "*err" to an error code on
failure */
-gboolean ngsniffer_dump_open(wtap_dumper *wdh, int *err)
+gboolean ngsniffer_dump_open(wtap_dumper *wdh, gboolean cant_seek _U_, int *err)
{
size_t nwritten;
char buf[6] = {REC_VERS, 0x00, 0x12, 0x00, 0x00, 0x00}; /* version record */
/* Write a record for a packet to a dump file.
Returns TRUE on success, FALSE on failure. */
static gboolean ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
- const union wtap_pseudo_header *pseudo_header, const u_char *pd, int *err)
+ const union wtap_pseudo_header *pseudo_header, const guchar *pd, int *err)
{
ngsniffer_dump_t *priv = wdh->dump.ngsniffer;
struct frame2_rec rec_hdr;
nwritten = fwrite(buf, 1, 6, wdh->fh);
if (nwritten != 6) {
- if (nwritten == 0 && ferror(wdh->fh))
- *err = errno;
- else
- *err = WTAP_ERR_SHORT_WRITE;
+ if (err != NULL) {
+ if (nwritten == 0 && ferror(wdh->fh))
+ *err = errno;
+ else
+ *err = WTAP_ERR_SHORT_WRITE;
+ }
return FALSE;
}
return TRUE;
Return value is the number of bytes in outbuf on return.
*/
static int
-SnifferDecompress( unsigned char * inbuf, size_t inlen,
+SnifferDecompress( unsigned char * inbuf, size_t inlen,
unsigned char * outbuf, size_t outlen, int *err )
{
unsigned char * pin = inbuf;
Run length is the low nybble of the first code byte.
Byte to repeat immediately follows.
Total code size: 2 bytes.
- */
+ */
length = code_low + 3;
/* If length would put us past end of output, avoid overflow */
if ( pout + length > pout_end )
break;
case 1 : /* RLE long runs */
/*
- Low 4 bits of run length is the low nybble of the
- first code byte, upper 8 bits of run length is in
+ Low 4 bits of run length is the low nybble of the
+ first code byte, upper 8 bits of run length is in
the next byte.
Byte to repeat immediately follows.
Total code size: 3 bytes.
- */
+ */
length = code_low + ((unsigned int)(*pin++) << 4) + 19;
/* If we are already at end of input, there is no byte
to repeat */
break;
case 2 : /* LZ77 long strings */
/*
- Low 4 bits of offset to string is the low nybble of the
- first code byte, upper 8 bits of offset is in
+ Low 4 bits of offset to string is the low nybble of the
+ first code byte, upper 8 bits of offset is in
the next byte.
Length of string immediately follows.
Total code size: 3 bytes.
- */
+ */
offset = code_low + ((unsigned int)(*pin++) << 4) + 3;
/* If we are already at end of input, there is no byte
to repeat */
break;
default : /* (3 to 15): LZ77 short strings */
/*
- Low 4 bits of offset to string is the low nybble of the
- first code byte, upper 8 bits of offset is in
+ Low 4 bits of offset to string is the low nybble of the
+ first code byte, upper 8 bits of offset is in
the next byte.
Length of string to repeat is overloaded into code_type.
Total code size: 2 bytes.
- */
+ */
offset = code_low + ((unsigned int)(*pin++) << 4) + 3;
/* Check if offset would put us back past begin of buffer */
if ( pout - offset < outbuf )
return -1;
bytes_left = comp_stream->nbytes - comp_stream->nextout;
}
-
+
bytes_to_copy = copybytes;
if (bytes_to_copy > bytes_left)
bytes_to_copy = bytes_left;
static long
ng_file_seek_seq(wtap *wth, long offset, int whence, int *err)
{
- long ret;
long delta;
char buf[65536];
long amount_to_read;
- if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED) {
- ret = file_seek(wth->fh, offset, whence);
- if (ret == -1)
- *err = file_error(wth->fh);
- return ret;
- }
+ if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED)
+ return file_seek(wth->fh, offset, whence, err);
switch (whence) {
static long
ng_file_seek_rand(wtap *wth, long offset, int whence, int *err)
{
- long ret;
ngsniffer_t *ngsniffer;
long delta;
GList *new, *next;
blob_info_t *next_blob, *new_blob;
- if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED) {
- ret = file_seek(wth->random_fh, offset, whence);
- if (ret == -1)
- *err = file_error(wth->random_fh);
- return ret;
- }
+ if (wth->file_type == WTAP_FILE_NGSNIFFER_UNCOMPRESSED)
+ return file_seek(wth->random_fh, offset, whence, err);
ngsniffer = wth->capture.ngsniffer;
/* Seek in the compressed file to the offset in the compressed file
of the beginning of that blob. */
- if (file_seek(wth->random_fh, new_blob->blob_comp_offset, SEEK_SET) == -1) {
- *err = file_error(wth->random_fh);
+ if (file_seek(wth->random_fh, new_blob->blob_comp_offset, SEEK_SET, err) == -1)
return -1;
- }
/* Make the blob we found the current one. */
ngsniffer->current_blob = new;