Add tvb_get_[n|le]toh[40|48|56]() accessors. Addresses bug 5082.
authorChris Maynard <Christopher.Maynard@GTECH.COM>
Fri, 14 Jan 2011 19:02:38 +0000 (19:02 -0000)
committerChris Maynard <Christopher.Maynard@GTECH.COM>
Fri, 14 Jan 2011 19:02:38 +0000 (19:02 -0000)
svn path=/trunk/; revision=35538

asn1/mpeg-pes/packet-mpeg-pes-template.c
doc/README.developer
epan/dissectors/packet-mpeg-pes.c
epan/libwireshark.def
epan/pint.h
epan/tvbuff.c
epan/tvbuff.h

index 0f7b93795f077d42444b18934d8963d585d56670..3e24b92ef2973668b6a4a39c2629fa18ddc95606 100644 (file)
@@ -160,21 +160,9 @@ static const value_string mpeg_pes_TrickModeFrequencyTruncation_vals[] = {
   {   0, NULL }
 };
 
-static guint64 tvb_get_ntoh40(tvbuff_t *tvb, unsigned offset)
-{
-       return (guint64)tvb_get_guint8(tvb, offset) << 32
-               | tvb_get_ntohl(tvb, offset + 1);
-}
-
-static guint64 tvb_get_ntoh48(tvbuff_t *tvb, unsigned offset)
-{
-       return (guint64)tvb_get_ntohs(tvb, offset) << 32
-               | tvb_get_ntohl(tvb, offset + 2);
-}
-
 #define TSHZ 90000
 
