forked from osmocom/wireshark
Handle signed integers > 32 bits. Bug 8454 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8454)
svn path=/trunk/; revision=54183
This commit is contained in:
parent
1b4ea6bb68
commit
79d336c664
82
epan/proto.c
82
epan/proto.c
|
@ -222,6 +222,8 @@ proto_tree_set_uint(field_info *fi, guint32 value);
|
|||
static void
|
||||
proto_tree_set_int(field_info *fi, gint32 value);
|
||||
static void
|
||||
proto_tree_set_int64_tvb(field_info *fi, tvbuff_t *tvb, gint start, guint length, const guint encoding);
|
||||
static void
|
||||
proto_tree_set_uint64(field_info *fi, guint64 value);
|
||||
static void
|
||||
proto_tree_set_uint64_tvb(field_info *fi, tvbuff_t *tvb, gint start, guint length, const guint encoding);
|
||||
|
@ -1358,7 +1360,14 @@ proto_tree_new_item(field_info *new_fi, proto_tree *tree,
|
|||
length_error = length < 1 ? TRUE : FALSE;
|
||||
report_type_length_mismatch(tree, "a 64-bit integer", length, length_error);
|
||||
}
|
||||
proto_tree_set_uint64_tvb(new_fi, tvb, start, length, encoding);
|
||||
if (new_fi->hfinfo->type == FT_INT64)
|
||||
{
|
||||
proto_tree_set_int64_tvb(new_fi, tvb, start, length, encoding);
|
||||
}
|
||||
else
|
||||
{
|
||||
proto_tree_set_uint64_tvb(new_fi, tvb, start, length, encoding);
|
||||
}
|
||||
break;
|
||||
|
||||
/* XXX - make these just FT_INT? */
|
||||
|
@ -2557,6 +2566,77 @@ proto_tree_set_uint64_tvb(field_info *fi, tvbuff_t *tvb, gint start,
|
|||
proto_tree_set_uint64(fi, value);
|
||||
}
|
||||
|
||||
static void
|
||||
proto_tree_set_int64_tvb(field_info *fi, tvbuff_t *tvb, gint start,
|
||||
guint length, const guint encoding)
|
||||
{
|
||||
guint64 value = 0;
|
||||
guint8* b = (guint8 *)tvb_memdup(wmem_packet_scope(), tvb, start, length);
|
||||
|
||||
if (encoding) {
|
||||
b += length;
|
||||
switch (length) {
|
||||
default: DISSECTOR_ASSERT_NOT_REACHED();
|
||||
case 8: value <<= 8; value += *--b;
|
||||
case 7: value <<= 8; value += *--b;
|
||||
case 6: value <<= 8; value += *--b;
|
||||
case 5: value <<= 8; value += *--b;
|
||||
case 4: value <<= 8; value += *--b;
|
||||
case 3: value <<= 8; value += *--b;
|
||||
case 2: value <<= 8; value += *--b;
|
||||
case 1: value <<= 8; value += *--b;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (length) {
|
||||
default: DISSECTOR_ASSERT_NOT_REACHED();
|
||||
case 8: value <<= 8; value += *b++;
|
||||
case 7: value <<= 8; value += *b++;
|
||||
case 6: value <<= 8; value += *b++;
|
||||
case 5: value <<= 8; value += *b++;
|
||||
case 4: value <<= 8; value += *b++;
|
||||
case 3: value <<= 8; value += *b++;
|
||||
case 2: value <<= 8; value += *b++;
|
||||
case 1: value <<= 8; value += *b++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(length)
|
||||
{
|
||||
case 7:
|
||||
if (value & 0x80000000000000LL) /* account for sign bit */
|
||||
value |= 0xFF00000000000000LL;
|
||||
break;
|
||||
case 6:
|
||||
if (value & 0x800000000000LL) /* account for sign bit */
|
||||
value |= 0xFFFF000000000000LL;
|
||||
break;
|
||||
case 5:
|
||||
if (value & 0x8000000000LL) /* account for sign bit */
|
||||
value |= 0xFFFFFF0000000000LL;
|
||||
break;
|
||||
case 4:
|
||||
if (value & 0x80000000LL) /* account for sign bit */
|
||||
value |= 0xFFFFFFFF00000000LL;
|
||||
break;
|
||||
case 3:
|
||||
if (value & 0x800000LL) /* account for sign bit */
|
||||
value |= 0xFFFFFFFFFF000000LL;
|
||||
break;
|
||||
case 2:
|
||||
if (value & 0x8000LL) /* account for sign bit */
|
||||
value |= 0xFFFFFFFFFFFF0000LL;
|
||||
break;
|
||||
case 1:
|
||||
if (value & 0x80LL) /* account for sign bit */
|
||||
value |= 0xFFFFFFFFFFFFFF00LL;
|
||||
break;
|
||||
}
|
||||
|
||||
proto_tree_set_uint64(fi, value);
|
||||
}
|
||||
|
||||
/* Add a FT_STRING or FT_STRINGZ to a proto_tree. Creates own copy of string,
|
||||
* and frees it when the proto_tree is destroyed. */
|
||||
proto_item *
|
||||
|
|
|
@ -836,6 +836,18 @@ tvb_get_ntoh40(tvbuff_t *tvb, const gint offset)
|
|||
return pntoh40(ptr);
|
||||
}
|
||||
|
||||
gint64
|
||||
tvb_get_ntohi40(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
guint64 ret;
|
||||
|
||||
ret = tvb_get_ntoh40(tvb, offset);
|
||||
if (ret & 0x8000000000LL) /* account for sign bit */
|
||||
ret |= 0xFFFFFF0000000000LL;
|
||||
|
||||
return (gint64)ret;
|
||||
}
|
||||
|
||||
guint64
|
||||
tvb_get_ntoh48(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
|
@ -845,6 +857,18 @@ tvb_get_ntoh48(tvbuff_t *tvb, const gint offset)
|
|||
return pntoh48(ptr);
|
||||
}
|
||||
|
||||
gint64
|
||||
tvb_get_ntohi48(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
guint64 ret;
|
||||
|
||||
ret = tvb_get_ntoh48(tvb, offset);
|
||||
if (ret & 0x800000000000LL) /* account for sign bit */
|
||||
ret |= 0xFFFF000000000000LL;
|
||||
|
||||
return (gint64)ret;
|
||||
}
|
||||
|
||||
guint64
|
||||
tvb_get_ntoh56(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
|
@ -854,6 +878,18 @@ tvb_get_ntoh56(tvbuff_t *tvb, const gint offset)
|
|||
return pntoh56(ptr);
|
||||
}
|
||||
|
||||
gint64
|
||||
tvb_get_ntohi56(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
guint64 ret;
|
||||
|
||||
ret = tvb_get_ntoh56(tvb, offset);
|
||||
if (ret & 0x80000000000000LL) /* account for sign bit */
|
||||
ret |= 0xFF00000000000000LL;
|
||||
|
||||
return (gint64)ret;
|
||||
}
|
||||
|
||||
guint64
|
||||
tvb_get_ntoh64(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
|
@ -1102,6 +1138,18 @@ tvb_get_letoh40(tvbuff_t *tvb, const gint offset)
|
|||
return pletoh40(ptr);
|
||||
}
|
||||
|
||||
gint64
|
||||
tvb_get_letohi40(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
guint64 ret;
|
||||
|
||||
ret = tvb_get_letoh40(tvb, offset);
|
||||
if (ret & 0x8000000000LL) /* account for sign bit */
|
||||
ret |= 0xFFFFFF0000000000LL;
|
||||
|
||||
return (gint64)ret;
|
||||
}
|
||||
|
||||
guint64
|
||||
tvb_get_letoh48(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
|
@ -1111,6 +1159,18 @@ tvb_get_letoh48(tvbuff_t *tvb, const gint offset)
|
|||
return pletoh48(ptr);
|
||||
}
|
||||
|
||||
gint64
|
||||
tvb_get_letohi48(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
guint64 ret;
|
||||
|
||||
ret = tvb_get_letoh48(tvb, offset);
|
||||
if (ret & 0x800000000000LL) /* account for sign bit */
|
||||
ret |= 0xFFFF000000000000LL;
|
||||
|
||||
return (gint64)ret;
|
||||
}
|
||||
|
||||
guint64
|
||||
tvb_get_letoh56(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
|
@ -1120,6 +1180,18 @@ tvb_get_letoh56(tvbuff_t *tvb, const gint offset)
|
|||
return pletoh56(ptr);
|
||||
}
|
||||
|
||||
gint64
|
||||
tvb_get_letohi56(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
guint64 ret;
|
||||
|
||||
ret = tvb_get_letoh56(tvb, offset);
|
||||
if (ret & 0x80000000000000LL) /* account for sign bit */
|
||||
ret |= 0xFF00000000000000LL;
|
||||
|
||||
return (gint64)ret;
|
||||
}
|
||||
|
||||
guint64
|
||||
tvb_get_letoh64(tvbuff_t *tvb, const gint offset)
|
||||
{
|
||||
|
|
|
@ -285,8 +285,11 @@ WS_DLL_PUBLIC guint16 tvb_get_ntohs(tvbuff_t *tvb, const gint offset);
|
|||
WS_DLL_PUBLIC guint32 tvb_get_ntoh24(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC guint32 tvb_get_ntohl(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC guint64 tvb_get_ntoh40(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC gint64 tvb_get_ntohi40(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC guint64 tvb_get_ntoh48(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC gint64 tvb_get_ntohi48(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC guint64 tvb_get_ntoh56(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC gint64 tvb_get_ntohi56(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC guint64 tvb_get_ntoh64(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC gfloat tvb_get_ntohieee_float(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC gdouble tvb_get_ntohieee_double(tvbuff_t *tvb,
|
||||
|
@ -296,8 +299,11 @@ WS_DLL_PUBLIC guint16 tvb_get_letohs(tvbuff_t *tvb, const gint offset);
|
|||
WS_DLL_PUBLIC guint32 tvb_get_letoh24(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC guint32 tvb_get_letohl(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC guint64 tvb_get_letoh40(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC gint64 tvb_get_letohi40(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC guint64 tvb_get_letoh48(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC gint64 tvb_get_letohi48(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC guint64 tvb_get_letoh56(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC gint64 tvb_get_letohi56(tvbuff_t *tvb, const gint offset);
|
||||
WS_DLL_PUBLIC guint64 tvb_get_letoh64(tvbuff_t *tvb, const gint offset);
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue