Question

I am getting no luck searching for a standard function to do byte-order conversion to write a lua plug-in for wireshark.

struct.pack doesn't seem to work, at least when doing "require 'struct'", wireshark throws an error.

You can call tvb functions to get an explicit (that's what I am doing now so it's not portable :((( ) conversion to either big endian or little endian, but nothing to the host endian byte order.

I searched and searched online but nothing came up so I am hoping someone can offer a solution.

Thanks!

Was it helpful?

Solution

Is it enough if you can determine the endianness of the system you are running on?

In Lua 5.1 and 5.2 at least, the 7th byte of the bytecode header is 1 for little endian systems and 0 for big endian systems. You can obtain this byte from any Lua script this way:

string.dump(function() end):byte(7)

If you use LuaJIT you can just check the value of:

ffi.abi("le")

Finding this out should be enough to let you write portable code.

OTHER TIPS

Wireshark is close to supporting struct.unpack way of doing things. It's not out on a stable release yet.

http://ask.wireshark.org/questions/32715/no-struct-support-in-wireshark-1107s-lua-interpreter

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top