-static guint64 decode_time_stamp(tvbuff_t *tvb, unsigned offset, nstime_t *nst)
+static guint64 decode_time_stamp(tvbuff_t *tvb, gint offset, nstime_t *nst)
 {
        guint64 bytes = tvb_get_ntoh40(tvb, offset);
        guint64 ts =
@@ -189,7 +177,7 @@ static guint64 decode_time_stamp(tvbuff_t *tvb, unsigned offset, nstime_t *nst)
 
 #define SCRHZ 27000000
 
-static guint64 decode_clock_reference(tvbuff_t *tvb, unsigned offset,
+static guint64 decode_clock_reference(tvbuff_t *tvb, gint offset,
                nstime_t *nst)
 {
        guint64 bytes = tvb_get_ntoh48(tvb, offset);
@@ -213,7 +201,7 @@ dissect_mpeg_pes_header_data(tvbuff_t *tvb, packet_info *pinfo,
                        0, -1, FALSE);
        proto_tree *tree = proto_item_add_subtree(item, ett_mpeg_pes_header_data);
 
-       unsigned offset = 0;
+       gint offset = 0;
        if (flags & PTS_FLAG) {
                nstime_t nst;
                decode_time_stamp(tvb, offset, &nst);
@@ -357,8 +345,8 @@ dissect_mpeg_pes_header_data(tvbuff_t *tvb, packet_info *pinfo,
        }
 }
 
-static unsigned
-dissect_mpeg_pes_pack_header(tvbuff_t *tvb, unsigned offset,
+static gint
+dissect_mpeg_pes_pack_header(tvbuff_t *tvb, gint offset,
                packet_info *pinfo, proto_tree *root)
 {
        unsigned program_mux_rate, stuffing_length;
@@ -405,7 +393,7 @@ dissect_mpeg_pes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        int prefix;
        int stream;
        asn1_ctx_t asn1_ctx;
-       unsigned offset = 0;
+       gint offset = 0;
 
        if (!tvb_bytes_exist(tvb, 0, 3))
                return FALSE;   /* not enough bytes for a PES prefix */
index b8956c82b85556dccea51ead638fb1d7a62c1749..ba810d6d07dd4a8bc577ef29e1029ed22757aebf 100644 (file)
@@ -1198,6 +1198,9 @@ integers, 32-bit integers (guint32), and 64-bit integers (guint64):
 guint16 tvb_get_ntohs(tvbuff_t*, gint offset);
 guint32 tvb_get_ntoh24(tvbuff_t*, gint offset);
 guint32 tvb_get_ntohl(tvbuff_t*, gint offset);
+guint64 tvb_get_ntoh40(tvbuff_t*, gint offset);
+guint64 tvb_get_ntoh48(tvbuff_t*, gint offset);
+guint64 tvb_get_ntoh56(tvbuff_t*, gint offset);
 guint64 tvb_get_ntoh64(tvbuff_t*, gint offset);
 
 Network-to-host-order accessors for single-precision and
@@ -1213,6 +1216,9 @@ Little-Endian-to-host-order accessors for 16-bit integers (guint16),
 guint16 tvb_get_letohs(tvbuff_t*, gint offset);
 guint32 tvb_get_letoh24(tvbuff_t*, gint offset);
 guint32 tvb_get_letohl(tvbuff_t*, gint offset);
+guint64 tvb_get_letoh40(tvbuff_t*, gint offset);
+guint64 tvb_get_letoh48(tvbuff_t*, gint offset);
+guint64 tvb_get_letoh56(tvbuff_t*, gint offset);
 guint64 tvb_get_letoh64(tvbuff_t*, gint offset);
 
 Little-Endian-to-host-order accessors for single-precision and
index 710634dd58ec6d9c3bab1902659662f30d99881b..578c12e24f4141375d1877f9cee661d5f55c875f 100644 (file)
@@ -601,21 +601,9 @@ static const value_string mpeg_pes_TrickModeFrequencyTruncation_vals[] = {
   {   0, NULL }
 };
 
-static guint64 tvb_get_ntoh40(tvbuff_t *tvb, unsigned offset)
-{
-       return (guint64)tvb_get_guint8(tvb, offset) << 32
-               | tvb_get_ntohl(tvb, offset + 1);
-}
-
-static guint64 tvb_get_ntoh48(tvbuff_t *tvb, unsigned offset)
-{
-       return (guint64)tvb_get_ntohs(tvb, offset) << 32
-               | tvb_get_ntohl(tvb, offset + 2);
-}
-
 #define TSHZ 90000
 
-static guint64 decode_time_stamp(tvbuff_t *tvb, unsigned offset, nstime_t *nst)
+static guint64 decode_time_stamp(tvbuff_t *tvb, gint offset, nstime_t *nst)
 {
        guint64 bytes = tvb_get_ntoh40(tvb, offset);
        guint64 ts =
@@ -630,7 +618,7 @@ static guint64 decode_time_stamp(tvbuff_t *tvb, unsigned offset, nstime_t *nst)
 
 #define SCRHZ 27000000
 
-static guint64 decode_clock_reference(tvbuff_t *tvb, unsigned offset,
+static guint64 decode_clock_reference(tvbuff_t *tvb, gint offset,
                nstime_t *nst)
 {
        guint64 bytes = tvb_get_ntoh48(tvb, offset);
@@ -654,7 +642,7 @@ dissect_mpeg_pes_header_data(tvbuff_t *tvb, packet_info *pinfo,
                        0, -1, FALSE);
        proto_tree *tree = proto_item_add_subtree(item, ett_mpeg_pes_header_data);
 
-       unsigned offset = 0;
+       gint offset = 0;
        if (flags & PTS_FLAG) {
                nstime_t nst;
                decode_time_stamp(tvb, offset, &nst);
@@ -798,8 +786,8 @@ dissect_mpeg_pes_header_data(tvbuff_t *tvb, packet_info *pinfo,
        }
 }
 
-static unsigned
-dissect_mpeg_pes_pack_header(tvbuff_t *tvb, unsigned offset,
+static gint
+dissect_mpeg_pes_pack_header(tvbuff_t *tvb, gint offset,
                packet_info *pinfo, proto_tree *root)
 {
        unsigned program_mux_rate, stuffing_length;
@@ -846,7 +834,7 @@ dissect_mpeg_pes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        int prefix;
        int stream;
        asn1_ctx_t asn1_ctx;
-       unsigned offset = 0;
+       gint offset = 0;
 
        if (!tvb_bytes_exist(tvb, 0, 3))
                return FALSE;   /* not enough bytes for a PES prefix */
@@ -1224,7 +1212,7 @@ proto_register_mpeg_pes(void)
         "BIT_STRING_SIZE_16", HFILL }},
 
 /*--- End of included file: packet-mpeg-pes-hfarr.c ---*/
-#line 582 "packet-mpeg-pes-template.c"
+#line 570 "packet-mpeg-pes-template.c"
                { &hf_mpeg_pes_pack_header,
                        { "Pack header", "mpeg-pes.pack",
                                FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
@@ -1342,7 +1330,7 @@ proto_register_mpeg_pes(void)
     &ett_mpeg_pes_Picture,
 
 /*--- End of included file: packet-mpeg-pes-ettarr.c ---*/
-#line 689 "packet-mpeg-pes-template.c"
+#line 677 "packet-mpeg-pes-template.c"
                &ett_mpeg_pes_pack_header,
                &ett_mpeg_pes_header_data,
                &ett_mpeg_pes_trick_mode
index 27b13b5ee9c3fb190ed77801917b806ac6b1232b..612f733cbb2ad343dda2ee417e9885069f8e042a 100644 (file)
@@ -1053,6 +1053,9 @@ tvb_get_guint8
 tvb_get_ipv4
 tvb_get_ipv6
 tvb_get_letoh24
+tvb_get_letoh40
+tvb_get_letoh48
+tvb_get_letoh56
 tvb_get_letoh64
 tvb_get_letohguid
 tvb_get_letohieee_double
@@ -1062,6 +1065,9 @@ tvb_get_letohs
 tvb_get_nstringz
 tvb_get_nstringz0
 tvb_get_ntoh24
+tvb_get_ntoh40
+tvb_get_ntoh48
+tvb_get_ntoh56
 tvb_get_ntoh64
 tvb_get_ntohguid
 tvb_get_ntohieee_double
index 42ca539a3a9dbf19e744fce0d492a48ff43aa5bc..da6480819b6cf7acf01b993f0dbf0ca5447ed79f 100644 (file)
                       (guint16)*((const guint8 *)(p)+1)<<0))
 
 #define pntoh24(p)  ((guint32)*((const guint8 *)(p)+0)<<16|  \
-                     (guint32)*((const guint8 *)(p)+1)<<8|  \
+                     (guint32)*((const guint8 *)(p)+1)<<8|   \
                      (guint32)*((const guint8 *)(p)+2)<<0)
 
 #define pntohl(p)   ((guint32)*((const guint8 *)(p)+0)<<24|  \
                      (guint32)*((const guint8 *)(p)+1)<<16|  \
                      (guint32)*((const guint8 *)(p)+2)<<8|   \
                      (guint32)*((const guint8 *)(p)+3)<<0)
+
+#define pntoh40(p)  ((guint64)*((const guint8 *)(p)+0)<<32|  \
+                     (guint64)*((const guint8 *)(p)+1)<<24|  \
+                     (guint64)*((const guint8 *)(p)+2)<<16|  \
+                     (guint64)*((const guint8 *)(p)+3)<<8|   \
+                     (guint64)*((const guint8 *)(p)+4)<<0)
+
+#define pntoh48(p)  ((guint64)*((const guint8 *)(p)+0)<<40|  \
+                     (guint64)*((const guint8 *)(p)+1)<<32|  \
+                     (guint64)*((const guint8 *)(p)+2)<<24|  \
+                     (guint64)*((const guint8 *)(p)+3)<<16|  \
+                     (guint64)*((const guint8 *)(p)+4)<<8|   \
+                     (guint64)*((const guint8 *)(p)+5)<<0)
+
+#define pntoh56(p)  ((guint64)*((const guint8 *)(p)+0)<<48|  \
+                     (guint64)*((const guint8 *)(p)+1)<<40|  \
+                     (guint64)*((const guint8 *)(p)+2)<<32|  \
+                     (guint64)*((const guint8 *)(p)+3)<<24|  \
+                     (guint64)*((const guint8 *)(p)+4)<<16|  \
+                     (guint64)*((const guint8 *)(p)+5)<<8|   \
+                     (guint64)*((const guint8 *)(p)+6)<<0)
+
 #define pntoh64(p)  ((guint64)*((const guint8 *)(p)+0)<<56|  \
                      (guint64)*((const guint8 *)(p)+1)<<48|  \
                      (guint64)*((const guint8 *)(p)+2)<<40|  \
                       (guint16)*((const guint8 *)(p)+0)<<0))
 
 #define pletoh24(p) ((guint32)*((const guint8 *)(p)+2)<<16|  \
-                     (guint32)*((const guint8 *)(p)+1)<<8|  \
+                     (guint32)*((const guint8 *)(p)+1)<<8|   \
                      (guint32)*((const guint8 *)(p)+0)<<0)
 
 #define pletohl(p)  ((guint32)*((const guint8 *)(p)+3)<<24|  \
                      (guint32)*((const guint8 *)(p)+2)<<16|  \
                      (guint32)*((const guint8 *)(p)+1)<<8|   \
                      (guint32)*((const guint8 *)(p)+0)<<0)
+
+#define pletoh40(p) ((guint64)*((const guint8 *)(p)+4)<<32|  \
+                     (guint64)*((const guint8 *)(p)+3)<<24|  \
+                     (guint64)*((const guint8 *)(p)+2)<<16|  \
+                     (guint64)*((const guint8 *)(p)+1)<<8|   \
+                     (guint64)*((const guint8 *)(p)+0)<<0)
+
+#define pletoh48(p) ((guint64)*((const guint8 *)(p)+5)<<40|  \
+                     (guint64)*((const guint8 *)(p)+4)<<32|  \
+                     (guint64)*((const guint8 *)(p)+3)<<24|  \
+                     (guint64)*((const guint8 *)(p)+2)<<16|  \
+                     (guint64)*((const guint8 *)(p)+1)<<8|   \
+                     (guint64)*((const guint8 *)(p)+0)<<0)
+
+#define pletoh56(p) ((guint64)*((const guint8 *)(p)+6)<<48|  \
+                     (guint64)*((const guint8 *)(p)+5)<<40|  \
+                     (guint64)*((const guint8 *)(p)+4)<<32|  \
+                     (guint64)*((const guint8 *)(p)+3)<<24|  \
+                     (guint64)*((const guint8 *)(p)+2)<<16|  \
+                     (guint64)*((const guint8 *)(p)+1)<<8|   \
+                     (guint64)*((const guint8 *)(p)+0)<<0)
+
 #define pletoh64(p) ((guint64)*((const guint8 *)(p)+7)<<56|  \
                      (guint64)*((const guint8 *)(p)+6)<<48|  \
                      (guint64)*((const guint8 *)(p)+5)<<40|  \
