I'm proposing a new tvbuff accessor for accessing 64,32,24 and 16 bit
ints in network byte order. This is useful e.g. with
proto_tree_add_ipv4 which expects a network byte order address as its
argument. Currently e.g. IGMP dissector uses tvb_get_letohl for
proto_tree_add_ipv4 which breaks with big endian hosts.
There was some discussion relating to this about a year ago [1] I
guess no patch became of it. This preprocessor method at least gets
rid of memcpy and extra byteswapping on little endian machines. The
patch is a little bit of hackery, but does not add requirements for
copying memory or doing extra bytes swapping.
Any chance for the patch to go in? I already have a patch ready for
packet-igmp.c.
[1] http://www.ethereal.com/lists/ethereal-dev/200007/msg00061.html
Index: epan/tvbuff.h
===================================================================
RCS file: /cvsroot/ethereal/epan/tvbuff.h,v
retrieving revision 1.13
diff -u -r1.13 tvbuff.h
--- tvbuff.h 2001/05/27 21:34:05 1.13
+++ tvbuff.h 2001/06/22 19:45:51
@@ -224,6 +224,23 @@
guint8 tvb_get_guint8(tvbuff_t*, gint offset);
+/* For accessing ints in network byte order */
+#ifdef WORDS_BIGENDIAN
+#define tvb_get_ns tvb_get_ntohs
+#define tvb_get_n24 tvb_get_ntoh24
+#define tvb_get_nl tvb_get_ntohl
+#ifdef G_HAVE_GINT64
+#define tvb_get_nll tvb_get_ntohll
+#endif
+#else
+#define tvb_get_ns tvb_get_letohs
+#define tvb_get_n24 tvb_get_letoh24
+#define tvb_get_nl tvb_get_letohl
+#ifdef G_HAVE_GINT64
+#define tvb_get_nll tvb_get_letohll
+#endif
+#endif /* ifdef WORDS_BIGENDIAN */
+
guint16 tvb_get_ntohs(tvbuff_t*, gint offset);
guint32 tvb_get_ntoh24(tvbuff_t*, gint offset);
guint32 tvb_get_ntohl(tvbuff_t*, gint offset);
Index: doc/README.tvbuff
===================================================================
RCS file: /cvsroot/ethereal/doc/README.tvbuff,v
retrieving revision 1.4
diff -u -r1.4 README.tvbuff
--- README.tvbuff 2000/06/15 03:49:00 1.4
+++ README.tvbuff 2001/06/22 19:45:52
@@ -103,6 +103,13 @@
guint8 tvb_get_guint8(tvbuff_t*, gint offset);
+Network-order access for shorts (guint16), longs (guint24), and
+24-bit ints:
+
+guint16 tvb_get_ns(tvbuff_t*, gint offset);
+guint32 tvb_get_nl(tvbuff_t*, gint offset);
+guint32 tvb_get_n24(tvbuff_t*, gint offset);
+
Network-to-host-order access for shorts (guint16), longs (guint24), and
24-bit ints: