2013-06-25 47 views
1

如何根據以太網中的類型字段調用您自己的解剖器? 從以太網幀中獲取Type值後,我想要解析帶有一些添加字段的自定義以太網幀,然後進行正常解剖。在第2層添加Wireshark解剖器

我可以寫解剖器,它可以解析指定的UDP/TCP端口上的數據包,但不知道如何執行指定的以太網類型。

回答

0

以下代碼將vlan_dissector註冊爲以太網802.1Q幀的解析器。

-- subscribe for Ethernet packets on type 33024(0x8100). 
    local eth_table = Dissector.get("ethertype") 
    eth_table:add(33024, vlan_dissector) 
0

我現在有工作片段。這只是一個原型。

-- create myproto protocol and its fields 
p_myproto = Proto ("myproto","My Protocol") 
local f_command = ProtoField.uint16("myproto.command", "Command", base.HEX) 
local f_data = ProtoField.string("myproto.data", "Data", FT_STRING) 

p_myproto.fields = {f_command} 

-- myproto dissector function 
function p_myproto.dissector (buf, pkt, root) 
    -- validate packet length is adequate, otherwise quit 
    if buf:len() == 0 then return end 
    pkt.cols.protocol = p_myproto.name 

    -- create subtree for myproto 
    subtree = root:add(p_myproto, buf(0)) 
    -- add protocol fields to subtree 
    subtree:add(f_command, buf(0,2)):append_text(" [Command text]") 

    -- description of payload 
    subtree:append_text(", Command details here or in the tree below") 
end 

-- Initialization routine 
function p_myproto.init() 
end 

-- subscribe for Ethernet packets on type 5212 (0x145c). 
local eth_table = DissectorTable.get("ethertype") 
eth_table:add(5212, p_myproto) 
相關問題