index 69d3ac4fc7e556bee057b570b90b9f34eac9c9cd..edb095a8d85c23bcd46a9770b508137006ea36f0 100644 (file)
@@ -1180,6 +1180,33 @@ tvb_get_ntohl(tvbuff_t *tvb, const gint offset)
        return pntohl(ptr);
 }
 
+guint64
+tvb_get_ntoh40(tvbuff_t *tvb, const gint offset)
+{
+       const guint8* ptr;
+
+       ptr = fast_ensure_contiguous(tvb, offset, 5);
+       return pntoh40(ptr);
+}
+
+guint64
+tvb_get_ntoh48(tvbuff_t *tvb, const gint offset)
+{
+       const guint8* ptr;
+
+       ptr = fast_ensure_contiguous(tvb, offset, 6);
+       return pntoh48(ptr);
+}
+
+guint64
+tvb_get_ntoh56(tvbuff_t *tvb, const gint offset)
+{
+       const guint8* ptr;
+
+       ptr = fast_ensure_contiguous(tvb, offset, 7);
+       return pntoh56(ptr);
+}
+
 guint64
 tvb_get_ntoh64(tvbuff_t *tvb, const gint offset)
 {
@@ -1419,6 +1446,33 @@ tvb_get_letohl(tvbuff_t *tvb, const gint offset)
        return pletohl(ptr);
 }
 
+guint64
+tvb_get_letoh40(tvbuff_t *tvb, const gint offset)
+{
+       const guint8* ptr;
+
+       ptr = fast_ensure_contiguous(tvb, offset, 5);
+       return pletoh40(ptr);
+}
+
+guint64
+tvb_get_letoh48(tvbuff_t *tvb, const gint offset)
+{
+       const guint8* ptr;
+
+       ptr = fast_ensure_contiguous(tvb, offset, 6);
+       return pletoh48(ptr);
+}
+
+guint64
+tvb_get_letoh56(tvbuff_t *tvb, const gint offset)
+{
+       const guint8* ptr;
+
+       ptr = fast_ensure_contiguous(tvb, offset, 7);
+       return pletoh56(ptr);
+}
+
 guint64
 tvb_get_letoh64(tvbuff_t *tvb, const gint offset)
 {
index cd9d63b659e58080457895b9d7d9422c44fe77c8..d377d395f4830424893faebfc7ac66015d3470b6 100644 (file)
@@ -319,6 +319,9 @@ extern guint8  tvb_get_guint8(tvbuff_t*, const gint offset);
 extern guint16 tvb_get_ntohs(tvbuff_t*, const gint offset);
 extern guint32 tvb_get_ntoh24(tvbuff_t*, const gint offset);
 extern guint32 tvb_get_ntohl(tvbuff_t*, const gint offset);
+extern guint64 tvb_get_ntoh40(tvbuff_t*, const gint offset);
+extern guint64 tvb_get_ntoh48(tvbuff_t*, const gint offset);
+extern guint64 tvb_get_ntoh56(tvbuff_t*, const gint offset);
 extern guint64 tvb_get_ntoh64(tvbuff_t*, const gint offset);
 extern gfloat tvb_get_ntohieee_float(tvbuff_t*, const gint offset);
 extern gdouble tvb_get_ntohieee_double(tvbuff_t*, const gint offset);
@@ -326,6 +329,9 @@ extern gdouble tvb_get_ntohieee_double(tvbuff_t*, const gint offset);
 extern guint16 tvb_get_letohs(tvbuff_t*, const gint offset);
 extern guint32 tvb_get_letoh24(tvbuff_t*, const gint offset);
 extern guint32 tvb_get_letohl(tvbuff_t*, const gint offset);
+extern guint64 tvb_get_letoh40(tvbuff_t*, const gint offset);
+extern guint64 tvb_get_letoh48(tvbuff_t*, const gint offset);
+extern guint64 tvb_get_letoh56(tvbuff_t*, const gint offset);
 extern guint64 tvb_get_letoh64(tvbuff_t*, const gint offset);
 extern gfloat tvb_get_letohieee_float(tvbuff_t*, const gint offset);
 extern gdouble tvb_get_letohieee_double(tvbuff_t*, const gint offset);