diff options
author | Franklin "Snaipe" Mathieu <snaipe@diacritic.io> | 2016-11-04 15:28:28 +0100 |
---|---|---|
committer | Alexis La Goutte <alexis.lagoutte@gmail.com> | 2016-11-06 09:01:16 +0000 |
commit | e95519b7f95517780e912df1277f06f707d1176e (patch) | |
tree | 171d0ba6ab3825d6a1962a3e857ad83e2046249d | |
parent | f894379ea73619d6c31e5c4932d93e307741ffec (diff) |
lua: Added new integer sizes in TvbRange
* Added support for 3-byte integers in :int() and :le_int()
* Added support for 5, 6, and 7-byte integers in :int64() and :le_int64()
Change-Id: If9ab4ea806191bc63effe45a081b9c65693c2367
Signed-off-by: Franklin "Snaipe" Mathieu <snaipe@diacritic.io>
Reviewed-on: https://code.wireshark.org/review/18672
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
-rw-r--r-- | epan/wslua/wslua_tvb.c | 42 | ||||
-rw-r--r-- | test/lua/tvb.lua | 28 |
2 files changed, 63 insertions, 7 deletions
diff --git a/epan/wslua/wslua_tvb.c b/epan/wslua/wslua_tvb.c index 5d12df941e..33ffa65ddc 100644 --- a/epan/wslua/wslua_tvb.c +++ b/epan/wslua/wslua_tvb.c @@ -421,7 +421,7 @@ WSLUA_METHOD TvbRange_tvb(lua_State *L) { */ WSLUA_METHOD TvbRange_uint(lua_State* L) { /* Get a Big Endian (network order) unsigned integer from a `TvbRange`. - The range must be 1, 2, 3 or 4 octets long. */ + The range must be 1-4 octets long. */ TvbRange tvbr = checkTvbRange(L,1); if (!(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { @@ -453,7 +453,7 @@ WSLUA_METHOD TvbRange_uint(lua_State* L) { */ WSLUA_METHOD TvbRange_le_uint(lua_State* L) { /* Get a Little Endian unsigned integer from a `TvbRange`. - The range must be 1, 2, 3 or 4 octets long. */ + The range must be 1-4 octets long. */ TvbRange tvbr = checkTvbRange(L,1); if (!(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { @@ -574,7 +574,7 @@ WSLUA_METHOD TvbRange_le_uint64(lua_State* L) { */ WSLUA_METHOD TvbRange_int(lua_State* L) { /* Get a Big Endian (network order) signed integer from a `TvbRange`. - The range must be 1, 2 or 4 octets long. */ + The range must be 1-4 octets long. */ TvbRange tvbr = checkTvbRange(L,1); if (!(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { @@ -589,6 +589,9 @@ WSLUA_METHOD TvbRange_int(lua_State* L) { case 2: lua_pushnumber(L,(gshort)tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; + case 3: + lua_pushnumber(L,(gint)tvb_get_ntoh24(tvbr->tvb->ws_tvb,tvbr->offset)); + return 1; case 4: lua_pushnumber(L,(gint)tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The signed integer value */ @@ -610,7 +613,7 @@ WSLUA_METHOD TvbRange_int(lua_State* L) { */ WSLUA_METHOD TvbRange_le_int(lua_State* L) { /* Get a Little Endian signed integer from a `TvbRange`. - The range must be 1, 2 or 4 octets long. */ + The range must be 1-4 octets long. */ TvbRange tvbr = checkTvbRange(L,1); if (!(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { @@ -625,6 +628,9 @@ WSLUA_METHOD TvbRange_le_int(lua_State* L) { case 2: lua_pushnumber(L,(gshort)tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; + case 3: + lua_pushnumber(L,(gint)tvb_get_letoh24(tvbr->tvb->ws_tvb,tvbr->offset)); + return 1; case 4: lua_pushnumber(L,(gint)tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The signed integer value. */ @@ -639,7 +645,7 @@ WSLUA_METHOD TvbRange_le_int(lua_State* L) { */ WSLUA_METHOD TvbRange_int64(lua_State* L) { /* Get a Big Endian (network order) signed 64 bit integer from a `TvbRange`, as an `Int64` object. - The range must be 1, 2, 4 or 8 octets long. */ + The range must be 1-8 octets long. */ TvbRange tvbr = checkTvbRange(L,1); if (!(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { @@ -654,9 +660,21 @@ WSLUA_METHOD TvbRange_int64(lua_State* L) { case 2: pushInt64(L,(gint16)tvb_get_ntohs(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; + case 3: + pushInt64(L,(gint)tvb_get_ntoh24(tvbr->tvb->ws_tvb,tvbr->offset)); + return 1; case 4: pushInt64(L,(gint32)tvb_get_ntohl(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; + case 5: + pushInt64(L,(gint64)tvb_get_ntoh40(tvbr->tvb->ws_tvb,tvbr->offset)); + return 1; + case 6: + pushInt64(L,(gint64)tvb_get_ntoh48(tvbr->tvb->ws_tvb,tvbr->offset)); + return 1; + case 7: + pushInt64(L,(gint64)tvb_get_ntoh56(tvbr->tvb->ws_tvb,tvbr->offset)); + return 1; case 8: pushInt64(L,(gint64)tvb_get_ntoh64(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The `Int64` object. */ @@ -671,7 +689,7 @@ WSLUA_METHOD TvbRange_int64(lua_State* L) { */ WSLUA_METHOD TvbRange_le_int64(lua_State* L) { /* Get a Little Endian signed 64 bit integer from a `TvbRange`, as an `Int64` object. - The range must be 1, 2, 4 or 8 octets long. */ + The range must be 1-8 octets long. */ TvbRange tvbr = checkTvbRange(L,1); if (!(tvbr && tvbr->tvb)) return 0; if (tvbr->tvb->expired) { @@ -686,9 +704,21 @@ WSLUA_METHOD TvbRange_le_int64(lua_State* L) { case 2: pushInt64(L,(gint16)tvb_get_letohs(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; + case 3: + pushInt64(L,(gint)tvb_get_letoh24(tvbr->tvb->ws_tvb,tvbr->offset)); + return 1; case 4: pushInt64(L,(gint32)tvb_get_letohl(tvbr->tvb->ws_tvb,tvbr->offset)); return 1; + case 5: + pushInt64(L,(gint64)tvb_get_letoh40(tvbr->tvb->ws_tvb,tvbr->offset)); + return 1; + case 6: + pushInt64(L,(gint64)tvb_get_letoh48(tvbr->tvb->ws_tvb,tvbr->offset)); + return 1; + case 7: + pushInt64(L,(gint64)tvb_get_letoh56(tvbr->tvb->ws_tvb,tvbr->offset)); + return 1; case 8: pushInt64(L,(gint64)tvb_get_letoh64(tvbr->tvb->ws_tvb,tvbr->offset)); WSLUA_RETURN(1); /* The `Int64` object. */ diff --git a/test/lua/tvb.lua b/test/lua/tvb.lua index 6b63ff447a..1eb576c973 100644 --- a/test/lua/tvb.lua +++ b/test/lua/tvb.lua @@ -54,7 +54,7 @@ end -- number of verifyFields() * (1 + number of fields) + -- number of verifyResults() * (1 + 2 * number of values) -- -local taptests = { [FRAME]=4, [OTHER]=318 } +local taptests = { [FRAME]=4, [OTHER]=330 } local function getResults() print("\n-----------------------------\n") @@ -149,6 +149,7 @@ local testfield = STRING = ProtoField.string ("test.basic.string", "Basic string"), BOOLEAN = ProtoField.bool ("test.basic.boolean", "Basic boolean", 16, {"yes","no"}, 0x0001), UINT16 = ProtoField.uint16 ("test.basic.uint16", "Basic uint16"), + INT24 = ProtoField.int24 ("test.basic.uint24", "Basic uint24"), BYTES = ProtoField.bytes ("test.basic.bytes", "Basic Bytes"), UINT_BYTES = ProtoField.ubytes ("test.basic.ubytes", "Basic Uint Bytes"), OID = ProtoField.oid ("test.basic.oid", "Basic OID"), @@ -197,6 +198,7 @@ local getfield = STRING = Field.new ("test.basic.string"), BOOLEAN = Field.new ("test.basic.boolean"), UINT16 = Field.new ("test.basic.uint16"), + INT24 = Field.new ("test.basic.uint24"), BYTES = Field.new ("test.basic.bytes"), UINT_BYTES = Field.new ("test.basic.ubytes"), OID = Field.new ("test.basic.oid"), @@ -427,6 +429,30 @@ function test_proto.dissector(tvbuf,pktinfo,root) verifyFields("basic.UINT16", uint16_match_fields) ---------------------------------------- + testing(OTHER, "Basic int24") + + local int24_match_fields = {} + + execute ("basic-int24", pcall (callTreeAdd, tree, testfield.basic.INT24, tvb_bytes:range(0,3)) ) + addMatchFields(int24_match_fields, 65280) + + execute ("basic-int24", pcall (callTreeAdd, tree, testfield.basic.INT24, tvb_bytes:range(3,3)) ) + addMatchFields(int24_match_fields, 98304) + + verifyFields("basic.INT24", int24_match_fields) + +---------------------------------------- + testing(OTHER, "Basic int24-le") + + execute ("basic-int24", pcall (callTreeAddLE, tree, testfield.basic.INT24, tvb_bytes:range(0,3)) ) + addMatchFields(int24_match_fields, 65280) + + execute ("basic-int24", pcall (callTreeAddLE, tree, testfield.basic.INT24, tvb_bytes:range(3,3)) ) + addMatchFields(int24_match_fields, 32769) + + verifyFields("basic.INT24", int24_match_fields) + +---------------------------------------- testing(OTHER, "Basic bytes") local bytes_match_fields = {} |