Hi Guy,
> > here is my patch that adds a Wiretap module for reading files created
> > with "hcidump -w".
>
> Checked in, with wiretap/Makefile.nmake updated to build it, with the
> __attribute((packed))__ stuff removed (not all compilers used to build
> Wiretap support it, and there are no fields in there that would require
> padding), and with the byte swapping done with "g_ntohs()" and
> "g_ntohl()" so it doesn't have to include headers not found on all
> platforms.
sorry for the nmake stuff, but I always forget them :(
Attached is another patch against CVS, which re-introduces the byte
swapping, because the ntohs/ntohl are not working in this case. I used
the GLIB macros and so it should be portable now. I also use the macro
_U_ for __attribute((packed))__ and this should be portable, too.
Regards
Marcel
diff -urN ethereal/wiretap/hcidump.c ethereal-mh/wiretap/hcidump.c
--- ethereal/wiretap/hcidump.c Thu Oct 30 04:11:02 2003
+++ ethereal-mh/wiretap/hcidump.c Thu Oct 30 12:16:17 2003
@@ -28,13 +28,27 @@
#include "buffer.h"
#include "hcidump.h"
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define htobs(val) (val)
+#define htobl(val) (val)
+#define btohs(val) (val)
+#define btohl(val) (val)
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+#define htobs(val) GUINT16_SWAP_LE_BE(val)
+#define htobl(val) GUINT32_SWAP_LE_BE(val)
+#define btohs(val) GUINT16_SWAP_LE_BE(val)
+#define btohl(val) GUINT32_SWAP_LE_BE(val)
+#else
+#error unknown ENDIAN type
+#endif
+
struct dump_hdr {
guint16 len;
guint8 in;
guint8 pad;
guint32 ts_sec;
guint32 ts_usec;
-};
+} _U_;
#define DUMP_HDR_SIZE (sizeof(struct dump_hdr))
@@ -55,7 +69,7 @@
}
wth->data_offset += DUMP_HDR_SIZE;
- packet_size = g_ntohs(dh.len);
+ packet_size = btohs(dh.len);
if (packet_size > WTAP_MAX_PACKET_SIZE) {
/*
* Probably a corrupt capture file; don't blow up trying
@@ -79,8 +93,8 @@
}
wth->data_offset += packet_size;
- wth->phdr.ts.tv_sec = g_ntohl(dh.ts_sec);
- wth->phdr.ts.tv_usec = g_ntohl(dh.ts_usec);
+ wth->phdr.ts.tv_sec = btohl(dh.ts_sec);
+ wth->phdr.ts.tv_usec = btohl(dh.ts_usec);
wth->phdr.caplen = packet_size;
wth->phdr.len = packet_size;
wth->phdr.pkt_encap = WTAP_ENCAP_BLUETOOTH_H4;
@@ -131,7 +145,7 @@
return (*err != 0) ? -1 : 0;
}
- if (dh.in != 0 && dh.in != 1 && dh.pad != 0 && g_ntohs(dh.len) < 1)
+ if (dh.in != 0 && dh.in != 1 && dh.pad != 0 && btohs(dh.len) < 1)
return 0;
bytes_read = file_read(&type, 1, 1, wth->fh);