This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Setting and getting a preference of an existing protocol from Lua

0

Hi, Would anyone know if it's possible to get or set a preference of an existing protocol from Lua ?

thanks

asked 27 Jun '11, 10:22

izopizo's gravatar image

izopizo
2024714
accept rate: 0%

By "existing protocol", do you mean a protocol that was not registered from Lua (e.g., "ip")?

(27 Jun '11, 19:08) helloworld

Yes, For example wireshark preferences file contains following attribute ip.defragment: TRUE Is there a way I can get or set this preference ?

I'm aware of the ability to get/set preferences if I define my own protocol in lua but I'm looking for a way of doing the same thing for protocols like IP/TCP/UDP or any other not registered from Lua.

(28 Jun '11, 02:16) izopizo

There's not even a documented, supported way of doing that from C, much less from Lua.

Why do you want to know the settings of some other protocol's preferences? By doing so, you're making an assumption about what its preferences are, and that can change over time.

(28 Jun '11, 11:03) Guy Harris ♦♦

Looks simple from C. I know you need Lua, but since Guy mentioned it, I thought I'd list it in case someone cares:

(28 Jun '11, 19:47) helloworld

Since all prefs are read from and written to a file, it is possible from Lua to read/set a preference of a protocol that wasn't originally registered from Lua. It's kind of a pain though...

(28 Jun '11, 19:50) helloworld

But then there are command-line overrides (the -o flag) that aren't written to file, so Lua can't know about those...

(28 Jun '11, 19:53) helloworld

Exactly. Those routines were not intended to be used by dissectors; they're intended to be used by programs when starting up or, in the case of read_prefs_file(), by the code that maintains the "recents" file. They may or may not do what you want when used elsewhere, and they may or may not continue to exist with the current interface or even continue to exist at all.

(28 Jun '11, 20:07) Guy Harris ♦♦
1

Thanks for all your responses. What I was hoping to do was to change preferences on the fly. For example MTP3 protocol can come in different version ITU/ANSI I wanted to implement autodetection in LUA and change preferences on the fly accordingly

Thanks again

(29 Jun '11, 09:52) izopizo

"Autodetection" in what sense? Are you, in effect, trying to enhance the MTP3 dissector in a Lua add-on, so that, rather than requiring the user to determine whether the MTP3 traffic is ITU or ANSI, the Lua script will look at the traffic, attempt to determine whether it's ITU or ANSI, and then change the preference accordingly?

(29 Jun '11, 09:56) Guy Harris ♦♦
showing 5 of 9 show 4 more comments

2 Answers:

1

The fast answer is no.

AFAIK, setting prefs of non-Lua protocols on-the-fly from Wireshark's Lua API is not possible. As a hack, Lua can "stage" a pref setting by writing to the preferences file, which Wireshark would read at startup or on profile change (the Lua API alone can't trigger either of these events). Still, nothing prevents the user from changing your setting in the meantime.

Lua can read a pref that was set from the GUI as soon as the user changes it because updates are written to preferences immediately. The problem here is determining which preferences to read, since each configuration profile can have its own, and Lua can't know which is active. And as mentioned in comments, Lua can't detect pref overrides from the command line's -o flag (which are not reflected in preferences).

Your best bet is to submit an enhancement request for the Lua API (and vote!).

answered 29 Jun '11, 23:48

helloworld's gravatar image

helloworld
3.1k42041
accept rate: 28%

0

Check this out: http://sharkfest.wireshark.org/sharkfest.09/DT06_Bjorlykke_Lua%20Scripting%20in%20Wireshark.pdf Page 33 is about Prefs..

answered 28 Jun '11, 02:06

Hiftu's gravatar image

Hiftu
442
accept rate: 0%