/* lanalyzer.c
*
- * $Id: lanalyzer.c,v 1.36 2002/07/29 06:09:58 guy Exp $
+ * $Id: lanalyzer.c,v 1.41 2003/12/11 21:23:37 ulfl Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
};
static gboolean lanalyzer_read(wtap *wth, int *err, long *data_offset);
+static gboolean lanalyzer_seek_read(wtap *wth, long seek_off,
+ union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err);
static void lanalyzer_close(wtap *wth);
static gboolean lanalyzer_dump_close(wtap_dumper *wdh, int *err);
wth->file_type = WTAP_FILE_LANALYZER;
wth->capture.lanalyzer = g_malloc(sizeof(lanalyzer_t));
wth->subtype_read = lanalyzer_read;
- wth->subtype_seek_read = wtap_def_seek_read;
+ wth->subtype_seek_read = lanalyzer_seek_read;
wth->subtype_close = lanalyzer_close;
wth->snapshot_length = 0;
wth->data_offset += packet_size;
true_size = pletohs(&descriptor[4]);
+ packet_size = pletohs(&descriptor[6]);
time_low = pletohs(&descriptor[8]);
time_med = pletohs(&descriptor[10]);
time_high = pletohs(&descriptor[12]);
+ /*
+ * OK, is the frame data size greater than than what's left of the
+ * record?
+ */
+ if (packet_size > record_length - DESCRIPTOR_LEN) {
+ /*
+ * Yes - treat this as an error.
+ */
+ g_message("lanalyzer: Record length is less than packet size");
+ *err = WTAP_ERR_BAD_RECORD;
+ return FALSE;
+ }
+
t = (double)time_low+(double)(time_med)*65536.0 +
(double)time_high*4294967296.0;
t = t/1000000.0 * 0.5; /* t = # of secs */
wth->phdr.ts.tv_usec = (unsigned long)((t-(double)(wth->phdr.ts.tv_sec))
*1.0e6);
- wth->phdr.len = true_size - 4;
+ if (true_size - 4 >= packet_size) {
+ /*
+ * It appears that the "true size" includes the FCS;
+ * make it reflect the non-FCS size (the "packet size"
+ * appears never to include the FCS, even if no slicing
+ * is done).
+ */
+ true_size -= 4;
+ }
+ wth->phdr.len = true_size;
wth->phdr.caplen = packet_size;
wth->phdr.pkt_encap = wth->file_encap;
+ switch (wth->file_encap) {
+
+ case WTAP_ENCAP_ETHERNET:
+ /* We assume there's no FCS in this frame. */
+ wth->pseudo_header.eth.fcs_len = 0;
+ break;
+ }
+
+ return TRUE;
+}
+
+static gboolean lanalyzer_seek_read(wtap *wth, long seek_off,
+ union wtap_pseudo_header *pseudo_header, guchar *pd, int length, int *err)
+{
+ int bytes_read;
+
+ if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
+ return FALSE;
+
+ /*
+ * Read the packet data.
+ */
+ bytes_read = file_read(pd, sizeof(guint8), length, wth->random_fh);
+ if (bytes_read != length) {
+ *err = file_error(wth->random_fh);
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return FALSE;
+ }
+
+ switch (wth->file_encap) {
+
+ case WTAP_ENCAP_ETHERNET:
+ /* We assume there's no FCS in this frame. */
+ pseudo_header->eth.fcs_len = 0;
+ break;
+ }
+
return TRUE;
}
static int swrite(const void* what, guint size, FILE *hd)
{
size_t nwritten;
-
+
nwritten = fwrite(what, 1, size, hd);
if (nwritten != size) {
if (nwritten == 0 && ferror(hd))
static int s8write(const guint8 s8, FILE *hd)
{
size_t nwritten;
-
+
nwritten = fwrite(&s8, 1, 1, hd);
if (nwritten != 1) {
if (nwritten == 0 && ferror(hd))
static int s16write(const guint16 s16, FILE *hd)
{
size_t nwritten;
-
+
nwritten = fwrite(&s16, 1, 2, hd);
if (nwritten != 2) {
if (nwritten == 0 && ferror(hd))
static int s32write(const guint32 s32, FILE *hd)
{
size_t nwritten;
-
+
nwritten = fwrite(&s32, 1, 4, hd);
if (nwritten != 4) {
if (nwritten == 0 && ferror(hd))
*err = s16write(htoles(SummarySize), wdh->fh); /* rlen */
if (*err)
return FALSE;
- *err = s8write(fT->tm_mday, wdh->fh); /* s.datcre.day */
+ *err = s8write((guint8) fT->tm_mday, wdh->fh); /* s.datcre.day */
if (*err)
return FALSE;
- *err = s8write(fT->tm_mon+1, wdh->fh); /* s.datcre.mon */
+ *err = s8write((guint8) (fT->tm_mon+1), wdh->fh); /* s.datcre.mon */
if (*err)
return FALSE;
*err = s16write(htoles(fT->tm_year + 1900), wdh->fh);/* s.datcre.year */
if (*err)
return FALSE;
- *err = s8write(fT->tm_mday, wdh->fh); /* s.datclo.day */
+ *err = s8write((guint8) fT->tm_mday, wdh->fh); /* s.datclo.day */
if (*err)
return FALSE;
- *err = s8write(fT->tm_mon+1, wdh->fh); /* s.datclo.mon */
+ *err = s8write((guint8) (fT->tm_mon+1), wdh->fh); /* s.datclo.mon */
if (*err)
return FALSE;
*err = s16write(htoles(fT->tm_year + 1900), wdh->fh);/* s.datclo.year */
if (*err)
return FALSE;
- *err = s8write(fT->tm_sec, wdh->fh); /* s.timeopn.second */
+ *err = s8write((guint8) fT->tm_sec, wdh->fh); /* s.timeopn.second */
if (*err)
return FALSE;
- *err = s8write(fT->tm_min, wdh->fh); /* s.timeopn.minute */
+ *err = s8write((guint8) fT->tm_min, wdh->fh); /* s.timeopn.minute */
if (*err)
return FALSE;
- *err = s8write(fT->tm_hour, wdh->fh); /* s.timeopn.hour */
+ *err = s8write((guint8) fT->tm_hour, wdh->fh); /* s.timeopn.hour */
if (*err)
return FALSE;
- *err = s8write(fT->tm_mday, wdh->fh); /* s.timeopn.mday */
+ *err = s8write((guint8) fT->tm_mday, wdh->fh); /* s.timeopn.mday */
if (*err)
return FALSE;
*err = s0write(2, wdh->fh);
if (*err)
return FALSE;
- *err = s8write(fT->tm_sec, wdh->fh); /* s.timeclo.second */
+ *err = s8write((guint8) fT->tm_sec, wdh->fh); /* s.timeclo.second */
if (*err)
return FALSE;
- *err = s8write(fT->tm_min, wdh->fh); /* s.timeclo.minute */
+ *err = s8write((guint8) fT->tm_min, wdh->fh); /* s.timeclo.minute */
if (*err)
return FALSE;
- *err = s8write(fT->tm_hour, wdh->fh); /* s.timeclo.hour */
+ *err = s8write((guint8) fT->tm_hour, wdh->fh); /* s.timeclo.hour */
if (*err)
return FALSE;
- *err = s8write(fT->tm_mday, wdh->fh); /* s.timeclo.mday */
+ *err = s8write((guint8) fT->tm_mday, wdh->fh); /* s.timeclo.mday */
if (*err)
return FALSE;
*err = s0write(2, wdh->fh);
*---------------------------------------------------*/
static gboolean lanalyzer_dump_close(wtap_dumper *wdh, int *err)
{
- if (wdh->dump.opaque) {
- lanalyzer_dump_header(wdh,err);
- g_free(wdh->dump.opaque);
- wdh->dump.opaque = 0;
- }
+ lanalyzer_dump_header(wdh,err);
return *err ? FALSE : TRUE;
}