forked from osmocom/wireshark
lua: add support for ethernet addresses to the Address class
The code for the Address class already contains commented-out code for a number of additional address types. Activate the draft constructor for ethernet addresses and complete it. Use the newly-added function to parse a string that contains an ethernet address. Add a basic test tvb.lua. Read an ethernet address from a tvb and compare it to a constant Address.ether object. Change-Id: I9771dd6e7ade4b572a8b864b8986d641b4eba3e5 Reviewed-on: https://code.wireshark.org/review/30163 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
parent
0f3a4db657
commit
178001e74d
|
@ -60,6 +60,22 @@ WSLUA_CONSTRUCTOR Address_ipv6(lua_State* L) {
|
||||||
WSLUA_RETURN(1); /* The Address object */
|
WSLUA_RETURN(1); /* The Address object */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WSLUA_CONSTRUCTOR Address_ether(lua_State *L) {
|
||||||
|
/* Creates an Address Object representing an Ethernet address. */
|
||||||
|
|
||||||
|
#define WSLUA_ARG_Address_ether_ETH 1 /* The Ethernet address. */
|
||||||
|
Address addr = (Address)g_malloc(sizeof(address));
|
||||||
|
const gchar *name = luaL_checkstring(L, WSLUA_ARG_Address_ether_ETH);
|
||||||
|
guint8 eth_buf[6];
|
||||||
|
|
||||||
|
if(!str_to_eth(name, eth_buf))
|
||||||
|
memset(eth_buf, 0, sizeof(eth_buf));
|
||||||
|
|
||||||
|
alloc_address_wmem(NULL, addr, AT_ETHER, sizeof(eth_buf), eth_buf);
|
||||||
|
pushAddress(L, addr);
|
||||||
|
WSLUA_RETURN(1); /* The Address object. */
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* TODO */
|
/* TODO */
|
||||||
static int Address_ss7(lua_State* L) {
|
static int Address_ss7(lua_State* L) {
|
||||||
|
@ -70,14 +86,6 @@ static int Address_ss7(lua_State* L) {
|
||||||
pushAddress(L,addr);
|
pushAddress(L,addr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
static int Address_eth(lua_State* L) {
|
|
||||||
Address addr = g_malloc(sizeof(address));
|
|
||||||
|
|
||||||
/* alloc_address() */
|
|
||||||
|
|
||||||
pushAddress(L,addr);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
static int Address_sna(lua_State* L) {
|
static int Address_sna(lua_State* L) {
|
||||||
Address addr = g_malloc(sizeof(address));
|
Address addr = g_malloc(sizeof(address));
|
||||||
|
|
||||||
|
@ -164,9 +172,9 @@ WSLUA_METHODS Address_methods[] = {
|
||||||
WSLUA_CLASS_FNREG(Address,ip),
|
WSLUA_CLASS_FNREG(Address,ip),
|
||||||
WSLUA_CLASS_FNREG_ALIAS(Address,ipv4,ip),
|
WSLUA_CLASS_FNREG_ALIAS(Address,ipv4,ip),
|
||||||
WSLUA_CLASS_FNREG(Address,ipv6),
|
WSLUA_CLASS_FNREG(Address,ipv6),
|
||||||
|
WSLUA_CLASS_FNREG(Address,ether),
|
||||||
#if 0
|
#if 0
|
||||||
WSLUA_CLASS_FNREG_ALIAS(Address,ss7pc,ss7),
|
WSLUA_CLASS_FNREG_ALIAS(Address,ss7pc,ss7),
|
||||||
WSLUA_CLASS_FNREG(Address,eth),
|
|
||||||
WSLUA_CLASS_FNREG(Address,sna},
|
WSLUA_CLASS_FNREG(Address,sna},
|
||||||
WSLUA_CLASS_FNREG(Address,atalk),
|
WSLUA_CLASS_FNREG(Address,atalk),
|
||||||
WSLUA_CLASS_FNREG(Address,vines),
|
WSLUA_CLASS_FNREG(Address,vines),
|
||||||
|
|
|
@ -54,7 +54,7 @@ end
|
||||||
-- number of verifyFields() * (1 + number of fields) +
|
-- number of verifyFields() * (1 + number of fields) +
|
||||||
-- number of verifyResults() * (1 + 2 * number of values)
|
-- number of verifyResults() * (1 + 2 * number of values)
|
||||||
--
|
--
|
||||||
local taptests = { [FRAME]=4, [OTHER]=330 }
|
local taptests = { [FRAME]=4, [OTHER]=333 }
|
||||||
|
|
||||||
local function getResults()
|
local function getResults()
|
||||||
print("\n-----------------------------\n")
|
print("\n-----------------------------\n")
|
||||||
|
@ -166,6 +166,7 @@ local testfield =
|
||||||
ABSOLUTE_UTC = ProtoField.absolute_time("test.basic.absolute.utc", "Basic absolute utc", base.UTC),
|
ABSOLUTE_UTC = ProtoField.absolute_time("test.basic.absolute.utc", "Basic absolute utc", base.UTC),
|
||||||
IPv4 = ProtoField.ipv4 ("test.basic.ipv4", "Basic ipv4 address"),
|
IPv4 = ProtoField.ipv4 ("test.basic.ipv4", "Basic ipv4 address"),
|
||||||
IPv6 = ProtoField.ipv6 ("test.basic.ipv6", "Basic ipv6 address"),
|
IPv6 = ProtoField.ipv6 ("test.basic.ipv6", "Basic ipv6 address"),
|
||||||
|
ETHER = ProtoField.ether ("test.basic.ether", "Basic ethernet address"),
|
||||||
-- GUID = ProtoField.guid ("test.basic.guid", "Basic GUID"),
|
-- GUID = ProtoField.guid ("test.basic.guid", "Basic GUID"),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -216,6 +217,7 @@ local getfield =
|
||||||
ABSOLUTE_UTC = Field.new ("test.basic.absolute.utc"),
|
ABSOLUTE_UTC = Field.new ("test.basic.absolute.utc"),
|
||||||
IPv4 = Field.new ("test.basic.ipv4"),
|
IPv4 = Field.new ("test.basic.ipv4"),
|
||||||
IPv6 = Field.new ("test.basic.ipv6"),
|
IPv6 = Field.new ("test.basic.ipv6"),
|
||||||
|
ETHER = Field.new ("test.basic.ether"),
|
||||||
-- GUID = Field.new ("test.basic.guid"),
|
-- GUID = Field.new ("test.basic.guid"),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -576,6 +578,18 @@ function test_proto.dissector(tvbuf,pktinfo,root)
|
||||||
|
|
||||||
verifyFields("basic.IPv4", ipv4_match_fields)
|
verifyFields("basic.IPv4", ipv4_match_fields)
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
testing(OTHER, "tree:add ether")
|
||||||
|
|
||||||
|
local tvb = ByteArray.new("010203040506"):tvb("Ether")
|
||||||
|
local ether = testfield.basic.ETHER
|
||||||
|
local ether_match_fields = {}
|
||||||
|
|
||||||
|
execute ("ether", pcall (callTreeAdd, tree, ether, tvb:range(0,6)))
|
||||||
|
addMatchFields(ether_match_fields, Address.ether('01:02:03:04:05:06'))
|
||||||
|
|
||||||
|
verifyFields("basic.ETHER", ether_match_fields)
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
testing(OTHER, "tree:add_packet_field Bytes")
|
testing(OTHER, "tree:add_packet_field Bytes")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue