aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--wiretap/AUTHORS2
-rw-r--r--wiretap/netxray.c63
-rw-r--r--wiretap/wtap-int.h87
3 files changed, 111 insertions, 41 deletions
diff --git a/wiretap/AUTHORS b/wiretap/AUTHORS
index 50b3beb725..ceade0c6b0 100644
--- a/wiretap/AUTHORS
+++ b/wiretap/AUTHORS
@@ -9,4 +9,4 @@ Tim Farley <tfarley@iss.net>
Bert Driehuis <driehuis@playbeing.org>
Mike Hall <mlh@io.com>
Daniel Thompson <daniel.thompson@st.com>
-
+Chris Jepeway <thai-dragon@eleven29.com>
diff --git a/wiretap/netxray.c b/wiretap/netxray.c
index 447723802b..a5e69aa577 100644
--- a/wiretap/netxray.c
+++ b/wiretap/netxray.c
@@ -1,6 +1,6 @@
/* netxray.c
*
- * $Id: netxray.c,v 1.34 2000/11/19 03:47:35 guy Exp $
+ * $Id: netxray.c,v 1.35 2001/02/13 00:50:05 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -40,6 +40,15 @@ static const char netxray_magic[] = { /* magic header */
'X', 'C', 'P', '\0'
};
+#ifdef G_HAVE_GINT64
+typedef guint64 netxray_ticks;
+#else
+typedef struct {
+ guint32 lo; /* lower 32 bits of time stamp */
+ guint32 hi; /* upper 32 bits of time stamp */
+} netxray_ticks;
+#endif
+
/* NetXRay file header (minus magic number). */
struct netxray_hdr {
char version[8]; /* version number */
@@ -51,8 +60,7 @@ struct netxray_hdr {
guint32 xxy[3]; /* unknown */
guint16 network; /* datalink type */
guint8 xxz[6];
- guint32 timelo; /* lower 32 bits of time stamp of capture start */
- guint32 timehi; /* upper 32 bits of time stamp of capture start */
+ netxray_ticks t;
/*
* XXX - other stuff.
*/
@@ -77,8 +85,7 @@ static const char vers_2_002[] = {
/* NetXRay 1.x data record format - followed by frame data. */
struct netxrayrec_1_x_hdr {
- guint32 timelo; /* lower 32 bits of time stamp */
- guint32 timehi; /* upper 32 bits of time stamp */
+ netxray_ticks t;
guint16 orig_len; /* packet length */
guint16 incl_len; /* capture length */
guint32 xxx[4]; /* unknown */
@@ -86,8 +93,7 @@ struct netxrayrec_1_x_hdr {
/* NetXRay 2.x data record format - followed by frame data. */
struct netxrayrec_2_x_hdr {
- guint32 timelo; /* lower 32 bits of time stamp */
- guint32 timehi; /* upper 32 bits of time stamp */
+ netxray_ticks t;
guint16 orig_len; /* packet length */
guint16 incl_len; /* capture length */
guint32 xxx[7]; /* unknown */
@@ -99,6 +105,26 @@ static gboolean netxray_dump_1_1(wtap_dumper *wdh, const struct wtap_pkthdr *phd
const union wtap_pseudo_header *pseudo_header, const u_char *pd, int *err);
static gboolean netxray_dump_close_1_1(wtap_dumper *wdh, int *err);
+static double netxray_ticks2double(netxray_ticks *t)
+{
+# ifdef G_HAVE_GINT64
+ return pletohll(t);
+# else
+ return pletohl(&t->lo) +
+ pletohl(&t->hi) * 4294967296.0;
+# endif
+}
+
+static void double2netxray_ticks(netxray_ticks *t, double d)
+{
+# ifdef G_HAVE_GINT64
+ *t = htolell(d);
+# else
+ t->lo = htolel((guint32) (d % 4294967296.0));
+ t->hi = htolel((guint32) (d / 4294967296.0));
+# endif
+}
+
int netxray_open(wtap *wth, int *err)
{
int bytes_read;
@@ -169,7 +195,7 @@ int netxray_open(wtap *wth, int *err)
file_type = WTAP_FILE_NETXRAY_1_1;
} else if (memcmp(hdr.version, vers_2_001, sizeof vers_2_001) == 0
|| memcmp(hdr.version, vers_2_002, sizeof vers_2_002) == 0) {
- timeunit = 1000000.0;
+ timeunit = 1193180.0;
version_major = 2;
file_type = WTAP_FILE_NETXRAY_2_00x;
} else {
@@ -197,9 +223,8 @@ int netxray_open(wtap *wth, int *err)
wth->snapshot_length = 16384; /* XXX - not available in header */
wth->capture.netxray->start_time = pletohl(&hdr.start_time);
wth->capture.netxray->timeunit = timeunit;
- t = (double)pletohl(&hdr.timelo)
- + (double)pletohl(&hdr.timehi)*4294967296.0;
- t = t/timeunit;
+ t = netxray_ticks2double(&hdr.t);
+ t /= timeunit;
wth->capture.netxray->start_timestamp = t;
wth->capture.netxray->version_major = version_major;
/*wth->frame_number = 0;*/
@@ -288,13 +313,11 @@ reread:
}
wth->data_offset += packet_size;
- t = (double)pletohl(&hdr.hdr_1_x.timelo)
- + (double)pletohl(&hdr.hdr_1_x.timehi)*4294967296.0;
+ t = netxray_ticks2double(&hdr.hdr_1_x.t);
t /= wth->capture.netxray->timeunit;
t -= wth->capture.netxray->start_timestamp;
wth->phdr.ts.tv_sec = wth->capture.netxray->start_time + (long)t;
- wth->phdr.ts.tv_usec = (unsigned long)((t-(double)(unsigned long)(t))
- *1.0e6);
+ wth->phdr.ts.tv_usec = (t - (unsigned long)(t)) * 1.0e6;
wth->phdr.caplen = packet_size;
wth->phdr.len = pletohs(&hdr.hdr_1_x.orig_len);
wth->phdr.pkt_encap = wth->file_encap;
@@ -390,10 +413,9 @@ static gboolean netxray_dump_1_1(wtap_dumper *wdh, const struct wtap_pkthdr *phd
/* build the header for each packet */
memset(&rec_hdr, '\0', sizeof(rec_hdr));
- timestamp = (phdr->ts.tv_sec - netxray->start.tv_sec)*1000000 +
- phdr->ts.tv_usec;
- rec_hdr.timelo = htolel(timestamp);
- rec_hdr.timehi = htolel(0);
+ timestamp = (phdr->ts.tv_sec - netxray->start.tv_sec)*1000000.0 +
+ phdr->ts.tv_usec;
+ double2netxray_ticks(&rec_hdr.t, timestamp);
rec_hdr.orig_len = htoles(phdr->len);
rec_hdr.incl_len = htoles(phdr->caplen);
@@ -454,8 +476,7 @@ static gboolean netxray_dump_close_1_1(wtap_dumper *wdh, int *err)
file_hdr.start_offset = htolel(CAPTUREFILE_HEADER_SIZE);
file_hdr.end_offset = htolel(filelen);
file_hdr.network = htoles(wtap_encap[wdh->encap]);
- file_hdr.timelo = htolel(0);
- file_hdr.timehi = htolel(0);
+ double2netxray_ticks(&file_hdr.t, 0);
memset(hdr_buf, '\0', sizeof hdr_buf);
memcpy(hdr_buf, &file_hdr, sizeof(file_hdr));
diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h
index b220cbef79..e07fa0043e 100644
--- a/wiretap/wtap-int.h
+++ b/wiretap/wtap-int.h
@@ -1,6 +1,6 @@
/* wtap-int.h
*
- * $Id: wtap-int.h,v 1.10 2000/11/12 08:45:28 guy Exp $
+ * $Id: wtap-int.h,v 1.11 2001/02/13 00:50:05 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@@ -219,6 +219,11 @@ struct wtap_dumper {
(guint32)((l) & 0x0000FF00)<<8| \
(guint32)((l) & 0x00FF0000)>>8| \
(guint32)((l) & 0xFF000000)>>24)
+
+#ifdef G_HAVE_GINT64
+#define htolell(ll) GUINT64_TO_LE(ll)
+#endif
+
#else
#define htoles(s) (s)
#define htolel(l) (l)
@@ -227,48 +232,92 @@ struct wtap_dumper {
/* Pointer versions of ntohs and ntohl. Given a pointer to a member of a
* byte array, returns the value of the two or four bytes at the pointer.
* The pletoh[sl] versions return the little-endian representation.
+ *
+ * If G_HAVE_GINT64 is defined, so we can use "gint64" and "guint64" to
+ * refer to 64-bit integral quantities, we also provide pntohll and
+ * phtolell, which extract 64-bit integral quantities.
*/
#ifndef pntohs
#define pntohs(p) ((guint16) \
- ((guint16)*((guint8 *)p+0)<<8| \
- (guint16)*((guint8 *)p+1)<<0))
+ ((guint16)*((guint8 *)(p)+0)<<8| \
+ (guint16)*((guint8 *)(p)+1)<<0))
+#endif
+
+#ifndef pntoh24
+#define pntoh24(p) ((guint32)*((guint8 *)(p)+0)<<16| \
+ (guint32)*((guint8 *)(p)+1)<<8| \
+ (guint32)*((guint8 *)(p)+2)<<0)
#endif
#ifndef pntohl
-#define pntohl(p) ((guint32)*((guint8 *)p+0)<<24| \
- (guint32)*((guint8 *)p+1)<<16| \
- (guint32)*((guint8 *)p+2)<<8| \
- (guint32)*((guint8 *)p+3)<<0)
+#define pntohl(p) ((guint32)*((guint8 *)(p)+0)<<24| \
+ (guint32)*((guint8 *)(p)+1)<<16| \
+ (guint32)*((guint8 *)(p)+2)<<8| \
+ (guint32)*((guint8 *)(p)+3)<<0)
+#endif
+
+#ifdef G_HAVE_GINT64
+#ifndef pntohll
+#define pntohll(p) ((guint64)*((guint8 *)(p)+0)<<56| \
+ (guint64)*((guint8 *)(p)+1)<<48| \
+ (guint64)*((guint8 *)(p)+2)<<40| \
+ (guint64)*((guint8 *)(p)+3)<<32| \
+ (guint64)*((guint8 *)(p)+4)<<24| \
+ (guint64)*((guint8 *)(p)+5)<<16| \
+ (guint64)*((guint8 *)(p)+6)<<8| \
+ (guint64)*((guint8 *)(p)+7)<<0)
#endif
+#endif
+
#ifndef phtons
#define phtons(p) ((guint16) \
- ((guint16)*((guint8 *)p+0)<<8| \
- (guint16)*((guint8 *)p+1)<<0))
+ ((guint16)*((guint8 *)(p)+0)<<8| \
+ (guint16)*((guint8 *)(p)+1)<<0))
#endif
#ifndef phtonl
-#define phtonl(p) ((guint32)*((guint8 *)p+0)<<24| \
- (guint32)*((guint8 *)p+1)<<16| \
- (guint32)*((guint8 *)p+2)<<8| \
- (guint32)*((guint8 *)p+3)<<0)
+#define phtonl(p) ((guint32)*((guint8 *)(p)+0)<<24| \
+ (guint32)*((guint8 *)(p)+1)<<16| \
+ (guint32)*((guint8 *)(p)+2)<<8| \
+ (guint32)*((guint8 *)(p)+3)<<0)
#endif
#ifndef pletohs
#define pletohs(p) ((guint16) \
- ((guint16)*((guint8 *)p+1)<<8| \
- (guint16)*((guint8 *)p+0)<<0))
+ ((guint16)*((guint8 *)(p)+1)<<8| \
+ (guint16)*((guint8 *)(p)+0)<<0))
+#endif
+
+#ifndef pletoh24
+#define pletoh24(p) ((guint32)*((guint8 *)(p)+2)<<16| \
+ (guint32)*((guint8 *)(p)+1)<<8| \
+ (guint32)*((guint8 *)(p)+0)<<0)
#endif
+
#ifndef pletohl
-#define pletohl(p) ((guint32)*((guint8 *)p+3)<<24| \
- (guint32)*((guint8 *)p+2)<<16| \
- (guint32)*((guint8 *)p+1)<<8| \
- (guint32)*((guint8 *)p+0)<<0)
+#define pletohl(p) ((guint32)*((guint8 *)(p)+3)<<24| \
+ (guint32)*((guint8 *)(p)+2)<<16| \
+ (guint32)*((guint8 *)(p)+1)<<8| \
+ (guint32)*((guint8 *)(p)+0)<<0)
#endif
+#ifdef G_HAVE_GINT64
+#ifndef pletohll
+#define pletohll(p) ((guint64)*((guint8 *)(p)+7)<<56| \
+ (guint64)*((guint8 *)(p)+6)<<48| \
+ (guint64)*((guint8 *)(p)+5)<<40| \
+ (guint64)*((guint8 *)(p)+4)<<32| \
+ (guint64)*((guint8 *)(p)+3)<<24| \
+ (guint64)*((guint8 *)(p)+2)<<16| \
+ (guint64)*((guint8 *)(p)+1)<<8| \
+ (guint64)*((guint8 *)(p)+0)<<0)
+#endif
+#endif
+
#define wtap_file_read_unknown_bytes(target, num_bytes, fh, err) \
G_STMT_START \
{ \