Wireshark Developer Guide A4
Wireshark Developer Guide A4
Preface ......................................................................................................................... x
1. Foreword .......................................................................................................... x
2. Who should read this document? .......................................................................... x
3. Acknowledgements ............................................................................................ x
4. About this document .......................................................................................... x
5. Where to get the latest copy of this document? ....................................................... xi
6. Providing feedback about this document ............................................................... xi
I. Wireshark Build Environment ....................................................................................... 1
1. Introduction ...................................................................................................... 2
1.1. Introduction ............................................................................................ 2
1.2. What is Wireshark? ................................................................................. 2
1.3. Supported Platforms ................................................................................. 2
1.3.1. Unix ........................................................................................... 2
1.3.2. Linux .......................................................................................... 2
1.3.3. Microsoft Windows ....................................................................... 3
1.4. Development and maintenance of Wireshark ................................................ 3
1.4.1. Programming languages used .......................................................... 3
1.4.2. Open Source Software ................................................................... 4
1.5. Releases and distributions ......................................................................... 4
1.5.1. Binary distributions ....................................................................... 4
1.5.2. Source code distributions ................................................................ 5
1.6. Automated Builds (Buildbot) ..................................................................... 5
1.6.1. Advantages .................................................................................. 5
1.6.2. What does the Buildbot do? ............................................................ 6
1.7. Reporting problems and getting help ........................................................... 6
1.7.1. Website ....................................................................................... 6
1.7.2. Wiki ........................................................................................... 6
1.7.3. FAQ ........................................................................................... 7
1.7.4. Other sources ............................................................................... 7
1.7.5. Mailing Lists ................................................................................ 7
1.7.6. Bug database (Bugzilla) ................................................................. 8
1.7.7. Q&A Site .................................................................................... 8
1.7.8. Reporting Problems ....................................................................... 8
1.7.9. Reporting Crashes on UNIX/Linux platforms ..................................... 9
1.7.10. Reporting Crashes on Windows platforms ........................................ 9
2. Quick Setup .................................................................................................... 10
2.1. UNIX: Installation ................................................................................. 10
2.2. Win32/64: Step-by-Step Guide ................................................................. 10
2.2.1. Install Microsoft C compiler and SDK ............................................ 10
2.2.2. Install Qt ................................................................................... 11
2.2.3. Install Cygwin ............................................................................ 11
2.2.4. Install PowerShell ....................................................................... 12
2.2.5. Optional: Install Chocolatey .......................................................... 12
2.2.6. Install Python ............................................................................. 12
2.2.7. Install Git .................................................................................. 12
2.2.8. Install and Prepare Sources ........................................................... 13
2.2.9. Open a Visual Studio Command Prompt .......................................... 13
2.2.10. Verify installed tools .................................................................. 14
2.2.11. Install Libraries ......................................................................... 15
2.2.12. Build Wireshark ........................................................................ 15
2.2.13. Debug Environment Setup ........................................................... 16
2.2.14. Optional: Create Users and Developers Guide ............................... 16
2.2.15. Optional: Create a Wireshark Installer ........................................... 16
3. Work with the Wireshark sources ........................................................................ 17
3.1. Introduction .......................................................................................... 17
3.2. The Wireshark Git repository ................................................................... 17
3.2.1. The web interface to the Git repository ............................................ 17
3.3. Obtain the Wireshark sources ................................................................... 18
iii
iv
vi
vii
viii
100
100
100
100
100
100
100
101
111
111
111
116
116
119
120
126
126
126
126
126
127
127
127
127
127
127
128
128
128
128
128
129
129
129
129
129
129
131
131
131
132
132
132
133
133
133
134
134
134
134
134
135
135
135
135
136
136
136
ix
136
136
136
136
137
137
137
137
137
138
138
138
138
138
138
138
141
141
143
143
149
155
156
158
159
165
165
165
165
166
166
166
166
167
167
167
167
168
Preface
1. Foreword
This book tries to give you a guide to start your own experiments into the wonderful world of
Wireshark development.
Developers who are new to Wireshark often have a hard time getting their development environment
up and running. This is especially true for Win32 developers, as a lot of the tools and methods used
when building Wireshark are much more common in the UNIX world than on Win32.
The first part of this book will describe how to set up the environment needed to develop Wireshark.
The second part of this book will describe how to change the Wireshark source code.
We hope that you find this book useful, and look forward to your comments.
3. Acknowledgements
The authors would like to thank the whole Wireshark team for their assistance. In particular, the authors
would like to thank:
Gerald Combs, for initiating the Wireshark project.
Guy Harris, for many helpful hints and his effort in maintaining the various contributions on the
mailing lists.
Frank Singleton from whose README.idl2wrs Section 9.8, idl2wrs: Creating dissectors from
CORBA IDL files is derived.
The authors would also like to thank the following people for their helpful feedback on this document:
XXX - Please give feedback :-)
And of course a big thank you to the many, many contributors of the Wireshark development
community!
Preface
This is a warning
You should pay attention to a warning, as otherwise data loss might occur.
This is a note
A note will point you to common mistakes and things that might not be obvious.
This is a tip
Tips will be helpful for your everyday work developing Wireshark.
xi
Chapter 1. Introduction
1.1. Introduction
This chapter will provide you with information about Wireshark development in general.
1.3.1. Unix
Apple Mac OS X
BeOS
FreeBSD
HP-UX
IBM AIX
NetBSD
OpenBSD
SCO UnixWare/OpenUnix
SGI Irix
Sun Solaris/Intel
Sun Solaris/Sparc
Tru64 UNIX (formerly Digital UNIX)
1.3.2. Linux
Debian GNU/Linux
Ubuntu
Introduction
Gentoo Linux
IBM S/390 Linux (Red Hat)
Mandrake Linux
PLD Linux
Red Hat Linux
Rock Linux
Slackware Linux
Suse Linux
Introduction
The typical task for a new Wireshark developer is to extend an existing, or write a new dissector for a
specific network protocol. As (almost) any dissector is written in plain old ANSI C, a good knowledge
about ANSI C will be sufficient for Wireshark development in almost any case.
So unless you are going to change the build process of Wireshark itself, you wont come in touch with
any other programming language than ANSI C (such as Perl or Python, which are used only in the
Wireshark build process).
Beside the usual tools for developing a program in C (compiler, make, ), the build process uses some
additional helper tools (Perl, Python, Sed, ), which are needed for the build process when Wireshark
is to be build and installed from the released source packages. If Wireshark is installed from a binary
package, none of these helper tools are needed on the target system.
Introduction
Win32 PAF (.paf.exe file). Another Windows end user method is to get a portable application file
which will install all the required things for him.
Debian (.deb file). A user of a Debian Package Manager (DPKG) based system obtains a .deb file
from which the package manager checks the dependencies and installs the software.
Red Hat (.rpm file). A user of a Red Hat Package Manager (RPM) based system obtains an .rpm
file from which the package manager checks the dependencies and installs the software.
MAC OS X (.dmg file). The typical MAC OS X end user is used to get a .dmg file which will install
all the required things for him. The other requirement is to have the X11.app installed.
Solaris. A Solaris user obtains a file from which the package manager (PKG) checks the
dependencies and installs the software.
However, if you want to start developing with Wireshark, the binary distributions wont be too helpful,
as you need the source files, of course.
For details about how to build these binary distributions yourself, e.g. if you need a distribution for a
special audience, see Section 3.11, Binary packaging.
1.6.1. Advantages
Recognizing (cross platform) build problems - early. Compilation problems can be narrowed down
to a few commits, making a fix much easier.
"Health status" overview of the sources. A quick look at: http://buildbot.wireshark.org/trunk/ gives
a good "feeling" if the sources are currently "well". On the other hand, if all is "red", an update of
a personal source tree might better be done later
"Up to date" binary packages are available. After a change was committed to the repository, a binary
package / installer is usually available within a few hours at: https://www.wireshark.org/download/
automated/. This can be quite helpful, e.g. a bug reporter can easily verify a bugfix by installing
a recent build.
Automated regression tests. In particular, the fuzz tests often indicate "real life" problems that are
otherwise hard to find.
Introduction
1.7.1. Website
You will find lots of useful information on the Wireshark homepage at https://www.wireshark.org/.
1.7.2. Wiki
The Wireshark Wiki at http://wiki.wireshark.org/ provides a wide range of information related to
Wireshark and packet capturing in general. You will find a lot of information not part of this
developers guide. For example, there is an explanation how to capture on a switched network, an
ongoing effort to build a protocol reference and a lot more.
And best of all, if you would like to contribute your knowledge on a specific topic (maybe a network
protocol you know well), you can edit the wiki pages by simply using your webbrowser.
Introduction
1.7.3. FAQ
The "Frequently Asked Questions" will list often asked questions and the corresponding answers.
Before sending any mail to the mailing lists below, be sure to read the FAQ, as it will often answer
any questions you might have. This will save yourself and others a lot of time. Keep in mind that a
lot of people are subscribed to the mailing lists.
You will find the FAQ inside Wireshark by clicking the menu item Help/Contents and selecting the
FAQ page in the upcoming dialog.
An online version is available at the Wireshark website: https://www.wireshark.org/faq.html. You
might prefer this online version as its typically more up to date and the HTML format is easier to use.
This mailing list will inform you about new program releases, which
usually appear about every 4-8 weeks.
wireshark-users
wireshark-dev
wireshark-bugs
This list is for Wireshark developers. Every time a change to the bug
database occurs, a mail to this mailing list is generated. If you want
to be notified about all the changes to the bug database, join this list.
Details about the bug database can be found in Section 1.7.6, Bug
database (Bugzilla).
wireshark-commits
This list is for Wireshark developers. Every time a change to the GIT
repository is checked in, a mail to this mailing list is generated. If you
want to be notified about all the changes to the GIT repository, join
Introduction
this list. Details about the GIT repository can be found in Section 3.2,
The Wireshark Git repository.
You can subscribe to each of these lists from the Wireshark web site: https://www.wireshark.org/lists/.
From there, you can choose which mailing list you want to subscribe to by clicking on the Subscribe/
Unsubscribe/Options button under the title of the relevant list. The links to the archives are included
on that page as well.
Introduction
Using GDB
Type the characters in the first line verbatim. Those are back-tics there.
backtrace is a gdb command. You should enter it verbatim after the first line shown
above, but it will not be echoed. The ^D (Control-D, that is, press the Control key and
the D key together) will cause gdb to exit. This will leave you with a file called bt.txt in
the current directory. Include the file with your bug report.
If you do not have gdb available, you will have to check out your operating systems
debugger.
You should mail the traceback to the wireshark-dev mailing list, or attach it to your bug report.
Warning
Unless you know exactly what you are doing, you should strictly follow the
recommendations below.
Quick Setup
In case the install of the SDK fails go to software management and remove the VC++ 2010 runtime
and redist packages (dont worry, they will be added back via the service pack later). If installation
of the SDK still fails, there may be a permission problem. See here for a solution.
2. C compiler service pack: Download and install "Microsoft Visual Studio 2010 Service Pack 1."
This is a very large download.
3. Microsoft Visual C++ 2010 Service Pack 1 Compiler Update for the Windows SDK 7.1, if you
want to build 64-bit binaries for Windows 7: Download and install "Microsoft Visual C++ 2010
Service Pack 1 Compiler Update for the Windows SDK 7.1."
4. If you will be building 64-bit binaries those items must be installed in that order as installing the
Microsoft Visual Studio 2010 Service Pack 1 can, if youve installed the Microsoft Windows SDK
for Windows 7, remove the 64-bit compilers, as per http://support.microsoft.com/?kbid=2519277
the Microsoft Knowledge Base article "FIX: Visual C++ compilers are removed when you upgrade
Visual Studio 2010 Professional or Visual Studio 2010 Express to Visual Studio 2010 SP1 if
Windows SDK v7.1 is installed". The release notes for the Microsoft Visual C++ 2010 Service Pack
1 Compiler Update for the Windows SDK 7.1 say that, to ensure that your system has a supported
configuration, you must install the items in the order specified above. If you have Microsoft Update
installed, so that the Windows update process will update software other than components of
Windows, and thus will update Visual Studio, you may need to disable it until after all of the above
are installed, to make sure it doesnt install Visual Studio 2010 SP1 out of order.
2.2.2. Install Qt
The main Wireshark application uses the Qt windowing toolkit. To install Qt download the Online
Installer from the Qt Project download page and select a component that matches your target system
and compiler. For example, the msvc2013 64-bit OpenGL component is used to build the official
64-bit packages.
Note that the Qt package also includes the Qt Creator IDE, which is useful for designing graphical
components and includes an interactive debugger. Youll need to build Wireshark using nmake before
youll be able to build the Wireshark project (uiqtWireshark.pro), however.
You can also use Chocolatey to install Qt (there are packages for x86 & x64 and various MSVC
compilers, e.g.
PS$>cinst qt-sdk-windows-x86-msvc2013_opengl
11
Quick Setup
asciidoc
You might also have to install
Interpreters/m4
if installing Devel/bison doesnt provide a working version of Bison. If m4 is missing bison will fail.
After clicking the Next button several times, the setup will then download and install the selected
packages (this may take a while).
Why is this recommended? Cygwins bash version is required, as no native Win32 version is available.
As additional packages can easily be added, Perl and other packages are also used.
12
Quick Setup
2.2.7.3. TortoiseGit
TortoiseGit is a native Windows graphical Git similar to TortoiseSVN. You can download the installer
from http://code.google.com/p/tortoisegit/.
2.2.7.5. Others
A list of other GUI interfaces for Git can be found at http://git-scm.com/downloads/guis
13
Quick Setup
set
set
set
set
CYGWIN=nodosfilewarning
WIRESHARK_BASE_DIR=C:\Development
WIRESHARK_TARGET_PLATFORM=win32 or win64 as required
QT5_BASE_DIR=C:\Qt\Qt5.3.0\5.3\msvc2013
If you are using a version of Visual Studio earlier than VS2012 then you must set an additional env
var, e.g. for VS2010 set the following:
> set VisualStudioVersion=10.0
Setting these variables could be added to a batch file to be run after you open the Visual Studio
Tools Command Prompt.
2. Change to the correct source directory
> cd C:\Development\wireshark
Dependencies ahead
You will need the Wireshark sources and some tools (nmake, bash) installed, before this
verification is able to work.
Enter at the Visual Studio Command prompt line:
> nmake -f Makefile.nmake verify_tools
This will check for the various tools needed to build Wireshark:
Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation. All rights reserved.
14
Quick Setup
wget: /usr/bin/wget
The "ERROR" at the start occurs because you havent yet downloaded the third party libraries and it
can be ignored at this stage. If you have problems with all the first three items (cl, link, nmake), check
that you opened a Visual Studio Command Prompt Section 2.2.9, Open a Visual Studio Command
Prompt.
Unfortunately, the link command is defined both in Cygwin and in MSVC, each with completely
different functionality. Youll need the MSVC link. If your link command looks something like: /
usr/bin/link the link command of Cygwin takes precedence over the MSVC one. To fix this, you
can change your PATH environment setting or simply rename link.exe in Cygwin. If you rename
it, make sure to remember that a Cygwin update may provide a new version of it.
Make sure that the other tools found are the Cygwin versions. Some build problems have been caused
by incompatible versions of grep and unzip provided by other installed applications.
to download and install libraries using wget. This may take a while.
3. If the download fails you may be behind a restrictive firewall. See the proxy comment in
Section 4.17, Windows: GNU wget (optional).
Note that 32-bit versions of the software require 32-bit versions of the libraries and that 64-bit versions
require 64-bit libraries. The build process creates independent directories for each as needed. See
Section 2.2.9, Open a Visual Studio Command Promptfor how to open the required Visual Studio
Command Prompt and WIRESHARK_TARGET_PLATFORM to select either a 32- or 64-bit build.
to build Wireshark.
3. Wait for Wireshark to compile. This will take a while, and there will be a lot of text output in the
command prompt window
4. For the QT version run C:\Development\wireshark\wireshark-qt-release
\Wireshark.exe and make sure it starts.
5. For the older GTK version
gtk2\Wireshark-gtk.exe.
run
C:\Development\wireshark\wireshark-
6. Open Help # About. If it shows your "private" program version, e.g.: Version 1.99.x-myprotocol123
congratulations! You have compiled your own version of Wireshark!
Tip
If compilation fails for suspicious reasons after you changed some source files try to
"distclean" the sources and make "all" again
15
Quick Setup
> C:\Development\wireshark\packaging\nsis\wireshark-win32-wireshark-major-minor-version:[].x-mypr
to test your new installer. Its a good idea to test on a different machine than the developer machine.
Note that if youve built an x64 version, the installer will be named accordingly.
16
17
https://code.wireshark.org/review/gitweb?p=wireshark.git;a=tree
You can also view commit logs, branches, tags, and past revisions:
https://code.wireshark.org/review/gitweb?p=wireshark.git
Like most revision control systems, Git uses branching to manange different copies of the source code
and allow parallel development. Wireshark uses the following branches for official releases:
master: Main feature development and odd-numbered "feature" releases.
master-x.y: Stable release maintenance. For example, master-1.10 is used to manage the 1.10.x
official releases.
18
2. Under Profile set a username. This will be the username that you use for SSH access. For the steps
below well assume that your username is henry.perry.
3. Select SSH Public Keys and add one or more keys. You will typically upload a key for each
computer that you use.
4. Install git-review. This is an installable package in many Linux distributions. You can also install
it as a Python package. (This step isnt strictly necessary but it makes working with Gerrit much
easier.)
5. Now on to the command line. First, make sure git works:
$ git --version
6. If this is your first time using Git, make sure your username and email address are configured. This
is particularly important if you plan on uploading changes.
$ git config --global user.name "Henry Perry"
$ git config --global user.email [email protected]
The checkout only has to be done once. This will copy all the sources of the latest version (including
directories) from the server to your machine. This may take some time depending on the speed of
your internet connection.
8. Then set up the git pre-commit hook and the push address:
$ cd wireshark
$ cp tools/pre-commit .git/hooks/
$ git config --add remote.origin.push HEAD:refs/for/master
This will run a few basic checks on commit to make sure that the code does not contain trivial
errors. It will also warn if it is out of sync with its master copy in the tools/ directory. The change
in the push address is necessary: We have an asymmetric process for pulling and pushing because
of gerrit.
9. Initialize git-review.
$ git review -s
This prepares your local repository for use with Gerrit, including installing the commit-msg hook
script.
19
The buildbot server will automatically start to generate a snapshot of Wiresharks source tree after
a source code change is committed. These snapshots can be found at https://www.wireshark.org/
download.htmlautomated/src/.
If Git access isnt possible, e.g. if the connection to the server isnt possible because of a corporate
firewall, the sources can be obtained by downloading the buildbot snapshots. However, if you are
going to maintain your sources in parallel to the "official" sources for some time, its recommended to
use the anonymous (or authenticated) Git access if possible (believe it, it will save you a lot of time).
Depending on your preferences and work habits you might want to run git pull --rebase or
git checkout -b my-topic-branch origin/master instead.
Fetching should only take a few seconds, even on a slow internet connection. It will update your local
repository history with changes from the official repository. If you and someone else have changed
the same file since the last update, Git will try to merge the changes into your private file (this works
remarkably well).
20
If you havent changed anything in the sources, you could simply throw away your old sources and
reinstall everything just like the first time. But be sure, that you really havent changed anything. It
might be a good idea to simply rename the "old" dir to have it around, just in case you remember later
that you really did change something before.
If you have changed your source tree, you have to merge the official changes since the last update into
your source tree. You will install the content of the .tar.bz2 file into a new directory and use a
good merge tool (e.g. http://winmerge.sourceforge.net/for Win32) to bring your personal source tree
in sync with the official sources again.
This method can be problematic and can be much more difficult and error-prone than using Git.
21
3.6.1. Unix/Linux
After a successful build you can run Wireshark right from the build directory. Still the program would
need to know that its being run from the build directory and not from its install location. This has
inpact on the directories where the program can find the other parts and relevant data files.
In order to run the Wireshark from the build directory set the environment variable
WIRESHARK_RUN_FROM_BUILD_DIRECTORY and run Wireshark. If your platform is properly
setup, your build directory and current working directory are not in your PATH, so the commandline
to launch Wireshark would be:
$ WIRESHARK_RUN_FROM_BUILD_DIRECTORY=1 ./wireshark
Theres no need to run Wireshark as root user, you just wont be able to capture. When you opt to run
Wireshark this way, your terminal output can be informative when things dont work as expected.
If you prefer a graphic debugger you can use the Data Display Debugger (ddd) instead of GNU
debugger (gdb).
Additional traps can be set on GLib by setting the G_DEBUG environment variable:
$ G_DEBUG=fatal_criticals libtool --mode=execute ddd wireshark
22
See http://library.gnome.org/devel/glib/stable/glib-running.html
23
Please remember
Wireshark is a volunteer effort. You arent paying to have your code reviewed and
integrated.
24
Fuzz test your changes! Fuzz testing is a very effective way to automatically find a lot of dissector
related bugs. Youll take a capture file containing packets affecting your dissector and the fuzz
test will randomly change bytes in this file, so that unusual code paths in your dissector are
checked. There are tools available to automatically do this on any number of input files, see: http:
//wiki.wireshark.org/FuzzTesting for details.
If you have git-review installed you can upload the change with a lot less typing:
# Note: The "-f" flag deletes your current branch.
$ git review -f
You can push using any Git client. Many clients have support for Gerrit, either built in or via an
additional module.
You might get one of the following responses to your patch request:
Your patch is checked into the repository. Congratulations!
You are asked to provide additional information, capture files, or other material. If you havent
fuzzed your code, you may be asked to do so.
Your patch is rejected. You should get a response with the reason for rejection. Common reasons
include not following the style guide, buggy or insecure code, and code that wont compile on other
platforms. In each case youll have to fix each problem and upload another patch.
You dont get any response to your patch. Possible reason: All the core developers are busy (e.g.,
with their day jobs or family or other commitments) and havent had time to look at your patch.
Dont worry, if your patch is in the review system it wont get lost.
If youre concerned, feel free to add a comment to the patch or send an email to the developers list
asking for status. But please be patient: most if not all of us do this in our spare time.
25
If you want to cherry-pick a Gerrit change ID (e.g. I5e6f7890) you can use git review -X
I5e6f7890 instead of git cherry-pick and git review instead of git push as described
in the previous chapter.
If theyre relative to a higher-level directory, youd replace 0 with the number of higher-level
directories in the path, e.g. if the names are wireshark.orig/prefs.c and wireshark.mine/prefs.c, youd
run it with:
$ patch -p1 < new.diff
If theyre relative to a subdirectory of the top-level directory, youd run patch in that directory and
run it with -p0.
If you run it without -pat all, the patch tool flattens path names, so that if you have a patch file
with patches to Makefile.am and wiretap/Makefile.am, itll try to apply the first patch to the top-level
Makefile.am and then apply the wiretap/Makefile.am patch to the top-level Makefile.am as well.
At which position in the filesystem should the patch tool be called?
If the pathnames are relative to the top-level source directory, or to a directory above that directory,
youd run it in the top-level source directory.
If theyre relative to a subdirectory for example, if somebody did a patch to packet-ip.c and ran
diff or git diff in the epan/dissectors directory youd run it in that subdirectory. It is preferred
that people not submit patches like that, especially if theyre only patching files that exist in multiple
directories such as Makefile.am.
26
to build the RPM and source RPM. Once it is done, there will be a message stating where the built
RPM can be found.
27
28
4.3. Chocolatey
Chocolatey is a Windows package manager that can be used to install (and update) many of the
packages required for Wireshark development. Chocolatey can be obtained from the website or from
a DOS command prompt:
or a Powershell prompt:
PS:\>iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
29
Tool Reference
30
Tool Reference
31
Tool Reference
32
Tool Reference
Yes
Purchase required?
Free Download
No
config.nmake MSVC_VARIANT
MSVC2013
Yes
Purchase required?
Free Download
Yes.
config.nmake MSVC_VARIANT
MSVC2010EE
Remarks
Yes
Purchase required?
Yes
No
config.nmake MSVC_VARIANT
MSVC2010
Remarks
cl.exe
_MSC_VER
CRT DLL
12.0
1800
msvcr120.dll
10.0
1600
msvcr100.dll
After correct installation of the toolchain, typing at the Visual Studio Command line prompt (cmd.exe):
> cl
33
Tool Reference
34
Tool Reference
the compiler setup installs these files so they are available - but they might not be available on a user
machine!
This is especially true for the C runtime DLL (msvcr*.dll), which contains the implementation of ANSI
and alike functions, e.g.: fopen(), malloc(). The DLL is named like: msvcrversion'.dll, an abbreviation
for "MicroSoft Visual C Runtime". For Wireshark to work, this DLL must be available on the users
machine.
Starting with MSVC7, it is necessary to ship the C runtime DLL (msvcrversion'.dll) together with the
application installer somehow, as that DLL is possibly not available on the target system.
35
Tool Reference
4.6.8. Debugger
Using a good debugger can save you a lot of development time.
The debugger you use must match the C compiler Wireshark was compiled with, otherwise the
debugger will simply fail or you will only see a lot of garbage.
To debug Wireshark using WinDbg, open the built copy of Wireshark using the File Open
Executable menu, i.e. C:\Development\Wireshark\wireshark-qt-release\Wireshark.exe. To set a
36
Tool Reference
breakpoint open the required source file using the File Open Source File menu and then click on
the required line and press F9. To run the program, press F5.
4.7. bash
The bash shell is needed to run several shell scripts.
4.8. Python
Python is an interpreted programming language. The homepage of the Python project is http://
python.org/. It is used to generate some source files. Python 2.5 or later (including Python 3) should
work fine but Python 2.7 is recommended.
Python is either included or available as a package on most UNIX-like platforms. Windows
packages and source are available at http://python.org/download/. The Cygwin Python package is
not recommended since /usr/bin/python is a symbolic link, which causes confusion outside
Cygwin.
You can also use Chocolatey to install Python:
PS:\> cinst Python2
37
Tool Reference
4.9. Perl
Perl is an interpreted programming language. The homepage of the Perl project is http://
www.perl.com. Perl is used to convert various text files into usable source code. Perl version 5.6 and
above should work fine.
or
PS:\> cinst StrawberryPerl
38
Tool Reference
4.10. sed
Sed it the streaming editor. It makes it easy for example to replace text inside a source code file. The
Wireshark build process uses this to stamp version strings in various places.
4.11. Bison
Bison is a parser generator used for some of Wiresharks file format support.
39
Tool Reference
Native packages are available from other sources such as GnuWin. They arent officially supported
but should work.
4.12. Flex
Flex is a lexical analyzer generator used for Wiresharks display filters, some file formats, and other
features.
Native packages are available from other sources such as GnuWin. They arent officially supported
but should work.
40
Tool Reference
$ git --version
41
Tool Reference
patch 2.5.8
Copyright (C) 1988 Larry Wall
Copyright (C) 2002 Free Software Foundation, Inc.
This program comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of this program
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
written by Larry Wall and Paul Eggert
You will only need wget, if you want to use the Windows automated library download, see Section 5.3,
Win32: Automated library downloadfor details.
If GNU wget isnt already installed or available as a package for your platform (well, for Windows it
is available as a Cygwin package), you can get it at http://www.gnu.org/software/wget/wget.html.
If wget is trying to download files but fails to do so, your Internet connection might use an HTTP
proxy. Some Internet providers use such a proxy and it is common in many company networks today.
Wiresharks setup script will try to discover your proxy settings automatically, but you may need to set
the environment variable HTTP_PROXY by hand before using wget. For example, if you are behind
proxy.com which is listening on port 8080, you have to set it to something like:
set HTTP_PROXY=http://proxy.com:8080/
If you are unsure about the settings, you might ask your system administrator.
42
Tool Reference
To install it, simply download the latest released version (currently 2.46) from http://
nsis.sourceforge.net and start the downloaded installer. You will need NSIS version 2. Version 3 is
not yet supported.
You can find more instructions on using NSIS in Section 3.11.4, Win32: NSIS .exe installer.
43
5.2.1. Unix
If you have installed unix binary libraries on your system, they will match the C compiler. If not
already installed, the libraries should be available as a package from the platform installer, or you can
download and compile the source and then install the binaries.
44
Library Reference
By default the libraries will be downloaded and installed into C:\wireshark-win32-libs for x86 builds
and C:\wireshark-win64-libs for x86_64 builds. You can change this to any other location by editing
config.nmake and changing the line containing WIRESHARK_LIB_DIR to your favourite place. You
must use an absolute path.
Then run the command
> nmake -f Makefile.nmake setup
This will first check for all the various tools needed to build Wireshark as described in Section 2.2.10,
Verify installed tools.
Then it will download the zipped libraries (together around 45MB for x86 and 52MB for x64)
from the server location at http://anonsvn.wireshark.org/wireshark-win32-libs/trunk/packages/ into
the directory specified by WIRESHARK_LIB_DIR and install (unzip) all required library files there.
If you have problems downloading the library files, you might be connected to the internet through a
proxy. In this case see the wget proxy comment in Section 4.17, Windows: GNU wget (optional).
Note that this command will automatically do a clean-setup which will remove all files
previously unzipped from the downloaded files in your WIRESHARK_LIB_DIR library path (all
the subdirs, e.g. c:\wireshark-win32-libs\gtk+), except for the zip files located at the toplevel, which
are the files downloaded the last time(s).
Also note that as wget will download only the missing (updated) files, existing zip files in the
WIRESHARK_LIB_DIR dir wont be downloaded again. Remaining (outdated) zip files shouldnt
do any harm.
45
Library Reference
5.4.1. Unix
The GLib/GTK+ libraries are available for many unix-like platforms and Cygwin.
If these libraries arent already installed and also arent available as a package for your platform, you
can get them at http://www.gtk.org/download.html.
5.5.1. Unix
If this library isnt already installed or available as a package for your platform, you can get it at http:
//www.ibr.cs.tu-bs.de/projects/libsmi/.
5.6.1. Unix
If this library isnt already installed or available as a package for your platform, you can get it at http:
//c-ares.haxx.se/.
5.7.1. Unix
This library is almost certain to be installed on your system. If it isnt or you dont want to use the
default library you can download it from http://www.zlib.net/.
46
Library Reference
5.9.1. Unix
If this library isnt already installed or available as a package for your platform, you can get it at http:
//www.gnu.org/software/gnutls/download.html.
5.10.1. Unix
If this library isnt already installed or available as a package for your platform, you can get it at http:
//directory.fsf.org/security/libgcrypt.html.
47
Library Reference
5.11.1. Unix
If this library isnt already installed or available as a package for your platform, you can get it at http:
//web.mit.edu/Kerberos/dist/.
5.12.1. Unix
If this library isnt already installed or available as a package for your platform, you can get it at http:
//www.lua.org/download.html.
5.13.1. Unix
If this library isnt already installed or available as a package for your platform, you can get it at http:
//www.portaudio.com/download.html.
5.14.1. Unix
If this library isnt already installed or available as a package for your platform, you can get it at http:
//www.maxmind.com/app/c.
48
6.2. Overview
The following will give you a simplified overview of Wiresharks function blocks:
This image is out of date. It is missing the utility library in wsutil and the Qt UI in ui/qt.
The function blocks in more detail: GTK+ 2:: Handling of all user input/output (all windows, dialogs
and such). Source code can be found in the ui/gtk directory.
Core
Main "glue code" that holds the other blocks together. Source code
can be found in the root directory.
Epan
50
The wiretap library is used to read and write capture files in libpcap,
pcapng, and many other file formats. Source code is in the wiretap
directory.
Capture
The interface with the capture engine. Source code is in the root
directory.
Dumpcap
The capture engine itself. This is the only part that is to execute with
elevated privileges. Source code is in the root directory.
These are separate libraries that provide packet capture and filtering
support on different platforms. The filtering WinPcap and libpcap
works at a much lower level than Wiresharks display filters and
uses a significantly different mechanism. Thats why we have
different display and capture filter syntaxes.
51
Chapter 7. Introduction
7.1. Source overview
Wireshark consists of the following major parts:
Packet dissection - in the /epan/dissector and /plugin/* directories
File I/O - using Wiresharks own wiretap library
Capture - using the libpcap/winpcap library, in /wiretap
User interface - using the Qt or GTK+ and associated libraries
Utilities - miscellaneous helper code
Help - using an external web browser and GTK text output
52
53
Read README.dissector
The file doc/README.dissector contains detailed information about implementing a
dissector. In many cases it is more up to date than this document.
54
Packet dissection
void
proto_register_foo(void)
{
proto_foo = proto_register_protocol (
"FOO Protocol", /* name
*/
"FOO",
/* short name */
"foo"
/* abbrev
*/
);
}
Lets go through this a bit at a time. First we have some boilerplate include files. These will be pretty
constant to start with.
Next we have an int that is initialised to -1 that records our protocol. This will get updated when we
register this dissector with the main program. Its good practice to make all variables and functions
that arent exported static to keep name space pollution down. Normally this isnt a problem unless
your dissector gets so big it has to span multiple files.
Then a #define for the UDP port that carries foo traffic.
Now that we have the basics in place to interact with the main program, well start with two protocol
dissector setup functions.
First well call proto_register_protocol() which registers the protocol. We can give it
three names that will be used for display in various places. The full and short name are used in e.g.
the "Preferences" and "Enabled protocols" dialogs as well as the generated field name list in the
documentation. The abbreviation is used as the display filter name.
Next we need a handoff routine.
Whats happening here? We are initialising the dissector. First we create a dissector handle; It is
associated with the foo protocol and with a routine to be called to do the actual dissecting. Then we
associate the handle with a UDP port number so that the main program will know to call us when it
gets UDP traffic on that port.
The stardard Wireshark dissector convention is to put proto_register_foo() and
proto_reg_handoff_foo() as the last two functions in the dissector source.
Now at last we get to write some dissecting code. For the moment well leave it as a basic placeholder.
This function is called to dissect the packets presented to it. The packet data is held in a special buffer
referenced here as tvb. We shall become fairly familiar with this as we get deeper into the details of
55
Packet dissection
the protocol. The packet info structure contains general data about the protocol, and we can update
information here. The tree parameter is where the detail dissection takes place.
For now well do the minimum we can get away with. In the first line we set the text of this to our
protocol, so everyone can see its being recognised. The only other thing we do is to clear out any data
in the INFO column if its being displayed.
At this point we should have a basic dissector ready to compile and install. It doesnt do much at
present, other than identify the protocol and label it.
In order to compile this dissector and create a plugin a couple of support files are required, besides
the dissector source in packet-foo.c:
Makefile.am - The UNIX/Linux makefile template.
Makefile.common - Contains the file names of this plugin.
Makefile.nmake - Contains the Wireshark plugin makefile for Windows.
moduleinfo.h - Contains plugin version information.
moduleinfo.nmake - Contains DLL version info for Windows.
packet-foo.c - Your dissector source.
plugin.rc.in - Contains the DLL resource template for Windows.
You can find a good example for these files in the interlink plugin directory. Makefile.common and
Makefile.am have to be modified to reflect the relevant files and dissector name. moduleinfo.h and
moduleinfo.nmake have to be filled in with the version information. Compile the dissector to a DLL
or shared library and copy it into the plugin directory of the installation.
What were doing here is adding a subtree to the dissection. This subtree will hold all the details of
this protocol and so not clutter up the display when not required.
56
Packet dissection
We are also marking the area of data that is being consumed by this protocol. In our case its all that
has been passed to us, as were assuming this protocol does not encapsulate another. Therefore, we
add the new tree node with proto_tree_add_item(), adding it to the passed in tree, label it with
the protocol, use the passed in tvb buffer as the data, and consume from 0 to the end (-1) of this data.
ENC_NA ("not applicable") is specified as the "encoding" parameter.
After this change, there should be a label in the detailed display for the protocol, and selecting this
will highlight the remaining contents of the packet.
Now lets go to the next step and add some protocol dissection. For this step well need
to construct a couple of tables that help with dissection. This needs some additions to the
proto_register_foo() function shown previously.
Two statically allocated arrays are added at the beginning of proto_register_foo(). The arrays
are then registered after the call to proto_register_protocol().
The variables hf_foo_pdu_type and ett_foo also need to be declared somewhere near the top
of the file.
57
Packet dissection
Now the dissection is starting to look more interesting. We have picked apart our first bit of the
protocol. One byte of data at the start of the packet that defines the packet type for foo protocol.
The proto_item_add_subtree() call has added a child node to the protocol tree which is
where we will do our detail dissection. The expansion of this node is controlled by the ett_foo
variable. This remembers if the node should be expanded or not as you move between packets.
All subsequent dissection will be added to this tree, as you can see from the next call. A call to
proto_tree_add_item() in the foo_tree, this time using the hf_foo_pdu_type to control
the formatting of the item. The pdu type is one byte of data, starting at 0. We assume it is in network
order (also called big endian), so that is why we use ENC_BIG_ENDIAN. For a 1-byte quantity, there
is no order issue, but it is good practice to make this the same as any multibyte fields that may be
present, and as we will see in the next section, this particular protocol uses network order.
If we look in detail at the hf_foo_pdu_type declaration in the static array we can see the details
of the definition.
hf_foo_pdu_type - The index for this node.
FOO PDU Type - The label for this item.
foo.type - This is the filter string. It enables us to type constructs such as foo.type=1 into the
filter box.
FT_UINT8 - This specifies this item is an 8bit unsigned integer. This tallies with our call above
where we tell it to only look at one byte.
BASE_DEC - Tor an integer type, this tells it to be printed as a decimal number. It could be
hexdecimal (BASE_HEX) or octal (BASE_OCT) if that made more sense.
Well ignore the rest of the structure for now.
If you install this plugin and try it out, youll see something that begins to look useful.
Now lets finish off dissecting the simple protocol. We need to add a few more variables to the hfarray,
and a couple more procedure calls.
58
Packet dissection
...
}
void
proto_register_foo(void) {
...
...
{ &hf_foo_flags,
{ "FOO PDU Flags", "foo.flags",
FT_UINT8, BASE_HEX,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_foo_sequenceno,
{ "FOO PDU Sequence Number", "foo.seqn",
FT_UINT16, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
},
{ &hf_foo_initialip,
{ "FOO PDU Initial IP", "foo.initialip",
FT_IPv4, BASE_NONE,
NULL, 0x0,
NULL, HFILL }
},
...
...
}
...
This dissects all the bits of this simple hypothetical protocol. Weve introduced a new variable
offsetinto the mix to help keep track of where we are in the packet dissection. With these extra bits
in place, the whole protocol is now dissected.
This is a handy data structure that can be used to look up a name for a value. There are routines to
directly access this lookup table, but we dont need to do that, as the support code already has that
added in. We just have to give these details to the appropriate part of the data, using the VALS macro.
This helps in deciphering the packets, and we can do a similar thing for the flags structure. For this
we need to add some more data to the table though.
59
Packet dissection
#define FOO_END_FLAG
#define FOO_PRIORITY_FLAG
0x02
0x04
Some things to note here. For the flags, as each bit is a different flag, we use the type FT_BOOLEAN,
as the flag is either on or off. Second, we include the flag mask in the 7th field of the data, which
allows the system to mask the relevant bit. Weve also changed the 5th field to 8, to indicate that we
are looking at an 8 bit quantity when the flags are extracted. Then finally we add the extra constructs
to the dissection routine. Note we keep the same offset for each of the flags.
This is starting to look fairly full featured now, but there are a couple of other things we can do to make
things look even more pretty. At the moment our dissection shows the packets as "Foo Protocol" which
whilst correct is a little uninformative. We can enhance this by adding a little more detail. First, lets get
hold of the actual value of the protocol type. We can use the handy function tvb_get_guint8()
to do this. With this value in hand, there are a couple of things we can do. First we can set the INFO
column of the non-detailed view to show what sort of PDU it is - which is extremely helpful when
looking at protocol traces. Second, we can also display this information in the dissection window.
60
Packet dissection
So here, after grabbing the value of the first 8 bits, we use it with one of the built-in utility routines
val_to_str(), to lookup the value. If the value isnt found we provide a fallback which just prints
the value in hex. We use this twice, once in the INFO field of the columns if its displayed, and
similarly we append this data to the base of our dissecting tree.
The first steps here are to recognise the compression. In this case a flag byte alerts us to the fact the
remainder of the packet is compressed. Next we retrieve the original size of the packet, which in this
case is conveniently within the protocol. If its not, it may be part of the compression routine to work
it out for you, in which case the logic would be different.
So armed with the size, a buffer is allocated to receive the uncompressed data using g_malloc(),
and the packet is decompressed into it. The tvb_get_ptr() function is useful to get a pointer to
61
Packet dissection
the raw data of the packet from the offset onwards. In this case the decompression routine also needs
to know the length, which is given by the tvb_length_remaining() function.
Next we build a new tvb buffer from this data, using the tvb_new_child_real_data() call.
This data is a child of our original data, so calling this function also acknowledges that. One
procedural step is to add a callback handler to free the data when its no longer needed via a call to
tvb_set_free_cb(). In this case g_malloc() was used to allocate the memory, so g_free()
is the appropriate callback function. Finally we add this tvb as a new data source, so that the detailed
display can show the decompressed bytes as well as the original.
After this has been set up the remainder of the dissector can dissect the buffer next_tvb, as its a new
buffer the offset needs to be 0 as we start again from the beginning of this buffer. To make the rest of
the dissector work regardless of whether compression was involved or not, in the case that compression
was not signaled, we use tvb_new_subset_remaining() to deliver us a new buffer based on
the old one but starting at the current offset, and extending to the end. This makes dissecting the packet
from this point on exactly the same regardless of compression.
62
Packet dissection
pinfo->fragmented = TRUE;
frag_msg = fragment_add_seq_check(tvb, offset, pinfo,
msg_seqid, /* ID for fragments belonging together */
msg_fragment_table, /* list of message fragments */
msg_reassembled_table, /* list of reassembled messages */
msg_num, /* fragment sequence number */
tvb_length_remaining(tvb, offset), /* fragment length - to the end */
flags & FL_FRAG_LAST); /* More fragments? */
We start by saving the fragmented state of this packet, so we can restore it later. Next comes some
protocol specific stuff, to dig the fragment data out of the stream if its present. Having decided it is
present, we let the function fragment_add_seq_check() do its work. We need to provide this
with a certain amount of data.
The tvb buffer we are dissecting.
The offset where the partial packet starts.
The provided packet info.
The sequence number of the fragment stream. There may be several streams of fragments in flight,
and this is used to key the relevant one to be used for reassembly.
The msg_fragment_table and the msg_reassembled_table are variables we need to
declare. Well consider these in detail later.
msg_num is the packet number within the sequence.
The length here is specified as the rest of the tvb as we want the rest of the packet data.
Finally a parameter that signals if this is the last fragment or not. This might be a flag as in this
case, or there may be a counter in the protocol.
Having passed the fragment data to the reassembly handler, we can now check if we have the whole
message. If there is enough information, this routine will return the newly reassembled data buffer.
After that, we add a couple of informative messages to the display to show that this is part of a sequence.
Then a bit of manipulation of the buffers and the dissection can proceed. Normally you will probably
not bother dissecting further unless the fragments have been reassembled as there wont be much to
find. Sometimes the first packet in the sequence can be partially decoded though if you wish.
63
Packet dissection
First a couple of hash tables are declared, and these are initialised in the protocol initialisation routine.
Following that, a fragment_items structure is allocated and filled in with a series of ett items, hf
data items, and a string tag. The ett and hf values should be included in the relevant tables like all the
other variables your protocol may use. The hf variables need to be placed in the structure something
like the following. Of course the names may need to be adjusted.
64
Packet dissection
{&hf_msg_fragment_overlap_conflicts,
{"Message fragment overlapping with conflicting data",
"msg.fragment.overlap.conflicts",
FT_BOOLEAN, 0, NULL, 0x00, NULL, HFILL } },
{&hf_msg_fragment_multiple_tails,
{"Message has multiple tail fragments",
"msg.fragment.multiple_tails",
FT_BOOLEAN, 0, NULL, 0x00, NULL, HFILL } },
{&hf_msg_fragment_too_long_fragment,
{"Message fragment too long", "msg.fragment.too_long_fragment",
FT_BOOLEAN, 0, NULL, 0x00, NULL, HFILL } },
{&hf_msg_fragment_error,
{"Message defragmentation error", "msg.fragment.error",
FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } },
{&hf_msg_fragment_count,
{"Message fragment count", "msg.fragment.count",
FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL } },
{&hf_msg_reassembled_in,
{"Reassembled in", "msg.reassembled.in",
FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL } },
{&hf_msg_reassembled_length,
{"Reassembled length", "msg.reassembled.length",
FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL } },
...
static gint *ett[] =
{
...
&ett_msg_fragment,
&ett_msg_fragments
...
These hf variables are used internally within the reassembly routines to make useful links, and to add
data to the dissection. It produces links from one packet to another, such as a partial packet having a
link to the fully reassembled packet. Likewise there are back pointers to the individual packets from
the reassembled one. The other variables are used for flagging up errors.
65
Packet dissection
As you can see this is really simple. Just call tcp_dissect_pdus() in your main dissection
routine and move you message parsing code into another function. This function gets called whenever
a message has been reassembled.
The parameters tvb, pinfo, treeand dataare just handed over to tcp_dissect_pdus(). The 4th
parameter is a flag to indicate if the data should be reassembled or not. This could be set according
to a dissector preference as well. Parameter 5 indicates how much data has at least to be available to
be able to determine the length of the foo message. Parameter 6 is a function pointer to a method that
returns this length. It gets called when at least the number of bytes given in the previous parameter is
available. Parameter 7 is a function pointer to your real message dissector. Parameter 8 is a the data
passed in from parent dissector.
Whilst you can program a tap without protocol specific data, it is generally not very useful. Therefore
its a good idea to declare a structure that can be passed through the tap. This needs to be a static
66
Packet dissection
structure as it will be used after the dissection routine has returned. Its generally best to pick out some
generic parts of the protocol you are dissecting into the tap data. A packet type, a priority or a status
code maybe. The structure really needs to be included in a header file so that it can be included by
other components that want to listen in to the tap.
Once you have these defined, its simply a case of populating the protocol specific structure and then
calling tap_queue_packet, probably as the last part of the dissector.
This now enables those interested parties to listen in on the details of this protocol conversation.
Working from the bottom up, first the plugin interface entry point is defined,
plugin_register_tap_listener(). This simply calls the initialisation function
register_foo_stat_trees().
This in turn calls the stats_tree_register() function, which takes three strings, and three
functions.
1. This is the tap name that is registered.
2. An abbreviation of the stats name.
3. The name of the stats module. A '/' character can be used to make sub menus.
4. The function that will called to generate the stats.
67
Packet dissection
In this case we create a new tree node, to handle the total packets, and as a child of that we create a
pivot table to handle the stats about different packet types.
static int foo_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t* edt, const void
{
struct FooTap *pi = (struct FooTap *)p;
tick_stat_node(st, st_str_packets, 0, FALSE);
stats_tree_tick_pivot(st, st_node_packet_types,
val_to_str(pi->packet_type, msgtypevalues, "Unknown packet type (%d)"));
return 1;
}
In this case the processing of the stats is quite simple. First we call the tick_stat_node for the
st_str_packets packet node, to count packets. Then a call to stats_tree_tick_pivot()
on the st_node_packet_types subtree allows us to record statistics by packet type.
This document
68
Packet dissection
wireshark_be.py
wireshark_gen.py
idl2wrs
A simple shell script wrapper that the end user should use to generate
the dissector from the IDL file(s).
e.g.:
$ idl2wrs echo.idl
You may wish to comment out the register_giop_user_module() code and that will leave you with
heuristic dissection.
If you dont want to use the shell script wrapper, then try steps 3 or 4 instead.
To write the C code to stdout.
$ omniidl
e.g.:
$ omniidl
-p ./ -b wireshark_be echo.idl
You may wish to comment out the register_giop_user_module() code and that will leave you with
heuristic dissection.
69
Packet dissection
Copy the resulting C code to subdirectory epan/dissectors/ inside your Wireshark source directory.
$ cp packet-test-idl.c /dir/where/wireshark/lives/epan/dissectors/
The new dissector has to be added to Makefile.common in the same directory. Look for the
declaration CLEAN_DISSECTOR_SRC and add the new dissector there. For example,
CLEAN_DISSECTOR_SRC = \
packet-2dparityfec.c
packet-3com-njack.c
...
\
\
becomes
CLEAN_DISSECTOR_SRC = \
packet-test-idl.c
packet-2dparityfec.c
packet-3com-njack.c
...
\
\
\
For the next steps, go up to the top of your Wireshark source directory.
Run configure
$ ./configure (or ./autogen.sh)
Good Luck !!
9.8.4. TODO
Exception code not generated (yet), but can be added manually.
Enums not converted to symbolic values (yet), but can be added manually.
Add command line options etc
More I am sure :-)
9.8.5. Limitations
See the TODO list inside packet-giop.c
9.8.6. Notes
The -p ./ option passed to omniidl indicates that the wireshark_be.py and wireshark_gen.py are
residing in the current directory. This may need tweaking if you place these files somewhere else.
If it complains about being unable to find some modules (e.g. tempfile.py), you may want to check if
PYTHONPATH is set correctly. On my Linux box, it is PYTHONPATH=/usr/lib/python2.4/
70
71
local t = root:add(p_multi,buf(0,2))
t:add(f_proto,buf(0,1))
t:add(f_dir,buf(1,1))
local proto_id = buf(0,1):uint()
local dissector = protos[proto_id]
if dissector ~= nil then
dissector:call(buf(2):tvb(),pkt,root)
elseif proto_id < 2 then
t:add(f_text,buf(2))
-- pkt.cols.info:set(buf(2,buf:len() - 3):string())
else
data_dis:call(buf(2):tvb(),pkt,root)
end
end
local wtap_encap_table = DissectorTable.get("wtap_encap")
local udp_encap_table = DissectorTable.get("udp.port")
wtap_encap_table:add(wtap.USER15,p_multi)
wtap_encap_table:add(wtap.USER12,p_multi)
udp_encap_table:add(7555,p_multi)
72
ips = {}
end
end
-- using this function we register our function
-- to be called when the user selects the Tools->Test->Packets menu
register_menu("Test/Packets", menuable_tap, MENU_TOOLS_UNSORTED)
10.5.1. Dumper
10.5.1.1. Dumper.new(filename, [filetype], [encap])
Creates a file to write packets. Dumper:new_for_current() will probably be a better choice.
Arguments
filename
filetype (optional)
encap (optional)
Returns
The newly created Dumper object
10.5.1.2. dumper:close()
Closes a dumper.
Errors
Cannot operate on a closed dumper
10.5.1.3. dumper:flush()
Writes all unsaved data of a dumper to the disk.
73
Note
Dumper:dump_current() will fit best in most cases.
Arguments
timestamp
pseudoheader
bytearray
10.5.1.5. dumper:new_for_current([filetype])
Creates a capture file using the same encapsulation as the one of the current packet.
Arguments
filetype (optional)
Returns
The newly created Dumper Object
Errors
Cannot be used outside a tap or a dissector
10.5.1.6. dumper:dump_current()
Dumps the current packet as it is.
Errors
Cannot be used outside a tap or a dissector
10.5.2. PseudoHeader
A pseudoheader to be used to save captured frames.
10.5.2.1. PseudoHeader.none()
Creates a "no" pseudoheader.
Returns
A null pseudoheader
10.5.2.2. PseudoHeader.eth([fcslen])
Creates an ethernet pseudoheader.
Arguments
fcslen (optional)
Returns
The ethernet pseudoheader
74
Arguments
aal (optional)
AAL number
vpi (optional)
VPI
vci (optional)
VCI
channel (optional)
Channel
cells (optional)
aal5u2u (optional)
aal5len (optional)
AAL5 Len
Returns
The ATM pseudoheader
Arguments
sent (optional)
annexa (optional)
linknum (optional)
Link Number.
Returns
The MTP2 pseudoheader
10.6.1.1. Field.new(fieldname)
Create a Field extractor.
Arguments
fieldname
75
Returns
The field extractor
Errors
A Field extractor must be defined before Taps or Dissectors get called
10.6.1.2. Field.list()
Gets a Lua array table of all registered field filter names.
Note
this is an expensive operation, and should only be used for troubleshooting.
Since: 1.11.3
Returns
The array table of field filter names
10.6.1.3. field:__call()
Obtain all values (see FieldInfo) for this field.
Returns
All the values of this field
Errors
Fields cannot be used outside dissectors or taps
10.6.1.4. field:__tostring()
Obtain a string with the field name.
10.6.2. FieldInfo
An extracted Field from dissected packet data. A FieldInfo object can only be used within the
callback functions of dissectors, post-dissectors, heuristic-dissectors, and taps.
A FieldInfo can be called on either existing Wireshark fields by using either Field.new() or
Field() before-hand, or it can be called on new fields created by Lua from a ProtoField.
10.6.2.1. fieldinfo:__len()
Obtain the Length of the field
10.6.2.2. fieldinfo:__unm()
Obtain the Offset of the field
10.6.2.3. fieldinfo:__call()
Obtain the Value of the field.
76
Previous to 1.11.4, this function retrieved the value for most field types, but for
ftypes.UINT_BYTES it retrieved the ByteArray of the fields entire TvbRange. In other
words, it returned a ByteArray that included the leading length byte(s), instead of just the value
bytes. That was a bug, and has been changed in 1.11.4. Furthermore, it retrieved an ftypes.GUID
as a ByteArray, which is also incorrect.
If you wish to still get a ByteArray of the TvbRange, use FieldInfo:get_range() to get
the TvbRange, and then use Tvb:bytes() to convert it to a ByteArray.
10.6.2.4. fieldinfo:__tostring()
The string representation of the field.
10.6.2.5. fieldinfo:__eq()
Checks whether lhs is within rhs.
10.6.2.6. fieldinfo:__le()
Checks whether the end byte of lhs is before the end of rhs.
Errors
Data source must be the same for both fields
10.6.2.7. fieldinfo:__lt()
Checks whether the end byte of rhs is before the beginning of rhs.
Errors
Data source must be the same for both fields
10.6.3. fieldinfo.len
Mode: Retrieve only.
The length of this field.
10.6.4. fieldinfo.offset
Mode: Retrieve only.
The offset of this field.
10.6.5. fieldinfo.value
Mode: Retrieve only.
The value of this field.
10.6.6. fieldinfo.label
Mode: Retrieve only.
The string representing this field
77
10.6.7. fieldinfo.display
Mode: Retrieve only.
The string display of this field as seen in GUI
10.6.8. fieldinfo.range
Mode: Retrieve only.
The TvbRange covering this field
10.6.9. fieldinfo.generated
Mode: Retrieve only.
Whether this field was marked as generated (boolean)
10.6.10. fieldinfo.name
Mode: Retrieve only.
The name of this field
Errors
Cannot be called outside a listener or dissector
Arguments
title (optional)
task (optional)
Returns
The newly created ProgDlg object.
78
Arguments
progress
task (optional)
Errors
GUI not available
Cannot be called for something not a ProgDlg
Progress value out of range (must be between 0.0 and 1.0)
10.7.1.3. progdlg:stopped()
Checks whether the user has pressed the stop button.
Returns
true if the user has asked to stop the progress.
10.7.1.4. progdlg:close()
Closes the progress dialog.
Returns
A string specifying whether the Progress Dialog has stopped or not.
Errors
GUI not available
10.7.2. TextWindow
Manages a text window.
10.7.2.1. TextWindow.new([title])
Creates a new TextWindow text window.
Arguments
title (optional)
Returns
The newly created TextWindow object.
Errors
GUI not available
79
10.7.2.2. textwindow:set_atclose(action)
Set the function that will be called when the text window closes.
Arguments
action
A Lua function to be executed when the user closes the text window.
Returns
The TextWindow object.
Errors
GUI not available
10.7.2.3. textwindow:set(text)
Sets the text.
Arguments
text
Returns
The TextWindow object.
Errors
GUI not available
10.7.2.4. textwindow:append(text)
Appends text
Arguments
text
Returns
The TextWindow object.
Errors
GUI not available
10.7.2.5. textwindow:prepend(text)
Prepends text
Arguments
text
Returns
The TextWindow object.
80
Errors
GUI not available
10.7.2.6. textwindow:clear()
Erases all text in the window.
Returns
The TextWindow object.
Errors
GUI not available
10.7.2.7. textwindow:get_text()
Get the text of the window
Returns
The `TextWindows text.
Errors
GUI not available
10.7.2.8. textwindow:set_editable([editable])
Make this text window editable.
Arguments
editable (optional)
Returns
The TextWindow object.
Errors
GUI not available
Arguments
label
function
Returns
The TextWindow object.
Errors
GUI not available
81
Returns
A boolean: true if it is enabled, false if it isnt.
Arguments
name
The name of the menu item. The submenus are to be separated by '`/s.
(string)
action
group (optional)
The menu group into which the menu item is to be inserted. If omitted,
defaults to MENU_STAT_GENERIC. One of:
MENU_STAT_UNSORTED (Statistics),
MENU_STAT_GENERIC (Statistics, first section),
MENU_STAT_CONVERSATION (Statistics/Conversation List),
MENU_STAT_ENDPOINT (Statistics/Endpoint List),
MENU_STAT_RESPONSE (Statistics/Service Response Time),
MENU_STAT_TELEPHONY (Telephony),
MENU_STAT_TELEPHONY_GSM (Telephony/GSM),
MENU_STAT_TELEPHONY_LTE (Telephony/LTE),
MENU_STAT_TELEPHONY_SCTP (Telephony/SCTP),
MENU_ANALYZE (Analyze),
MENU_ANALYZE_CONVERSATION
Filter),
(Analyze/Conversation
Arguments
title
action
82
Errors
GUI not available
At least one field required
All fields must be strings
10.7.3.4. retap_packets()
Rescan all packets and just run taps - dont reconstruct the display.
10.7.3.5. copy_to_clipboard(text)
Copy a string into the clipboard.
Arguments
text
Arguments
filename
filter
10.7.3.7. get_filter()
Get the main filter text.
10.7.3.8. set_filter(text)
Set the main filter text.
Arguments
text
Arguments
row
The index of the desired color in the temporary coloring rules list.
text
10.7.3.10. apply_filter()
Apply the filter in the main filter box.
10.7.3.11. reload()
Reload the current capture file.
83
10.7.3.12. browser_open_url(url)
Open an url in a browser.
Arguments
url
The url.
10.7.3.13. browser_open_data_file(filename)
Open a file in a browser.
Arguments
filename
Arguments
tap (optional)
filter (optional)
allfields (optional)
Note
this impacts performance.
Returns
The newly created Listener listener object
Errors
tap registration error
10.8.1.2. Listener.list()
Gets a Lua array table of all registered Listener tap names.
Note
this is an expensive operation, and should only be used for troubleshooting.
Since: 1.11.3
84
Returns
The array table of registered tap names
10.8.1.3. listener:remove()
Removes a tap Listener.
10.8.1.4. listener:__tostring()
Generates a string of debug info for the tap Listener.
10.8.2. listener.packet
Mode: Assign only.
A function that will be called once every packet matches the Listener listener filter.
When later called by Wireshark, the packet function will be given:
1. A Pinfo object
2. A Tvb object
3. A tapinfo table
function tap.packet(pinfo,tvb,tapinfo) ... end
Note
tapinfo is a table of info based on the `Listeners type, or nil.
10.8.3. listener.draw
Mode: Assign only.
A function that will be called once every few seconds to redraw the GUI objects; in Tshark this funtion
is called only at the very end of the capture file.
When later called by Wireshark, the draw function will not be given any arguments.
function tap.draw() ... end
10.8.4. listener.reset
Mode: Assign only.
A function that will be called at the end of the capture run.
When later called by Wireshark, the reset function will not be given any arguments.
function tap.reset() ... end
85
10.9.1.1. Address.ip(hostname)
Creates an Address Object representing an IP address.
Arguments
hostname
Returns
The Address object.
10.9.1.2. address:__tostring()
Returns
The string representing the address.
10.9.1.3. address:__eq()
Compares two Addresses.
10.9.1.4. address:__le()
Compares two Addresses.
10.9.1.5. address:__lt()
Compares two Addresses.
10.9.2. Column
A Column in the packet list.
10.9.2.1. column:__tostring()
Returns
The columns string text (in parenthesis if not available).
10.9.2.2. column:clear()
Clears a Column.
10.9.2.3. column:set(text)
Sets the text of a Column.
Arguments
text
10.9.2.4. column:append(text)
Appends text to a Column.
Arguments
text
86
10.9.2.5. column:prepend(text)
Prepends text to a Column.
Arguments
text
10.9.2.6. column:fence()
Sets Column text fence, to prevent overwriting.
Since: 1.10.6
10.9.2.7. column:clear_fence()
Clear Column text fence.
Since: 1.11.3
10.9.3. Columns
The Columns of the packet list.
10.9.3.1. columns:__tostring()
Returns
The string "Columns", no real use, just for debugging purposes.
Arguments
column
text
10.9.3.3. columns:__index()
Gets a specific Column.
10.9.4. NSTime
NSTime represents a nstime_t. This is an object with seconds and nanoseconds.
Arguments
seconds (optional)
Seconds.
nseconds (optional)
Nano seconds.
87
Returns
The new NSTime object.
Arguments
seconds (optional)
Seconds.
nseconds (optional)
Nanoseconds.
Returns
The new NSTime object.
10.9.4.3. nstime:__tostring()
Returns
The string representing the nstime.
10.9.4.4. nstime:__add()
Calculates the sum of two NSTimes.
10.9.4.5. nstime:__sub()
Calculates the diff of two NSTimes.
10.9.4.6. nstime:__unm()
Calculates the negative NSTime.
10.9.4.7. nstime:__eq()
Compares two NSTimes.
10.9.4.8. nstime:__le()
Compares two NSTimes.
10.9.4.9. nstime:__lt()
Compares two NSTimes.
10.9.5. nstime.secs
Mode: Retrieve or assign.
The NSTime seconds.
10.9.6. nstime.nsecs
Mode: Retrieve or assign.
88
10.9.7. Pinfo
Packet information.
10.9.8. pinfo.visited
Mode: Retrieve only.
Whether this packet has been already visited.
10.9.9. pinfo.number
Mode: Retrieve only.
The number of this packet in the current file.
10.9.10. pinfo.len
Mode: Retrieve only.
The length of the frame.
10.9.11. pinfo.caplen
Mode: Retrieve only.
The captured length of the frame.
10.9.12. pinfo.abs_ts
Mode: Retrieve only.
When the packet was captured.
10.9.13. pinfo.rel_ts
Mode: Retrieve only.
Number of seconds passed since beginning of capture.
10.9.14. pinfo.delta_ts
Mode: Retrieve only.
Number of seconds passed since the last captured packet.
10.9.15. pinfo.delta_dis_ts
Mode: Retrieve only.
Number of seconds passed since the last displayed packet.
10.9.16. pinfo.circuit_id
Mode: Retrieve or assign.
89
10.9.17. pinfo.curr_proto
Mode: Retrieve only.
Which Protocol are we dissecting.
10.9.18. pinfo.can_desegment
Mode: Retrieve or assign.
Set if this segment could be desegmented.
10.9.19. pinfo.desegment_len
Mode: Retrieve or assign.
Estimated number of additional bytes required for completing the PDU.
10.9.20. pinfo.desegment_offset
Mode: Retrieve or assign.
Offset in the tvbuff at which the dissector will continue processing when next called.
10.9.21. pinfo.fragmented
Mode: Retrieve only.
If the protocol is only a fragment.
10.9.22. pinfo.in_error_pkt
Mode: Retrieve only.
If were inside an error packet.
10.9.23. pinfo.match_uint
Mode: Retrieve only.
Matched uint for calling subdissector from table.
10.9.24. pinfo.match_string
Mode: Retrieve only.
Matched string for calling subdissector from table.
10.9.25. pinfo.port_type
Mode: Retrieve or assign.
Type of Port of .src_port and .dst_port.
90
10.9.26. pinfo.src_port
Mode: Retrieve or assign.
Source Port of this Packet.
10.9.27. pinfo.dst_port
Mode: Retrieve or assign.
Source Address of this Packet.
10.9.28. pinfo.dl_src
Mode: Retrieve or assign.
Data Link Source Address of this Packet.
10.9.29. pinfo.dl_dst
Mode: Retrieve or assign.
Data Link Destination Address of this Packet.
10.9.30. pinfo.net_src
Mode: Retrieve or assign.
Network Layer Source Address of this Packet.
10.9.31. pinfo.net_dst
Mode: Retrieve or assign.
Network Layer Destination Address of this Packet.
10.9.32. pinfo.src
Mode: Retrieve or assign.
Source Address of this Packet.
10.9.33. pinfo.dst
Mode: Retrieve or assign.
Destination Address of this Packet.
10.9.34. pinfo.match
Mode: Retrieve only.
Port/Data we are matching.
10.9.35. pinfo.columns
Mode: Retrieve only.
91
10.9.36. pinfo.cols
Mode: Retrieve only.
Accesss to the packet list columns (equivalent to pinfo.columns).
10.9.37. pinfo.private
Mode: Retrieve only.
Access to the private table entries.
10.9.38. pinfo.hi
Mode: Retrieve or assign.
Higher Address of this Packet.
10.9.39. pinfo.lo
Mode: Retrieve only.
Lower Address of this Packet.
10.9.40. pinfo.conversation
Mode: Assign only.
Sets the packet conversation to the given Proto object.
10.9.41. PrivateTable
PrivateTable represents the pinfo#private_table.
10.9.41.1. privatetable:__tostring()
Gets debugging type information about the private table.
Returns
A string with all keys in the table, mostly for debugging.
92
10.10.1. Dissector
A refererence to a dissector, used to call a dissector against a packet or a part of it.
10.10.1.1. Dissector.get(name)
Obtains a dissector reference by name.
Arguments
name
Returns
The Dissector reference.
10.10.1.2. Dissector.list()
Gets a Lua array table of all registered Dissector names.
Note
this is an expensive operation, and should only be used for troubleshooting.
Since: 1.11.3
Returns
The array table of registered dissector names.
Arguments
tvb
pinfo
tree
Returns
Number of bytes dissected. Note that some dissectors always return number of bytes in incoming
buffer, so be aware.
Arguments
tvb
pinfo
tree
93
10.10.1.5. dissector:__tostring()
Gets the Dissectors protocol short name.
Returns
A string of the protocols short name.
10.10.2. DissectorTable
A table of subdissectors of a particular protocol (e.g. TCP subdissectors like http, smtp, sip are added
to table "tcp.port").
Useful to add more dissectors to a table so that they appear in the Decode As dialog.
Arguments
tablename
uiname (optional)
The name of the table in the User Interface (defaults to the name given).
type (optional)
base (optional)
Returns
The newly created DissectorTable.
10.10.2.2. DissectorTable.list()
Gets a Lua array table of all DissectorTable names - i.e., the string names you can use for the first
argument to DissectorTable.get().
Note
this is an expensive operation, and should only be used for troubleshooting.
Since: 1.11.3
Returns
The array table of registered DissectorTable names.
10.10.2.3. DissectorTable.heuristic_list()
Gets a Lua array table of all heuristic list names - i.e., the string names you can use for the first
argument in Proto:register_heuristic().
Note
this is an expensive operation, and should only be used for troubleshooting.
94
Since: 1.11.3
Returns
The array table of registered heuristic list names
10.10.2.4. DissectorTable.get(tablename)
Obtain a reference to an existing dissector table.
Arguments
tablename
Returns
The DissectorTable.
Arguments
pattern
dissector
Arguments
pattern
dissector
Arguments
pattern
dissector
10.10.2.8. dissectortable:remove_all(dissector)
Remove all dissectors from a table.
Since: 1.11.3
95
Arguments
dissector
Arguments
pattern
The pattern to be matched (either an integer or a string depending on the tables type).
tvb
pinfo
tree
Returns
Number of bytes dissected. Note that some dissectors always return number of bytes in incoming
buffer, so be aware.
10.10.2.10. dissectortable:get_dissector(pattern)
Try to obtain a dissector from a table.
Arguments
pattern
The pattern to be matched (either an integer or a string depending on the tables type).
Returns
The dissector handle if found.
nil if not found.
10.10.2.11. dissectortable:add_for_decode_as(proto)
Add the given Proto to the "Decode as" list for this DissectorTable. The passed-in Proto objects
dissector() function is used for dissecting.
Since: 1.99.1
Arguments
proto
10.10.2.12. dissectortable:__tostring()
Gets some debug information about the DissectorTable.
Returns
A string of debug information about the DissectorTable.
10.10.3. Pref
A preference of a Protocol.
96
Arguments
label
The Label (text in the right side of the preference input) for this preference.
default
descr
Arguments
label
The Label (text in the right side of the preference input) for this preference.
default
descr
Arguments
label
The Label (text in the right side of the preference input) for this preference.
default
descr
Arguments
label
The Label (text in the right side of the preference input) for this preference.
default
descr
enum
radio
Arguments
label
The Label (text in the right side of the preference input) for this preference.
default
The default value for this preference, e.g., "53", "10-30", or "10-30,53,55,100-120".
97
descr
max
Arguments
label
descr
10.10.4. Prefs
The table of preferences of a protocol.
Arguments
name
pref
Errors
Unknow Pref type
10.10.4.2. prefs:__index(name)
Get the value of a preference setting.
Arguments
name
Returns
The current value of the preference.
Errors
Unknow Pref type
10.10.5. Proto
A new protocol in Wireshark. Protocols have more uses, the main one is to dissect a protocol. But they
can also be just dummies used to register preferences for other purposes.
98
desc
Returns
The newly created protocol.
Arguments
name
desc
Returns
The new Proto object.
Arguments
listname
The heuristic list name this function is a heuristic for (e.g., "udp" or
"infiniband.payload").
func
10.10.6. proto.dissector
Mode: Retrieve or assign.
The protocols dissector, a function you define.
When later called, the function will be given:
99
1. A Tvb object
2. A Pinfo object
3. A TreeItem object
10.10.7. proto.prefs
Mode: Retrieve only.
The preferences of this dissector.
10.10.8. proto.prefs_changed
Mode: Assign only.
The preferences changed routine of this dissector, a Lua function you define.
10.10.9. proto.init
Mode: Assign only.
The init routine of this dissector, a function you define.
The called init function is passed no arguments.
10.10.10. proto.name
Mode: Retrieve only.
The name given to this dissector.
10.10.11. proto.description
Mode: Retrieve only.
The description given to this dissector.
10.10.12. proto.fields
Mode: Retrieve or assign.
The `ProtoField`s Lua table of this dissector.
10.10.13. proto.experts
Mode: Retrieve or assign.
The expert info Lua table of this Proto.
Since: 1.11.3
10.10.14. ProtoExpert
A Protocol expert info field, to be used when adding items to the dissection tree.
Since: 1.11.3
100
Arguments
abbr
Filter name of the expert info field (the string that is used in filters).
text
group
Expert
group
type:
one
of:
expert.group.CHECKSUM,
expert.group.SEQUENCE,
expert.group.RESPONSE_CODE,
expert.group.REQUEST_CODE,
expert.group.UNDECODED,
expert.group.REASSEMBLE,
expert.group.MALFORMED,
expert.group.DEBUG,
expert.group.PROTOCOL,
expert.group.SECURITY, or expert.group.COMMENTS_GROUP.
severity
Expert
severity
type:
one
of:
expert.severity.COMMENT,
expert.severity.CHAT,
expert.severity.NOTE,
expert.severity.WARN, or expert.severity.ERROR.
Returns
The newly created ProtoExpert object.
10.10.14.2. protoexpert:__tostring()
Returns a string with debugging information about a ProtoExpert object.
Since: 1.11.3
10.10.15. ProtoField
A Protocol field (to be used when adding items to the dissection tree).
Arguments
name
Actual name of the field (the string that appears in the tree).
abbr
type
Field
Type:
one
of:
ftypes.BOOLEAN,
ftypes.UINT8, ftypes.UINT16, ftypes.UINT24,
ftypes.UINT32, ftypes.UINT64, ftypes.INT8,
ftypes.INT16, ftypes.INT24, ftypes.INT32,
ftypes.INT64, ftypes.FLOAT, ftypes.DOUBLE ,
ftypes.ABSOLUTE_TIME, ftypes.RELATIVE_TIME,
ftypes.STRING,
ftypes.STRINGZ,
ftypes.UINT_STRING,
ftypes.ETHER,
ftypes.BYTES,
ftypes.UINT_BYTES,
ftypes.IPv4,
ftypes.IPv6,
ftypes.IPXNET,
101
base (optional)
mask (optional)
descr (optional)
Returns
The newly created ProtoField object.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
valuestring (optional)
mask (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
valuestring (optional)
mask (optional)
desc (optional)
102
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
valuestring (optional)
mask (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
valuestring (optional)
mask (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
103
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
valuestring (optional)
mask (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
valuestring (optional)
mask (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
valuestring (optional)
mask (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
104
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
valuestring (optional)
mask (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
valuestring (optional)
mask (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
valuestring (optional)
105
mask (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
valuestring (optional)
mask (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
display (optional)
valuestring (optional)
mask (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
106
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
base (optional)
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
107
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
108
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
109
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
110
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
Arguments
abbr
name (optional)
Actual name of the field (the string that appears in the tree).
desc (optional)
Returns
A ProtoField object to be added to a table set to the Proto.fields attribute.
10.10.15.31. protofield:__tostring()
Returns a string with info about a protofield (for debugging purposes).
Arguments
proto
allfields (optional)
Note
this impacts performance (default=false).
111
In Wireshark version 1.11.3, this function was changed to return more than just the new child
TreeItem. The child is the first return value, so that function chaining will still work as before;
but it now also returns the value of the extracted field (i.e., a number, UInt64, Address, etc.). If
the value could not be extracted from the TvbRange, the child TreeItem is still returned, but the
second returned value is nil.
Another new feature added to this function in Wireshark version 1.11.3 is the ability to extract native
number ProtoField`s from string encoding in the `TvbRange, for ASCII-based
and similar string encodings. For example, a ProtoField of as ftypes.UINT32 type can be
extracted from a TvbRange containing the ASCII string "123", and it will correctly decode the ASCII
to the number 123, both in the tree as well as for the second return value of this function. To do so, you
must set the encoding argument of this function to the appropriate string ENC_* value, bitwise-ord
with the ENC_STRING value (see init.lua). ENC_STRING is guaranteed to be a unique bit flag,
and thus it can added instead of bitwise-ored as well. Only single-byte ASCII digit string encoding
types can be used for this, such as ENC_ASCII and ENC_UTF_8.
For example, assuming the Tvb named "tvb" contains the string "123":
-- this is done earlier in the script
local myfield = ProtoField.new("Transaction ID", "myproto.trans_id", ftypes.UINT16)
-- this is done inside a dissector, post-dissector, or heuristic function
-- child will be the created child tree, and value will be the number 123 or nil on failure
local child, value = tree:add_packet_field(myfield, tvb:range(0,3), ENC_UTF_8 + ENC_STRING)
Arguments
protofield
tvbrange (optional)
encoding
label (optional)
Returns
The new child TreeItem, the fields extracted value or nil, and offset or nil.
112
Arguments
protofield (optional)
tvbrange (optional)
value (optional)
label (optional)
One or more strings to use for the tree item label, instead of the
ProtoField/Proto one.
Returns
The new child TreeItem.
Arguments
protofield (optional)
tvbrange (optional)
value (optional)
label (optional)
One or more strings to use for the tree item label, instead of the
ProtoField/Proto one.
Returns
The new child TreeItem.
113
10.11.1.4. treeitem:set_text(text)
Sets the text of the label.
This used to return nothing, but as of 1.11.3 it returns the same tree item to allow chained calls.
Arguments
text
Returns
The same TreeItem.
10.11.1.5. treeitem:append_text(text)
Appends text to the label.
This used to return nothing, but as of 1.11.3 it returns the same tree item to allow chained calls.
Arguments
text
Returns
The same TreeItem.
10.11.1.6. treeitem:prepend_text(text)
Prepends text to the label.
This used to return nothing, but as of 1.11.3 it returns the same tree item to allow chained calls.
Arguments
text
Returns
The same TreeItem.
Note
This function is provided for backwards compatibility only, and should not be
used in new Lua code. It may be removed in the future. You should only use
TreeItem.add_proto_expert_info().
Arguments
group (optional)
114
severity (optional)
text (optional)
Returns
The same TreeItem.
Arguments
expert
text (optional)
Text for the expert info display (default is to use the registered text).
Returns
The same TreeItem.
Arguments
expert
tvb
The Tvb or TvbRange object bytes to associate the expert info with.
text (optional)
Text for the expert info display (default is to use the registered text).
Returns
The same TreeItem.
10.11.1.10. treeitem:set_generated()
Marks the TreeItem as a generated field (with data inferred but not contained in the packet).
This used to return nothing, but as of 1.11.3 it returns the same tree item to allow chained calls.
Returns
The same TreeItem.
10.11.1.11. treeitem:set_hidden()
This function should not be used, and is provided for backwards-compatibility only.
Returns
The same TreeItem.
115
10.11.1.12. treeitem:set_len(len)
Set `TreeItems length inside tvb, after it has already been created.
This used to return nothing, but as of 1.11.3 it returns the same tree item to allow chained calls.
Arguments
len
Returns
The same TreeItem.
Arguments
hexbytes (optional)
separator (optional)
Returns
The new ByteArray object.
Arguments
first
First array.
second
Second array.
Returns
The new composite ByteArray.
Arguments
first
First array.
116
second
Second array.
10.12.1.4. bytearray:prepend(prepended)
Prepend a ByteArray to this ByteArray.
Arguments
prepended
ByteArray to be prepended.
10.12.1.5. bytearray:append(appended)
Append a ByteArray to this ByteArray.
Arguments
appended
ByteArray to be appended.
10.12.1.6. bytearray:set_size(size)
Sets the size of a ByteArray, either truncating it or filling it with zeros.
Arguments
size
Errors
ByteArray size must be non-negative
Arguments
index
value
10.12.1.8. bytearray:get_index(index)
Get the value of a byte in a ByteArray.
Arguments
index
Returns
The value [0-255] of the byte.
10.12.1.9. bytearray:len()
Obtain the length of a ByteArray.
Returns
The length of the ByteArray.
117
Arguments
offset
length
Returns
A ByteArray containing the requested segment.
10.12.1.11. bytearray:base64_decode()
Obtain a base64 decoded ByteArray.
Returns
The created ByteArray.
Arguments
offset (optional)
length (optional)
Returns
A Lua string of the binary bytes in the ByteArray.
Arguments
lowercase (optional)
separator (optional)
Returns
A hex-ascii string representation of the ByteArray.
10.12.1.14. bytearray:__tostring()
Obtain a Lua string containing the bytes in a ByteArray so that it can be used in display filters (e.g.
"01FE456789AB").
Returns
A hex-ascii string representation of the ByteArray.
118
10.12.2. Tvb
A Tvb represents the packets buffer. It is passed as an argument to listeners and dissectors, and can
be used to extract information (via TvbRange) from the packets data.
To create a TvbRange the Tvb must be called with offset and length as optional arguments; the offset
defaults to 0 and the length to tvb:len().
Warning
Tvbs are usable only by the current listener or dissector call and are destroyed as soon
as the listener/dissector returns, so references to them are unusable once the function
has returned.
10.12.2.1. ByteArray.tvb(name)
Creates a new Tvb from a ByteArray (it gets added to the current frame too).
Arguments
name
Returns
The created Tvb.
10.12.2.2. TvbRange.tvb(range)
Creates a (sub)Tvb from a TvbRange.
Arguments
range
10.12.2.3. tvb:__tostring()
Convert the bytes of a Tvb into a string, to be used for debugging purposes, as will be appended
if the string is too long.
Returns
The string.
10.12.2.4. tvb:reported_len()
Obtain the reported (not captured) length of a Tvb.
Returns
The reported length of the Tvb.
10.12.2.5. tvb:len()
Obtain the actual (captured) length of a Tvb.
Returns
The captured length of the Tvb.
119
10.12.2.6. tvb:reported_length_remaining()
Obtain the reported (not captured) length of packet data to end of a Tvb or -1 if the offset is beyond
the end of the Tvb.
Returns
The captured length of the Tvb.
10.12.2.7. tvb:offset()
Returns the raw offset (from the beginning of the source Tvb) of a sub Tvb.
Returns
The raw offset of the Tvb.
10.12.2.8. tvb:__call()
Equivalent to tvb:range()
10.12.3. TvbRange
A TvbRange represents a usable range of a Tvb and is used to extract data from the Tvb that
generated it.
TvbRange`s are created by calling a `Tvb (e.g. tvb(offset,length)). If the TvbRange
span is outside the `Tvbs range the creation will cause a runtime error.
Arguments
offset (optional)
The offset (in octets) from the beginning of the Tvb. Defaults to 0.
length (optional)
The length (in octets) of the range. Defaults to until the end of the Tvb.
Returns
The TvbRange
Arguments
offset (optional)
length (optional)
Returns
A Lua string of the binary bytes in the Tvb.
120
10.12.3.3. tvbrange:uint()
Get a Big Endian (network order) unsigned integer from a TvbRange. The range must be 1, 2, 3
or 4 octets long.
Returns
The unsigned integer value.
10.12.3.4. tvbrange:le_uint()
Get a Little Endian unsigned integer from a TvbRange. The range must be 1, 2, 3 or 4 octets long.
Returns
The unsigned integer value
10.12.3.5. tvbrange:uint64()
Get a Big Endian (network order) unsigned 64 bit integer from a TvbRange, as a UInt64 object.
The range must be 1-8 octets long.
Returns
The UInt64 object.
10.12.3.6. tvbrange:le_uint64()
Get a Little Endian unsigned 64 bit integer from a TvbRange, as a UInt64 object. The range must
be 1-8 octets long.
Returns
The UInt64 object.
10.12.3.7. tvbrange:int()
Get a Big Endian (network order) signed integer from a TvbRange. The range must be 1, 2 or 4
octets long.
Returns
The signed integer value
10.12.3.8. tvbrange:le_int()
Get a Little Endian signed integer from a TvbRange. The range must be 1, 2 or 4 octets long.
Returns
The signed integer value.
10.12.3.9. tvbrange:int64()
Get a Big Endian (network order) signed 64 bit integer from a TvbRange, as an Int64 object. The
range must be 1-8 octets long.
Returns
The Int64 object.
121
10.12.3.10. tvbrange:le_int64()
Get a Little Endian signed 64 bit integer from a TvbRange, as an Int64 object. The range must
be 1-8 octets long.
Returns
The Int64 object.
10.12.3.11. tvbrange:float()
Get a Big Endian (network order) floating point number from a TvbRange. The range must be 4
or 8 octets long.
Returns
The floating point value.
10.12.3.12. tvbrange:le_float()
Get a Little Endian floating point number from a TvbRange. The range must be 4 or 8 octets long.
Returns
The floating point value.
10.12.3.13. tvbrange:ipv4()
Get an IPv4 Address from a TvbRange, as an Address object.
Returns
The IPv4 Address object.
10.12.3.14. tvbrange:le_ipv4()
Get an Little Endian IPv4 Address from a TvbRange, as an Address object.
Returns
The IPv4 Address object.
10.12.3.15. tvbrange:ether()
Get an Ethernet Address from a TvbRange, as an Address object.
Returns
The Ethernet Address object.
Errors
The range must be 6 bytes long
10.12.3.16. tvbrange:nstime([encoding])
Obtain a time_t structure from a TvbRange, as an NSTime object.
122
Arguments
encoding (optional)
Returns
The NSTime object and number of bytes used, or nil on failure.
Errors
The range must be 4 or 8 bytes long
10.12.3.17. tvbrange:le_nstime()
Obtain a nstime from a TvbRange, as an NSTime object.
Returns
The NSTime object.
Errors
The range must be 4 or 8 bytes long
10.12.3.18. tvbrange:string([encoding])
Obtain a string from a TvbRange.
Arguments
encoding (optional)
Returns
The string
10.12.3.19. tvbrange:ustring()
Obtain a Big Endian (network order) UTF-16 encoded string from a TvbRange.
Returns
The string.
10.12.3.20. tvbrange:le_ustring()
Obtain a Little Endian UTF-16 encoded string from a TvbRange.
Returns
The string.
10.12.3.21. tvbrange:stringz([encoding])
Obtain a zero terminated string from a TvbRange.
Arguments
encoding (optional)
123
Returns
The zero terminated string.
10.12.3.22. tvbrange:strsize([encoding])
Find the size of a zero terminated string from a TvbRange. The size of the string includes the
terminating zero.
Arguments
encoding (optional)
Returns
Length of the zero terminated string.
10.12.3.23. tvbrange:ustringz()
Obtain a Big Endian (network order) UTF-16 encoded zero terminated string from a TvbRange.
Returns
Two return values: the zero terminated string, and the length.
10.12.3.24. tvbrange:le_ustringz()
Obtain a Little Endian UTF-16 encoded zero terminated string from a TvbRange
Returns
Two return values: the zero terminated string, and the length.
10.12.3.25. tvbrange:bytes([encoding])
Obtain a ByteArray from a TvbRange.
Starting in 1.11.4, this function also takes an optional encoding argument, which can be set to
ENC_STR_HEX to decode a hex-string from the TvbRange into the returned ByteArray. The
encoding can be bitwise-ored with one or more separator encodings, such as ENC_SEP_COLON,
to allow separators to occur between each pair of hex characters.
The return value also now returns the number of bytes used as a second return value.
On failure or error, nil is returned for both return values.
Note
The encoding type of the hex string should also be set, for example ENC_ASCII or
ENC_UTF_8, along with ENC_STR_HEX.
Arguments
encoding (optional)
Returns
The ByteArray object or nil, and number of bytes consumed or nil.
124
Arguments
position (optional)
length (optional)
Returns
The bitfield value
Arguments
offset (optional)
The offset (in octets) from the beginning of the TvbRange. Defaults
to 0.
length (optional)
The length (in octets) of the range. Defaults to until the end of the
TvbRange.
name
Returns
The TvbRange
The TvbRange
10.12.3.28. tvbrange:len()
Obtain the length of a TvbRange.
10.12.3.29. tvbrange:offset()
Obtain the offset in a TvbRange.
Arguments
offset (optional)
length (optional)
Returns
A Lua string of the binary bytes in the TvbRange.
10.12.3.31. tvbrange:__tostring()
Converts the TvbRange into a string. Since the string gets truncated, you should use this only for
debugging purposes or if what you want is to have a truncated string in the format 67:89:AB:
125
Returns
A Lua hex string of the first 24 binary bytes in the TvbRange.
10.13.1. CaptureInfo
A CaptureInfo object, passed into Lua as an argument by FileHandler callback function
read_open(), read(), seek_read(), seq_read_close(), and read_close(). This
object represents capture file data and meta-data (data about the capture file) being read into Wireshark/
Tshark.
This objects fields can be written-to by Lua during the read-based function callbacks. In other words,
when the Lua plugins FileHandler.read_open() function is invoked, a CaptureInfo
object will be passed in as one of the arguments, and its fields should be written to by your Lua code
to tell Wireshark about the capture.
Since: 1.11.3
10.13.1.1. captureinfo:__tostring()
Generates a string of debug info for the CaptureInfo
Returns
String of debug information.
10.13.2. captureinfo.encap
Mode: Retrieve or assign.
The packet encapsulation type for the whole file.
See wtap_encaps in init.lua for available types. Set to wtap_encaps.PER_PACKET if
packets can have different types, then later set FrameInfo.encap for each packet during read()/
seek_read().
10.13.3. captureinfo.time_precision
Mode: Retrieve or assign.
The precision of the packet timestamps in the file.
See wtap_file_tsprec in init.lua for available precisions.
10.13.4. captureinfo.snapshot_length
Mode: Retrieve or assign.
The maximum packet length that could be recorded.
Setting it to 0 means unknown. Wireshark cannot handle anything bigger than 65535 bytes.
126
10.13.5. captureinfo.comment
Mode: Retrieve or assign.
A string comment for the whole capture file, or nil if there is no comment.
10.13.6. captureinfo.hardware
Mode: Retrieve or assign.
A string containing the description of the hardware used to create the capture, or nil if there is no
hardware string.
10.13.7. captureinfo.os
Mode: Retrieve or assign.
A string containing the name of the operating system used to create the capture, or nil if there is no
os string.
10.13.8. captureinfo.user_app
Mode: Retrieve or assign.
A string containing the name of the application used to create the capture, or nil if there is no
user_app string.
10.13.9. captureinfo.hosts
Mode: Assign only.
Sets resolved ip-to-hostname information.
The value set must be a Lua table of two key-ed names: ipv4_addresses and
ipv6_addresses. The value of each of these names are themselves array tables, of key-ed tables,
such that the inner table has a key addr set to the raw 4-byte or 16-byte IP address Lua string and
a name set to the resolved name.
For example, if the capture file identifies one resolved IPv4 address of 1.2.3.4 to foo.com, then you
must set CaptureInfo.hosts to a table of:
{ ipv4_addresses = { { addr = "\01\02\03\04", name = "foo.com" } } }
Note that either the ipv4_addresses or the ipv6_addresses table, or both, may be empty
or nil.
10.13.10. captureinfo.private_table
Mode: Retrieve or assign.
A private Lua value unique to this file.
The private_table is a field you set/get with your own Lua table. This is provided so that a Lua
script can save per-file reading/writing state, because multiple files can be opened and read at the
same time.
For example, if the user issued a reload-file command, or Lua called the reload() function, then
the current capture file is still open while a new one is being opened, and thus Wireshark will invoke
read_open() while the previous capture file has not caused read_close() to be called; and if
127
the read_open() succeeds then read_close() will be called right after that for the previous
file, rather than the one just opened. Thus the Lua script can use this private_table to store a
table of values specific to each file, by setting this private_table in the read_open() function,
which it can then later get back inside its read(), seek_read(), and read_close() functions.
10.13.11. CaptureInfoConst
A CaptureInfoConst object, passed into Lua as an argument to the FileHandler callback
function write_open().
This object represents capture file data and meta-data (data about the capture file) for the current
capture in Wireshark/Tshark.
This objects fields are read-from when used by write_open function callback. In other words,
when the Lua plugins FileHandler write_open function is invoked, a CaptureInfoConst
object will be passed in as one of the arguments, and its fields should be read from by your Lua code
to get data about the capture that needs to be written.
Since: 1.11.3
10.13.11.1. captureinfoconst:__tostring()
Generates a string of debug info for the CaptureInfoConst
Returns
String of debug information.
10.13.12. captureinfoconst.type
Mode: Retrieve only.
The file type.
10.13.13. captureinfoconst.snapshot_length
Mode: Retrieve only.
The maximum packet length that is actually recorded (vs. the original length of any given packet onthe-wire). A value of 0 means the snapshot length is unknown or there is no one such length for the
whole file.
10.13.14. captureinfoconst.encap
Mode: Retrieve only.
The packet encapsulation type for the whole file.
See wtap_encaps in init.lua for available types. It is set to wtap_encaps.PER_PACKET
if packets can have different types, in which case each Frame identifies its type, in
FrameInfo.packet_encap.
10.13.15. captureinfoconst.comment
Mode: Retrieve or assign.
A comment for the whole capture file, if the wtap_presence_flags.COMMENTS was set in the
presence flags; nil if there is no comment.
128
10.13.16. captureinfoconst.hardware
Mode: Retrieve only.
A string containing the description of the hardware used to create the capture, or nil if there is no
hardware string.
10.13.17. captureinfoconst.os
Mode: Retrieve only.
A string containing the name of the operating system used to create the capture, or nil if there is no
os string.
10.13.18. captureinfoconst.user_app
Mode: Retrieve only.
A string containing the name of the application used to create the capture, or nil if there is no user_app
string.
10.13.19. captureinfoconst.hosts
Mode: Retrieve only.
A ip-to-hostname Lua table of two key-ed names: ipv4_addresses and ipv6_addresses. The
value of each of these names are themselves array tables, of key-ed tables, such that the inner table has
a key addr set to the raw 4-byte or 16-byte IP address Lua string and a name set to the resolved name.
For example, if the current capture has one resolved IPv4 address of 1.2.3.4 to foo.com, then getting
CaptureInfoConst.hosts will get a table of:
{ ipv4_addresses = { { addr = "\01\02\03\04", name = "foo.com" } }, ipv6_addresses = { } }
Note that either the ipv4_addresses or the ipv6_addresses table, or both, may be empty,
however they will not be nil.
10.13.20. captureinfoconst.private_table
Mode: Retrieve or assign.
A private Lua value unique to this file.
The private_table is a field you set/get with your own Lua table. This is provided so that a Lua
script can save per-file reading/writing state, because multiple files can be opened and read at the
same time.
For example, if two Lua scripts issue a Dumper:new_for_current() call and the current
file happens to use your scripts writer, then the Wireshark will invoke write_open()
while the previous capture file has not had write_close() called. Thus the Lua script can
use this private_table to store a table of values specific to each file, by setting this
private_table in the write_open() function, which it can then later get back inside its write(),
and write_close() functions.
10.13.21. File
A File object, passed into Lua as an argument by FileHandler callback functions (e.g., read_open,
read, write, etc.). This behaves similarly to the Lua io librarys file object, returned when
calling io.open(), except in this case you cannot call file:close(), file:open(), nor
129
file:setvbuf(), since Wireshark/tshark manages the opening and closing of files. You also
cannot use the io library itself on this object, i.e. you cannot do io.read(file, 4). Instead,
use this File with the object-oriented style calling its methods, i.e. myfile:read(4). (see later
example)
The purpose of this object is to hide the internal complexity of how Wireshark handles files, and
instead provide a Lua interface that is familiar, by mimicking the io library. The reason true/raw io
files cannot be used is because Wireshark does many things under the hood, such as compress the file,
or write to stdout, or various other things based on configuration/commands.
When a File object is passed in through reading-based callback functions, such as read_open(),
read(), and read_close(), then the File objects write() and flush() functions are not
usable and will raise an error if used.
When a File object is passed in through writing-based callback functions, such as write_open(),
write(), and write_close(), then the File objects read() and lines() functions are not
usable and will raise an error if used.
Note
a File object should never be stored/saved beyond the scope of the callback function
it is passed in to.
For example:
function myfilehandler.read_open(file, capture)
local position = file:seek()
-- read 24 bytes
local line = file:read(24)
-- do stuff
-- it's not our file type, seek back (unnecessary but just to show it...)
file:seek("set",position)
-- return false because it's not our file type
return false
end
Since: 1.11.3
10.13.21.1. file:read()
Reads from the File, similar to Luas file:read(). See Lua 5.x ref manual for file:read().
10.13.21.2. file:seek()
Seeks in the File, similar to Luas file:seek(). See Lua 5.x ref manual for file:seek().
Returns
The current file cursor position as a number.
10.13.21.3. file:lines()
Lua iterator function for retrieving ASCII File lines, similar to Luas file:lines(). See Lua 5.x
ref manual for file:lines().
10.13.21.4. file:write()
Writes to the File, similar to Luas file:write(). See Lua 5.x ref manual for file:write().
130
10.13.21.5. file:__tostring()
Generates a string of debug info for the File object
Returns
String of debug information.
10.13.22. file.compressed
Mode: Retrieve only.
Whether the File is compressed or not.
See wtap_encaps in init.lua for available types. Set to wtap_encaps.PER_PACKET if packets
can have different types, then later set FrameInfo.encap for each packet during read()/
seek_read().
10.13.23. FileHandler
A FileHandler object, created by a call to FileHandler.new(arg1, arg2, ). The FileHandler object lets
you create a file-format reader, or writer, or both, by setting your own read_open/read or write_open/
write functions.
Since: 1.11.3
Arguments
name
The name of the file type, for display purposes only. E.g., "Wireshark - pcapng"
shortname
The file type short name, used as a shortcut in various places. E.g., "pcapng".
Note: the name cannot already be in use.
description
Descriptive text about this file format, for display purposes only
type
Returns
The newly created FileHandler object
10.13.23.2. filehandler:__tostring()
Generates a string of debug info for the FileHandler
Returns
String of debug information.
10.13.24. filehandler.read_open
Mode: Assign only.
The Lua function to be called when Wireshark opens a file for reading.
131
10.13.25. filehandler.read
Mode: Assign only.
The Lua function to be called when Wireshark wants to read a packet from the file.
When later called by Wireshark, the Lua function will be given:
1. A File object
2. A CaptureInfo object
3. A FrameInfo object
The purpose of the Lua function set to this read field is to read the next packet from the file,
and setting the parsed/read packet into the frame buffer using FrameInfo.data = foo or
FrameInfo:read_data().
The called Lua function should return the file offset/position number where the packet begins, or false
if it hit an error. The file offset will be saved by Wireshark and passed into the set seek_read()
Lua function later.
10.13.26. filehandler.seek_read
Mode: Assign only.
The Lua function to be called when Wireshark wants to read a packet from the file at the given offset.
When later called by Wireshark, the Lua function will be given:
1. A File object
2. A CaptureInfo object
3. A FrameInfo object
4. The file offset number previously set by the read() function call
10.13.27. filehandler.read_close
Mode: Assign only.
The Lua function to be called when Wireshark wants to close the read file completely.
When later called by Wireshark, the Lua function will be given:
132
1. A File object
2. A CaptureInfo object
It is not necessary to set this field to a Lua function - FileHandler can be registered without doing so
- it is available in case there is memory/state to clear in your script when the file is closed.
10.13.28. filehandler.seq_read_close
Mode: Assign only.
The Lua function to be called when Wireshark wants to close the sequentially-read file.
When later called by Wireshark, the Lua function will be given:
1. A File object
2. A CaptureInfo object
It is not necessary to set this field to a Lua function - FileHandler can be registered without doing so - it
is available in case there is memory/state to clear in your script when the file is closed for the sequential
reading portion. After this point, there will be no more calls to read(), only seek_read().
10.13.29. filehandler.can_write_encap
Mode: Assign only.
The Lua function to be called when Wireshark wants to write a file, by checking if this file writer can
handle the wtap packet encapsulation(s).
When later called by Wireshark, the Lua function will be given a Lua number, which matches one of
the encapsulations in the Lua wtap_encaps table. This might be the wtap_encap.PER_PACKET
number, meaning the capture contains multiple encapsulation types, and the file reader should only
return true if it can handle multiple encap types in one file. The function will then be called again,
once for each encap type in the file, to make sure it can write each one.
If the Lua file writer can write the given type of encapsulation into a file, then it returns the boolean
true, else false.
10.13.30. filehandler.write_open
Mode: Assign only.
The Lua function to be called when Wireshark opens a file for writing.
When later called by Wireshark, the Lua function will be given:
1. A File object
2. A CaptureInfoConst object
The purpose of the Lua function set to this write_open field is similar to the read_open callback
function: to initialize things necessary for writing the capture to a file. For example, if the output file
format has a file header, then the file header should be written within this write_open function.
The called Lua function should return true on success, or false if it hit an error.
Also
make
sure
to
set
the
FileHandler.write
(and
FileHandler.write_close) functions before returning true from this function.
133
potentially
10.13.31. filehandler.write
Mode: Assign only.
The Lua function to be called when Wireshark wants to write a packet to the file.
When later called by Wireshark, the Lua function will be given:
1. A File object
2. A CaptureInfoConst object
3. A FrameInfoConst object of the current frame/packet to be written
The purpose of the Lua function set to this write field is to write the next packet to the file.
The called Lua function should return true on success, or false if it hit an error.
10.13.32. filehandler.write_close
Mode: Assign only.
The Lua function to be called when Wireshark wants to close the written file.
When later called by Wireshark, the Lua function will be given:
1. A File object
2. A CaptureInfoConst object
It is not necessary to set this field to a Lua function - FileHandler can be registered without doing
so - it is available in case there is memory/state to clear in your script when the file is closed.
10.13.33. filehandler.type
Mode: Retrieve only.
The internal file type. This is automatically set with a new number when the FileHandler is registered.
10.13.34. filehandler.extensions
Mode: Retrieve or assign.
One or more file extensions that this file type usually uses.
For readers using heuristics to determine file type, Wireshark will try the readers of the files extension
first, before trying other readers. But ultimately Wireshark tries all file readers for any file extension,
until it finds one that accepts the file.
10.13.35. filehandler.writing_must_seek
Mode: Retrieve or assign.
True if the ability to seek is required when writing this file format, else false.
This will be checked by Wireshark when writing out to compressed file formats, because seeking is
not possible with compressed files. Usually a file writer only needs to be able to seek if it needs to go
back in the file to change something, such as a block or file length value earlier in the file.
134
10.13.36. filehandler.writes_name_resolution
Mode: Retrieve or assign.
True if the file format supports name resolution records, else false.
10.13.37. filehandler.supported_comment_types
Mode: Retrieve or assign.
Set to the bit-wise ORed number representing the type of comments the file writer supports writing,
based on the numbers in the wtap_comments table.
10.13.38. FrameInfo
A FrameInfo object, passed into Lua as an argument by FileHandler callback functions (e.g., read,
seek_read, etc.).
This object represents frame data and meta-data (data about the frame/packet) for a given read/
seek_read/`writes frame.
This objects fields are written-to/set when used by read function callbacks, and read-from/get when
used by file write function callbacks. In other words, when the Lua plugins FileHandler read/
seek_read/etc. functions are invoked, a FrameInfo object will be passed in as one of the arguments,
and its fields should be written-to/set based on the frame information read from the file; whereas when
the Lua plugins FileHandler.write() function is invoked, the FrameInfo object passed in
should have its fields read-from/get, to write that frame information to the file.
Since: 1.11.3
10.13.38.1. frameinfo:__tostring()
Generates a string of debug info for the FrameInfo
Returns
String of debug information.
Arguments
file
length
The number of bytes to read from the file at the current cursor position.
Returns
True if succeeded, else returns false along with the error number and string error description.
A Lua string of the frame buffers data.
10.13.39. frameinfo.time
Mode: Retrieve or assign.
135
Note
Set
the
FileHandler.time_precision
wtap_file_tsprec value as well.
to
the
appropriate
10.13.40. frameinfo.data
Mode: Retrieve or assign.
The data buffer containing the packet.
Note
This cannot be cleared once set.
10.13.41. frameinfo.rec_type
Mode: Retrieve or assign.
The record type of the packet frame
See wtap_rec_types in init.lua for values.
10.13.42. frameinfo.flags
Mode: Retrieve or assign.
The presence flags of the packet frame.
See wtap_presence_flags in init.lua for bit values.
10.13.43. frameinfo.captured_length
Mode: Retrieve or assign.
The captured packet length, and thus the length of the buffer passed to the FrameInfo.data field.
10.13.44. frameinfo.original_length
Mode: Retrieve or assign.
The on-the-wire packet length, which may be longer than the captured_length.
10.13.45. frameinfo.encap
Mode: Retrieve or assign.
The packet encapsulation type for the frame/packet, if the file supports per-packet types. See
wtap_encaps in init.lua for possible packet encapsulation types to use as the value for this
field.
10.13.46. frameinfo.comment
Mode: Retrieve or assign.
136
A string comment for the packet, if the wtap_presence_flags.COMMENTS was set in the
presence flags; nil if there is no comment.
10.13.47. FrameInfoConst
A constant FrameInfo object, passed into Lua as an argument by the FileHandler write callback
function. This has similar attributes/properties as FrameInfo, but the fields can only be read from, not
written to.
Since: 1.11.3
10.13.47.1. frameinfoconst:__tostring()
Generates a string of debug info for the FrameInfo
Returns
String of debug information.
Arguments
file
length (optional)
The number of bytes to write to the file at the current cursor position,
or all if not supplied.
Returns
True if succeeded, else returns false along with the error number and string error description.
10.13.48. frameinfoconst.time
Mode: Retrieve only.
The packet timestamp as an NSTime object.
10.13.49. frameinfoconst.data
Mode: Retrieve only.
The data buffer containing the packet.
10.13.50. frameinfoconst.rec_type
Mode: Retrieve only.
The record type of the packet frame - see wtap_presence_flags in init.lua for values.
10.13.51. frameinfoconst.flags
Mode: Retrieve only.
The presence flags of the packet frame - see wtap_presence_flags in init.lua for bits.
137
10.13.52. frameinfoconst.captured_length
Mode: Retrieve only.
The captured packet length, and thus the length of the buffer in the FrameInfoConst.data field.
10.13.53. frameinfoconst.original_length
Mode: Retrieve only.
The on-the-wire packet length, which may be longer than the captured_length.
10.13.54. frameinfoconst.encap
Mode: Retrieve only.
The packet encapsulation type, if the file supports per-packet types.
See wtap_encaps in init.lua for possible packet encapsulation types to use as the value for
this field.
10.13.55. frameinfoconst.comment
Mode: Retrieve only.
A comment for the packet; nil if there is none.
Arguments
filehandler
Returns
the new type number for this file reader/write
10.13.56.2. deregister_filehandler(filehandler)
De-register the FileHandler from Wireshark/tshark, so it no longer gets used for reading/writing/
display. This function cannot be called inside the reading/writing callback functions.
Arguments
filehandler
138
10.14.1.1. Dir.make(name)
Creates a directory.
The created directory is set for permission mode 0755 (octal), meaning it is read+write+execute by
owner, but only read+execute by group and others.
IF the directory was created successfully, a boolean true is returned. If the directory cannot be made
because it already exists, false is returned. If the directory cannot be made because an error occurred,
nil is returned.
Since: 1.11.3
Arguments
name
Returns
Boolean true on success, false if already exists, nil on error.
10.14.1.2. Dir.exists(name)
Returns true if the given directory name exists.
If the directory exists, a boolean true is returned. If the path is a file instead, false is returned. If
the path does not exist or an error occurred, nil is returned.
Since: 1.11.3
Arguments
name
Returns
Boolean true if the directory exists, false if its a file, nil on error/not-exist.
10.14.1.3. Dir.remove(name)
Removes an empty directory.
If the directory was removed successfully, a boolean true is returned. If the directory cannot be
removed because it does not exist, false is returned. If the directory cannot be removed because an
error occurred, nil is returned.
This function only removes empty directories. To remove a directory regardless, use
Dir.remove_all().
Since: 1.11.3
Arguments
name
Returns
Boolean true on success, false if does not exist, nil on error.
139
10.14.1.4. Dir.remove_all(name)
Removes an empty or non-empty directory.
If the directory was removed successfully, a boolean true is returned. If the directory cannot be
removed because it does not exist, false is returned. If the directory cannot be removed because an
error occurred, nil is returned.
Since: 1.11.3
Arguments
name
Returns
Boolean true on success, false if does not exist, nil on error.
Arguments
pathname
extension (optional)
Returns
the Dir object.
10.14.1.6. Dir.personal_config_path([filename])
Gets the personal configuration directory path, with filename if supplied.
Since: 1.11.3
Arguments
filename (optional)
A filename.
Returns
The full pathname for a file in the personal configuration directory.
10.14.1.7. Dir.global_config_path([filename])
Gets the global configuration directory path, with filename if supplied.
Since: 1.11.3
Arguments
filename (optional)
A filename
Returns
The full pathname for a file in wiresharks configuration directory.
140
10.14.1.8. Dir.personal_plugins_path()
Gets the personal plugins directory path.
Since: 1.11.3
Returns
The pathname for the personal plugins directory.
10.14.1.9. Dir.global_plugins_path()
Gets the global plugins directory path.
Since: 1.11.3
Returns
The pathname for the global plugins directory.
10.14.1.10. dir:__call()
At every invocation will return one file (nil when done).
10.14.1.11. dir:close()
Closes the directory.
Returns
version string
10.15.1.2. format_date(timestamp)
Formats an absolute timestamp into a human readable date.
Arguments
timestamp
Returns
A string with the formated date
10.15.1.3. format_time(timestamp)
Formats a relative timestamp in a human readable form.
Arguments
timestamp
141
Returns
A string with the formated time
10.15.1.4. report_failure(text)
Reports a failure to the user.
Arguments
text
10.15.1.5. critical()
Will add a log entry with critical severity.
Arguments
Objects to be printed
10.15.1.6. warn()
Will add a log entry with warn severity.
Arguments
Objects to be printed
10.15.1.7. message()
Will add a log entry with message severity.
Arguments
Objects to be printed
10.15.1.8. info()
Will add a log entry with info severity.
Arguments
Objects to be printed
10.15.1.9. debug()
Will add a log entry with debug severity.
Arguments
Objects to be printed
10.15.1.10. loadfile(filename)
Luas loadfile() has been modified so that if a file does not exist in the current directory it will look
for it in wiresharks user and system directories.
Arguments
filename
142
10.15.1.11. dofile(filename)
Luas dofile() has been modified so that if a file does not exist in the current directory it will look for
it in wiresharks user and system directories.
Arguments
filename
Arguments
argument
Argument
action (optional)
Action
10.16.1. Int64
Int64 represents a 64 bit signed integer.
For details, see http://wiki.wireshark.org/LuaAPI/Int64.
Arguments
string
endian (optional)
Returns
The Int64 object created, or nil on failure.
Arguments
value (optional)
143
highvalue (optional)
If this is a number and the first argument was a number, then the
first will be treated as a lower 32-bits, and this is the high-order
32 bit number.
Returns
The new Int64 object.
10.16.1.3. Int64.max()
Gets the max possible value.
Since: 1.11.3
Returns
The new Int64 object of the max value.
10.16.1.4. Int64.min()
Gets the min possible value.
Since: 1.11.3
Returns
The new Int64 object of the min value.
10.16.1.5. Int64.fromhex(hex)
Creates an Int64 object from the given hex string.
Since: 1.11.3
Arguments
hex
Returns
The new Int64 object.
10.16.1.6. int64:encode([endian])
Encodes the Int64 number into an 8-byte Lua string, using given endianness.
Since: 1.11.3
Arguments
endian (optional)
Returns
The Lua string.
10.16.1.7. int64:__call()
Creates a Int64 Object.
144
Since: 1.11.3
Returns
The new Int64 object.
10.16.1.8. int64:tonumber()
Returns a Lua number of the Int64 value - this may lose precision.
Since: 1.11.3
Returns
The Lua number.
10.16.1.9. int64:tohex([numbytes])
Returns a hex string of the Int64 value.
Since: 1.11.3
Arguments
numbytes (optional)
Returns
The string hex.
10.16.1.10. int64:higher()
Returns a Lua number of the higher 32-bits of the Int64 value. (negative Int64 will return a
negative Lua number).
Since: 1.11.3
Returns
The Lua number.
10.16.1.11. int64:lower()
Returns a Lua number of the lower 32-bits of the Int64 value. (always positive).
Since: 1.11.3
Returns
The Lua number.
10.16.1.12. int64:__tostring()
Converts the Int64 into a string of decimal digits.
Returns
The Lua string.
145
10.16.1.13. int64:__unm()
Returns the negative of the Int64, in a new Int64.
Since: 1.11.3
Returns
The new Int64.
10.16.1.14. int64:__add()
Adds two Int64 together and returns a new one (this may wrap the value).
Since: 1.11.3
10.16.1.15. int64:__sub()
Subtracts two Int64 and returns a new one (this may wrap the value).
Since: 1.11.3
10.16.1.16. int64:__mul()
Multiplies two Int64 and returns a new one (this may truncate the value).
Since: 1.11.3
10.16.1.17. int64:__div()
Divides two Int64 and returns a new one (integer divide, no remainder). Trying to divide by zero
results in a Lua error.
Since: 1.11.3
Returns
The Int64 object.
10.16.1.18. int64:__mod()
Divides two Int64 and returns a new one of the remainder. Trying to modulo by zero results in a
Lua error.
Since: 1.11.3
Returns
The Int64 object.
10.16.1.19. int64:__pow()
The first Int64 is taken to the power of the second Int64, returning a new one (this may truncate
the value).
Since: 1.11.3
Returns
The Int64 object.
146
10.16.1.20. int64:__eq()
Returns true if both Int64 are equal.
Since: 1.11.3
10.16.1.21. int64:__lt()
Returns true if first Int64 < second.
Since: 1.11.3
10.16.1.22. int64:__le()
Returns true if first Int64 second.
Since: 1.11.3
10.16.1.23. int64:bnot()
Returns a Int64 of the bitwise not operation.
Since: 1.11.3
Returns
The Int64 object.
10.16.1.24. int64:band()
Returns a Int64 of the bitwise and operation, with the given number/Int64/UInt64. Note that
multiple arguments are allowed.
Since: 1.11.3
Returns
The Int64 object.
10.16.1.25. int64:bor()
Returns a Int64 of the bitwise or operation, with the given number/Int64/UInt64. Note that
multiple arguments are allowed.
Since: 1.11.3
Returns
The Int64 object.
10.16.1.26. int64:bxor()
Returns a Int64 of the bitwise xor operation, with the given number/Int64/UInt64. Note that
multiple arguments are allowed.
Since: 1.11.3
Returns
The Int64 object.
147
10.16.1.27. int64:lshift(numbits)
Returns a Int64 of the bitwise logical left-shift operation, by the given number of bits.
Since: 1.11.3
Arguments
numbits
Returns
The Int64 object.
10.16.1.28. int64:rshift(numbits)
Returns a Int64 of the bitwise logical right-shift operation, by the given number of bits.
Since: 1.11.3
Arguments
numbits
Returns
The Int64 object.
10.16.1.29. int64:arshift(numbits)
Returns a Int64 of the bitwise arithmetic right-shift operation, by the given number of bits.
Since: 1.11.3
Arguments
numbits
Returns
The Int64 object.
10.16.1.30. int64:rol(numbits)
Returns a Int64 of the bitwise left rotation operation, by the given number of bits (up to 63).
Since: 1.11.3
Arguments
numbits
Returns
The Int64 object.
10.16.1.31. int64:ror(numbits)
Returns a Int64 of the bitwise right rotation operation, by the given number of bits (up to 63).
Since: 1.11.3
148
Arguments
numbits
Returns
The Int64 object.
10.16.1.32. int64:bswap()
Returns a Int64 of the bytes swapped. This can be used to convert little-endian 64-bit numbers to
big-endian 64 bit numbers or vice versa.
Since: 1.11.3
Returns
The Int64 object.
10.16.2. UInt64
UInt64 represents a 64 bit unsigned integer, similar to Int64.
For details, see: http://wiki.wireshark.org/LuaAPI/Int64.
Arguments
string
endian (optional)
Returns
The UInt64 object created, or nil on failure.
Arguments
value (optional)
highvalue (optional)
If this is a number and the first argument was a number, then the
first will be treated as a lower 32-bits, and this is the high-order
32-bit number.
Returns
The new UInt64 object.
149
10.16.2.3. UInt64.max()
Gets the max possible value.
Since: 1.11.3
Returns
The max value.
10.16.2.4. UInt64.min()
Gets the min possible value (i.e., 0).
Since: 1.11.3
Returns
The min value.
10.16.2.5. UInt64.fromhex(hex)
Creates a UInt64 object from the given hex string.
Since: 1.11.3
Arguments
hex
Returns
The new UInt64 object.
10.16.2.6. uint64:encode([endian])
Encodes the UInt64 number into an 8-byte Lua binary string, using given endianness.
Since: 1.11.3
Arguments
endian (optional)
Returns
The Lua binary string.
10.16.2.7. uint64:__call()
Creates a UInt64 Object.
Since: 1.11.3
Returns
The new UInt64 object.
150
10.16.2.8. uint64:tonumber()
Returns a Lua number of the UInt64 value - this may lose precision.
Since: 1.11.3
Returns
The Lua number.
10.16.2.9. uint64:__tostring()
Converts the UInt64 into a string.
Returns
The Lua string.
10.16.2.10. uint64:tohex([numbytes])
Returns a hex string of the UInt64 value.
Since: 1.11.3
Arguments
numbytes (optional)
Returns
The string hex.
10.16.2.11. uint64:higher()
Returns a Lua number of the higher 32-bits of the UInt64 value.
Returns
The Lua number.
10.16.2.12. uint64:lower()
Returns a Lua number of the lower 32-bits of the UInt64 value.
Returns
The Lua number.
10.16.2.13. uint64:__unm()
Returns the UInt64, in a new UInt64, since unsigned integers cant be negated.
Since: 1.11.3
Returns
The UInt64 object.
151
10.16.2.14. uint64:__add()
Adds two UInt64 together and returns a new one (this may wrap the value).
Since: 1.11.3
10.16.2.15. uint64:__sub()
Subtracts two UInt64 and returns a new one (this may wrap the value).
Since: 1.11.3
10.16.2.16. uint64:__mul()
Multiplies two UInt64 and returns a new one (this may truncate the value).
Since: 1.11.3
10.16.2.17. uint64:__div()
Divides two UInt64 and returns a new one (integer divide, no remainder). Trying to divide by zero
results in a Lua error.
Since: 1.11.3
Returns
The UInt64 result.
10.16.2.18. uint64:__mod()
Divides two UInt64 and returns a new one of the remainder. Trying to modulo by zero results in
a Lua error.
Since: 1.11.3
Returns
The UInt64 result.
10.16.2.19. uint64:__pow()
The first UInt64 is taken to the power of the second UInt64/number, returning a new one (this
may truncate the value).
Since: 1.11.3
Returns
The UInt64 object.
10.16.2.20. uint64:__eq()
Returns true if both UInt64 are equal.
Since: 1.11.3
10.16.2.21. uint64:__lt()
Returns true if first UInt64 < second.
152
Since: 1.11.3
10.16.2.22. uint64:__le()
Returns true if first UInt64 second.
Since: 1.11.3
10.16.2.23. uint64:bnot()
Returns a UInt64 of the bitwise not operation.
Since: 1.11.3
Returns
The UInt64 object.
10.16.2.24. uint64:band()
Returns a UInt64 of the bitwise and operation, with the given number/Int64/UInt64. Note that
multiple arguments are allowed.
Since: 1.11.3
Returns
The UInt64 object.
10.16.2.25. uint64:bor()
Returns a UInt64 of the bitwise or operation, with the given number/Int64/UInt64. Note that
multiple arguments are allowed.
Since: 1.11.3
Returns
The UInt64 object.
10.16.2.26. uint64:bxor()
Returns a UInt64 of the bitwise xor operation, with the given number/Int64/UInt64. Note that
multiple arguments are allowed.
Since: 1.11.3
Returns
The UInt64 object.
10.16.2.27. uint64:lshift(numbits)
Returns a UInt64 of the bitwise logical left-shift operation, by the given number of bits.
Since: 1.11.3
Arguments
numbits
153
Returns
The UInt64 object.
10.16.2.28. uint64:rshift(numbits)
Returns a UInt64 of the bitwise logical right-shift operation, by the given number of bits.
Since: 1.11.3
Arguments
numbits
Returns
The UInt64 object.
10.16.2.29. uint64:arshift(numbits)
Returns a UInt64 of the bitwise arithmetic right-shift operation, by the given number of bits.
Since: 1.11.3
Arguments
numbits
Returns
The UInt64 object.
10.16.2.30. uint64:rol(numbits)
Returns a UInt64 of the bitwise left rotation operation, by the given number of bits (up to 63).
Since: 1.11.3
Arguments
numbits
Returns
The UInt64 object.
10.16.2.31. uint64:ror(numbits)
Returns a UInt64 of the bitwise right rotation operation, by the given number of bits (up to 63).
Since: 1.11.3
Arguments
numbits
Returns
The UInt64 object.
154
10.16.2.32. uint64:bswap()
Returns a UInt64 of the bytes swapped. This can be used to convert little-endian 64-bit numbers to
big-endian 64 bit numbers or vice versa.
Since: 1.11.3
Returns
The UInt64 object.
155
Note
Using i, I, h, H, l, L, f, and T is strongly discouraged, as those sizes are systemdependent. Use the explicitly sized variants instead, such as i4 or E.
Note
Unpacking of i/I is done to a Lua number, a double-precision floating point, so
unpacking a 64-bit field (i8/I8) will lose precision. Use e/E to unpack into a Wireshark
Int64/UInt64 object instead.
10.17.1. Struct
10.17.1.1. Struct.pack(format, value)
Returns a string containing the values arg1, arg2, etc. packed/encoded according to the format string.
Arguments
format
156
value
Returns
The packed binary Lua string, plus any positions due to = being used in format.
Arguments
format
struct
begin (optional)
Returns
One or more values based on format, plus the position it stopped unpacking.
10.17.1.3. Struct.size(format)
Returns the length of a binary string that would be consumed/handled by the given format string.
Arguments
format
Returns
The size number
10.17.1.4. Struct.values(format)
Returns the number of Lua values contained in the given format string. This will be the number of
returned values from a call to Struct.unpack() not including the extra return value of offset position.
(i.e., Struct.values() does not count that extra return value) This will also be the number of arguments
Struct.pack() expects, not including the format string argument.
Arguments
format
Returns
The number of values
Arguments
bytestring
157
lowercase (optional)
separator (optional)
Returns
The Lua hex-ascii string
Arguments
hexbytes
separator (optional)
Returns
The Lua binary string
158
10.18.1. GRegex
GLib Regular Expressions based on PCRE.
Since: 1.11.3
10.18.1.1. Notes
All functions that take a regular expression pattern as an argument will generate an error if that pattern
is found invalid by the regex library.
All functions that take a string-type regex argument accept a compiled regex too. In this case, the
compile flags argument is ignored (should be either supplied as nils or omitted).
The capture flag argument cf may also be supplied as a string, whose characters stand for compilation
flags. Combinations of the following characters (case sensitive) are supported:
i = G_REGEX_CASELESS - Letters in the pattern match both upper- and lowercase letters. This
option can be changed within a pattern by a (?i) option setting.
m = G_REGEX_MULTILINE - By default, GRegex treats the strings as consisting of a single line
of characters (even if it actually contains newlines). The start of line metacharacter (^) matches
only at the start of the string, while the end of line metacharacter ($) matches only at the end of
the string, or before a terminating newline (unless G_REGEX_DOLLAR_ENDONLY is set). When
G_REGEX_MULTILINE is set, the start of line and end of line constructs match immediately
following or immediately before any newline in the string, respectively, as well as at the very start
and end. This can be changed within a pattern by a (?m) option setting.
s = G_REGEX_DOTALL - A dot metacharater (.) in the pattern matches all characters, including
newlines. Without it, newlines are excluded. This option can be changed within a pattern by a ("?
s") option setting.
x = G_REGEX_EXTENDED - Whitespace data characters in the pattern are totally ignored except
when escaped or inside a character class. Whitespace does not include the VT character (code 11).
In addition, characters between an unescaped # outside a character class and the next newline
character, inclusive, are also ignored. This can be changed within a pattern by a (?x) option setting.
U = G_REGEX_UNGREEDY - Inverts the greediness of the quantifiers so that they are not
greedy by default, but become greedy if followed by ?. It can also be set by a (?U) option setting
within the pattern.
10.18.1.2. GRegex.new(pattern)
Compiles regular expression pattern into a regular expression object whose internal representation is
corresponding to the library used. The returned result then can be used by the methods, e.g. match,
exec, etc. Regular expression objects are automatically garbage collected.
Since: 1.11.3
Arguments
pattern
Returns
The compiled regular expression (a userdata object)
Errors
A malformed pattern generates a Lua error
159
10.18.1.3. GRegex.flags([table])
Returns a table containing the numeric values of the constants defined by the regex library, with the
keys being the (string) names of the constants. If the table argument is supplied then it is used as the
output table, otherwise a new table is created. The constants contained in the returned table can then
be used in most functions and methods where compilation flags or execution flags can be specified.
They can also be used for comparing with return codes of some functions and methods for determining
the reason of failure.
Since: 1.11.3
Arguments
table (optional)
Returns
A table filled with the results.
10.18.1.4. GRegex.compile_flags([table])
Returns a table containing the numeric values of the constants defined by the regex library for compile
flags, with the keys being the (string) names of the constants. If the table argument is supplied then it
is used as the output table, otherwise a new table is created.
Since: 1.11.3
Arguments
table (optional)
Returns
A table filled with the results.
10.18.1.5. GRegex.match_flags([table])
Returns a table containing the numeric values of the constants defined by the regex library for match
flags, with the keys being the (string) names of the constants. If the table argument is supplied then it
is used as the output table, otherwise a new table is created.
Since: 1.11.3
Arguments
table (optional)
Returns
A table filled with the results.
160
Arguments
subject
pattern
init (optional)
cf (optional)
ef (optional)
Returns
On success, returns all substring matches ("captures"), in the order they appear in the pattern. false is
returned for sub-patterns that did not participate in the match. If the pattern specified no captures then
the whole matched substring is returned. On failure, returns nil.
Arguments
subject
pattern
init (optional)
cf (optional)
ef (optional)
Returns
On success, returns the start point of the match (a number), the end point of the match (a number),
and all substring matches ("captures"), in the order they appear in the pattern. false is returned for subpatterns that did not participate in the match. On failure, returns nil.
Arguments
subject
pattern
init (optional)
cf (optional)
ef (optional)
161
Returns
The iterator function is called by Lua. On every iteration (that is, on every match), it returns all captures
in the order they appear in the pattern (or the entire match if the pattern specified no captures). The
iteration will continue till the subject fails to match.
Arguments
subject
pattern
repl (optional)
max (optional)
cf (optional)
ef (optional)
Returns
On success, returns the subject string with the substitutions made, the number of matches found, and
the number of substitutions made.
Arguments
subject
sep
cf (optional)
ef (optional)
Returns
The iterator function is called by Lua. On every iteration, it returns a subject section (can be an empty
string), followed by all captures in the order they appear in the sep pattern (or the entire match if the
162
sep pattern specified no captures). If there is no match (this can occur only in the last iteration), then
nothing is returned after the subject section. The iteration will continue till the end of the subject.
10.18.1.11. GRegex.version()
Returns a returns a string containing the version of the used library.
Since: 1.11.3
Returns
The version string
Arguments
subject
init (optional)
ef (optional)
Returns
On success, returns all substring matches (captures), in the order they appear in the pattern. false is
returned for sub-patterns that did not participate in the match. If the pattern specified no captures then
the whole matched substring is returned. nil is returned if the pattern did not match.
Arguments
subject
init (optional)
ef (optional)
Returns
On success, returns the start point of the match (a number), the end point of the match (a number),
and all substring matches ("captures"), in the order they appear in the pattern. false is returned for subpatterns that did not participate in the match. On failure, returns nil.
163
Since: 1.11.3
Arguments
subject
init (optional)
ef (optional)
Returns
On success, returns the start point of the first match (a number), the end point of the first match (a
number), and the offsets of substring matches (captures in Lua terminology) are returned as a third
result, in a table. This table contains false in the positions where the corresponding sub-pattern did
not participate in the match. On failure, returns nil. Example: If the whole match is at offsets 10,20
and substring matches are at offsets 12,14 and 16,19 then the function returns the following: 10, 20,
{ 12,14,16,19 }.
Arguments
subject
init (optional)
ef (optional)
Returns
On success, returns the start point of the matches found (a number), a table containing the end points
of the matches found, the longer matches first, and the number of matches found as the third return
value. On failure, returns nil. Example: If there are 3 matches found starting at offset 10 and ending
at offsets 15, 20 and 25 then the function returns the following: 10, { 25,20,15 }, 3
10.18.1.16. gregex:__tostring()
Returns a string containing debug information about the GRegex object.
Since: 1.11.3
Returns
The debug string
164
165
User Interface
GLib (A general-purpose utility library, not specific to graphical user interfaces. GLib provides
many useful data types, macros, type conversions, string utilities, file utilities, a main loop
abstraction, and so on.)
Pango (Pango is a library for internationalized text handling. It centers around the PangoLayout
object, representing a paragraph of text. Pango provides the engine for GtkTextView, GtkLabel,
GtkEntry, and other widgets that display text.)
ATK (ATK is the Accessibility Toolkit. It provides a set of generic interfaces allowing accessibility
technologies to interact with a graphical user interface. For example, a screen reader uses ATK to
discover the text in an interface and read it to blind users. GTK+ widgets have built-in support for
accessibility using the ATK framework.)
GdkPixbuf (This is a small library which allows you to create GdkPixbuf ("pixel buffer") objects
from image data or image files. Use a GdkPixbuf in combination with GtkImage to display images.)
GDK (GDK is the abstraction layer that allows GTK+ to support multiple windowing systems.
GDK provides drawing and window system facilities on X11, Windows, and the Linux framebuffer
device.)
166
User Interface
167
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
168
169
170
171
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the
to attach them to the start of each source file
convey the exclusion of warranty; and each file
the "copyright" line and a pointer to where the
program. It is safest
to most effectively
should have at least
full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
172