Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7907541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:29:37+00:00 2026-06-03T11:29:37+00:00

First of all, I’m new to Lua altogether, and this is my first attempt

  • 0

First of all, I’m new to Lua altogether, and this is my first attempt at writing a wireshark dissector.

My protocol is straightforward – a 2 byte length field, followed by a string of that length.

When I run the code through the Lua console, everything works as expected.

When the code is added to the Wireshark plugins directory, I get the error

Lua Error: [string “C:\Users…\AppData\Roaming\Wireshark…”]:15: calling ‘add’ on bad self (number expected, got string)

Line 15 corresponds is the t:add(f_text... line.

Can anyone explain the discrepancy between the execution methods?

do
    local p_multi = Proto("aggregator","Aggregator");

    local f_len = ProtoField.int16("aggregator.length","Length",base.DEC)
    local f_text = ProtoField.string("aggregator.text","Text")

    p_multi.fields = { f_len, f_text }

    local data_dis = Dissector.get("data")

    function p_multi.dissector(buf,pkt,root)
            pkt.cols.protocol = "Aggregator"
            local len = buf(0,2):int()
            local t = root:add(p_multi,buf(0,len+2))
            t:add(f_len,buf(0,2),"Length: " .. buf(0,2):int())
            t:add(f_text,buf(2,len),"Text: " .. buf(2,len):string())
    end

    local tcp_encap_table = DissectorTable.get("tcp.port")
    tcp_encap_table:add(4321,p_multi)
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:29:40+00:00Added an answer on June 3, 2026 at 11:29 am

    Your dissector code is very close to correct, but you’re doing extra work that the interface won’t accept. If you change your dissector function like so,

    function p_multi.dissector(buf,pkt,root)
            pkt.cols.protocol = "Aggregator"
            local len = buf(0,2):int()
            local t = root:add(p_multi,buf(0,len+2))
            t:add(f_len,buf(0,2)) --let Wireshark do the hard work
            t:add(f_text,buf(2,len)) --you've already defined their labels etc.
    end
    

    you’ll get the desired behavior. The labels “Text” and “Length” are already defined for your fields, so there is no need to provide them again on lines 15 and 16.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, this isn't for a keylogger, it's for an input in a
First of all, I'm quite new to the Android and JAVA world (coming from
First of all there is probably a question like this already but i couldn't
First of all, apologize because I have seen some posts about this, but I
First of all, I've googled for this error and all of the pages I
First of all this is all just concept, I have no actual programming done
First of all, this is not a dupe of this question . You'll see
First of all this is not a question about how can I use http
First of all, there is no chance that this is a multi-user issue, as
i have this code which i use in order to extract first all users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.