diff options
author | Chris Maynard <Christopher.Maynard@GTECH.COM> | 2011-01-14 19:02:38 +0000 |
---|---|---|
committer | Chris Maynard <Christopher.Maynard@GTECH.COM> | 2011-01-14 19:02:38 +0000 |
commit | 116d67e1645eacacaa08aa8823e30b68713e7ea9 (patch) | |
tree | 216776fb60a77a33b43045cf3639b9ce6c2242a4 | |
parent | f37c04357b6fc22e3b60cdac3571804d12cdf986 (diff) |
Add tvb_get_[n|le]toh[40|48|56]() accessors. Addresses bug 5082.
svn path=/trunk/; revision=35538
-rw-r--r-- | asn1/mpeg-pes/packet-mpeg-pes-template.c | 24 | ||||
-rw-r--r-- | doc/README.developer | 6 | ||||
-rw-r--r-- | epan/dissectors/packet-mpeg-pes.c | 28 | ||||
-rw-r--r-- | epan/libwireshark.def | 6 | ||||
-rw-r--r-- | epan/pint.h | 48 | ||||
-rw-r--r-- | epan/tvbuff.c | 54 | ||||
-rw-r--r-- | epan/tvbuff.h | 6 |
7 files changed, 132 insertions, 40 deletions
diff --git a/asn1/mpeg-pes/packet-mpeg-pes-template.c b/asn1/mpeg-pes/packet-mpeg-pes-template.c index 0f7b93795f..3e24b92ef2 100644 --- a/asn1/mpeg-pes/packet-mpeg-pes-template.c +++ b/asn1/mpeg-pes/packet-mpeg-pes-template.c @@ -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 */ diff --git a/doc/README.developer b/doc/README.developer index b8956c82b8..ba810d6d07 100644 --- a/doc/README.developer +++ b/doc/README.developer @@ -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 diff --git a/epan/dissectors/packet-mpeg-pes.c b/epan/dissectors/packet-mpeg-pes.c index 710634dd58..578c12e24f 100644 --- a/epan/dissectors/packet-mpeg-pes.c +++ b/epan/dissectors/packet-mpeg-pes.c @@ -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 diff --git a/epan/libwireshark.def b/epan/libwireshark.def index 27b13b5ee9..612f733cbb 100644 --- a/epan/libwireshark.def +++ b/epan/libwireshark.def @@ -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 diff --git a/epan/pint.h b/epan/pint.h index 42ca539a3a..da6480819b 100644 --- a/epan/pint.h +++ b/epan/pint.h @@ -39,13 +39,35 @@ (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| \ @@ -61,13 +83,35 @@ (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| \ diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 69d3ac4fc7..edb095a8d8 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -1181,6 +1181,33 @@ tvb_get_ntohl(tvbuff_t *tvb, const gint offset) } 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) { const guint8* ptr; @@ -1420,6 +1447,33 @@ tvb_get_letohl(tvbuff_t *tvb, const gint offset) } 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) { const guint8* ptr; diff --git a/epan/tvbuff.h b/epan/tvbuff.h index cd9d63b659..d377d395f4 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -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); |