tvb: implement endianness-paramterized getters
authorEvan Huus <eapache@gmail.com>
Wed, 31 Dec 2014 22:05:58 +0000 (17:05 -0500)
committerEvan Huus <eapache@gmail.com>
Fri, 2 Jan 2015 04:07:19 +0000 (04:07 +0000)
e.g. tvb_get_guint16(tvb, offset, ENC_LITTLE_ENDIAN)

Change-Id: Iea02fd59b13678aca741d028fb1f66f334447498
Reviewed-on: https://code.wireshark.org/review/6191
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Evan Huus <eapache@gmail.com>
epan/tvbuff.c
epan/tvbuff.h

index 46746f45cec7839c3a7adde7854ea65ba8172ab3..fce1f3fa7221b40d6b9eeeedb44f497f4ebedb2f 100644 (file)
@@ -953,6 +953,114 @@ tvb_get_ntoh64(tvbuff_t *tvb, const gint offset)
        return pntoh64(ptr);
 }
 
+guint16
+tvb_get_guint16(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letohs(tvb, offset);
+       } else {
+               return tvb_get_ntohs(tvb, offset);
+       }
+}
+
+guint32
+tvb_get_guint24(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letoh24(tvb, offset);
+       } else {
+               return tvb_get_ntoh24(tvb, offset);
+       }
+}
+
+guint32
+tvb_get_guint32(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letohl(tvb, offset);
+       } else {
+               return tvb_get_ntohl(tvb, offset);
+       }
+}
+
+guint64
+tvb_get_guint40(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letoh40(tvb, offset);
+       } else {
+               return tvb_get_ntoh40(tvb, offset);
+       }
+}
+
+gint64
+tvb_get_gint40(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letohi40(tvb, offset);
+       } else {
+               return tvb_get_ntohi40(tvb, offset);
+       }
+}
+
+guint64
+tvb_get_guint48(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letoh48(tvb, offset);
+       } else {
+               return tvb_get_ntoh48(tvb, offset);
+       }
+}
+
+gint64
+tvb_get_gint48(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letohi48(tvb, offset);
+       } else {
+               return tvb_get_ntohi48(tvb, offset);
+       }
+}
+
+guint64
+tvb_get_guint56(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letoh56(tvb, offset);
+       } else {
+               return tvb_get_ntoh56(tvb, offset);
+       }
+}
+
+gint64
+tvb_get_gint56(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letohi56(tvb, offset);
+       } else {
+               return tvb_get_ntohi56(tvb, offset);
+       }
+}
+
+guint64
+tvb_get_guint64(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letoh64(tvb, offset);
+       } else {
+               return tvb_get_ntoh64(tvb, offset);
+       }
+}
+
+gfloat
+tvb_get_ieee_float(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letohieee_float(tvb, offset);
+       } else {
+               return tvb_get_ntohieee_float(tvb, offset);
+       }
+}
+
+gdouble
+tvb_get_ieee_double(tvbuff_t *tvb, const gint offset, const guint encoding) {
+       if (encoding & ENC_LITTLE_ENDIAN) {
+               return tvb_get_letohieee_double(tvb, offset);
+       } else {
+               return tvb_get_ntohieee_double(tvb, offset);
+       }
+}
+
 /*
  * Stuff for IEEE float handling on platforms that don't have IEEE
  * format as the native floating-point format.
@@ -1596,12 +1704,12 @@ tvb_get_letohguid(tvbuff_t *tvb, const gint offset, e_guid_t *guid)
  * NOTE: to support code written when proto_tree_add_item() took a
  * gboolean as its last argument, with FALSE meaning "big-endian"
  * and TRUE meaning "little-endian", we treat any non-zero value of
- * "representation" as meaning "little-endian".
+ * "encoding" as meaning "little-endian".
  */
 void
-tvb_get_guid(tvbuff_t *tvb, const gint offset, e_guid_t *guid, const guint representation)
+tvb_get_guid(tvbuff_t *tvb, const gint offset, e_guid_t *guid, const guint encoding)
 {
-       if (representation) {
+       if (encoding) {
                tvb_get_letohguid(tvb, offset, guid);
        } else {
                tvb_get_ntohguid(tvb, offset, guid);
index b9e8a782d696603a418dbb4d99d880ee0db70a02..66fd060d1310d0631a68e465b43ec4de1a4d6d31 100644 (file)
@@ -325,6 +325,19 @@ WS_DLL_PUBLIC gfloat tvb_get_letohieee_float(tvbuff_t *tvb, const gint offset);
 WS_DLL_PUBLIC gdouble tvb_get_letohieee_double(tvbuff_t *tvb,
     const gint offset);
 
+WS_DLL_PUBLIC guint16 tvb_get_guint16(tvbuff_t *tvb, const gint offset, const guint encoding);
+WS_DLL_PUBLIC guint32 tvb_get_guint24(tvbuff_t *tvb, const gint offset, const guint encoding);
+WS_DLL_PUBLIC guint32 tvb_get_guint32(tvbuff_t *tvb, const gint offset, const guint encoding);
+WS_DLL_PUBLIC guint64 tvb_get_guint40(tvbuff_t *tvb, const gint offset, const guint encoding);
+WS_DLL_PUBLIC gint64 tvb_get_gint40(tvbuff_t *tvb, const gint offset, const guint encoding);
+WS_DLL_PUBLIC guint64 tvb_get_guint48(tvbuff_t *tvb, const gint offset, const guint encoding);
+WS_DLL_PUBLIC gint64 tvb_get_gint48(tvbuff_t *tvb, const gint offset, const guint encoding);
+WS_DLL_PUBLIC guint64 tvb_get_guint56(tvbuff_t *tvb, const gint offset, const guint encoding);
+WS_DLL_PUBLIC gint64 tvb_get_gint56(tvbuff_t *tvb, const gint offset, const guint encoding);
+WS_DLL_PUBLIC guint64 tvb_get_guint64(tvbuff_t *tvb, const gint offset, const guint encoding);
+WS_DLL_PUBLIC gfloat tvb_get_ieee_float(tvbuff_t *tvb, const gint offset, const guint encoding);
+WS_DLL_PUBLIC gdouble tvb_get_ieee_double(tvbuff_t *tvb, const gint offset, const guint encoding);
+
 /*
  * Fetch 16-bit and 32-bit values in host byte order.
  * Used for some pseudo-headers in pcap/pcap-ng files, in which the
@@ -401,7 +414,7 @@ WS_DLL_PUBLIC void tvb_get_ntohguid(tvbuff_t *tvb, const gint offset,
 WS_DLL_PUBLIC void tvb_get_letohguid(tvbuff_t *tvb, const gint offset,
     e_guid_t *guid);
 WS_DLL_PUBLIC void tvb_get_guid(tvbuff_t *tvb, const gint offset,
-    e_guid_t *guid, const guint representation);
+    e_guid_t *guid, const guint encoding);
 
 /* Fetch a specified number of bits from bit offset in a tvb.  All of these
  * functions are equivalent, except for the type of the return value.  Note