1[[ChapterSources]]
2
3== Work with the Wireshark sources
4
5[[ChSrcIntro]]
6
7=== Introduction
8
9This chapter will explain how to work with the Wireshark source code.
10It will show you how to:
11
12* Get the source
13
14* Compile it on your machine
15
16* Submit changes for inclusion in the official release
17
18This chapter will not explain the source file contents in detail,
19such as where to find specific functionality. This is done in
20<<ChCodeOverview>>.
21
22[[ChSrcGitRepository]]
23
24=== The Wireshark Git repository
25
26https://git-scm.com/[Git] is used to keep track of the changes made to the Wireshark source code.
27The official repository is hosted at {wireshark-gitlab-project-url}[GitLab], and incoming changes are evaluated and reviewed there.
28For more information on GitLab see https://docs.gitlab.com/ce/gitlab-basics/[their documentation].
29
30.Why Git?
31
32Git is a fast, flexible way of managing source code.
33It allows large scale distributed development and ensures data integrity.
34
35.Why GitLab?
36
37GitLab makes it easy to contribute.
38You can make changes locally and push them to your own work area at gitlab.com, or if your change is minor you can make changes entirely within your web browser.
39
40.Historical trivia: GitLab is the *fourth* iteration of our source code repository and code review system.
41
42Wireshark originally used https://www.nongnu.org/cvs/[Concurrent Versions System] (CVS) and migrated to https://subversion.apache.org/[Subversion] in July 2004.
43We migrated from Subversion to Git and https://www.gerritcodereview.com/[Gerrit] in January 2014, and from Gerrit to GitLab in August 2020.
44
45Using Wireshark’s GitLab project you can:
46
47* Keep your private sources up to date with very little effort.
48* Receive notifications about code reviews and issues.
49* Get the source files from any previous release (or any other point in time).
50* Browse and search the source code using a web interface.
51* See which person changed a specific piece of code.
52
53[[ChSrcWebInterface]]
54
55==== Git Naming Conventions
56
57Like most revision control systems, Git uses
58https://en.wikipedia.org/wiki/Branching_%28revision_control%29[branching]
59to manage different copies of the source code and allow parallel development.
60Wireshark uses the following branch naming conventions:
61
62.master.
63Main feature development and odd-numbered development releases.
64
65.release-x.y, master-x.y.
66Stable release maintenance. For example, release-3.4 is used to manage the 3.4.x official releases.
67
68Tags for major releases and release candidates consist of a “v” followed by a version number such as “v3.2.1” or “v3.2.3rc0”.
69Major releases additionally have a tag prefixed with “wireshark-” followed by a version number, such as “wireshark-3.2.0”.
70
71[[ChSrcSVNWeb]]
72// Retain ChSrcSVNWeb for backward compatibility
73[[ChSrcGitWeb]]
74=== Browsing And Searching The Source Code
75
76If you need a quick look at the Wireshark source code you can browse the repository files in GitLab at
77
78{wireshark-code-browse-url}
79
80You can view commit logs, branches, and tags, find files and search the repository contents.
81You can also download individual files.
82
83[[ChSrcObtain]]
84=== Obtaining The Wireshark Sources
85
86There are two primary ways to obtain Wireshark’s source code: Git and compressed .tar archives.
87Each is described in more detail below.
88We recommend using Git for day to day development, particularly if you wish to contribute changes back to the project.
89The age mentioned in the following sections indicates the age of the most recent change in that set of the sources.
90
91[[ChSrcAnon]]
92// Retain ChSrcAnon for backward compatibility
93[[ChSrcGit]]
94==== Git Over SSH Or HTTPS
95
96This method is strongly recommended for day to day development.
97
98You can use a Git client to download the source code from Wireshark’s code review system.
99Anyone can clone from the anonymous HTTP git URL:
100
101{wireshark-git-anonhttp-url}
102
103If you have a GitLab account you can also clone using SSH:
104
105{wireshark-git-ssh-url}
106
107If wish to make changes to Wireshark you must create a GitLab account, create a fork of the official Wireshark repository, update your fork, and create a merge request.
108See <<ChSrcContribute>> for details.
109
110The following example shows how to get up and running on the command line.
111See <<ChToolsGit>> for information on installing and configuring graphical Git clients.
112
113. Now on to the command line.
114First, make sure `git` works:
115+
116--
117[source,sh]
118----
119$ git --version
120----
121--
122
123. If this is your first time using Git, make sure your username and email address are configured.
124This is particularly important if you  plan on uploading changes:
125+
126--
127[source,sh]
128----
129$ git config --global user.name "Henry Perry"
130$ git config --global user.email henry.perry@example.com
131----
132--
133
134. Next, clone the Wireshark repository:
135+
136--
137[source,sh]
138----
139# If you have a GitLab account, you can use the SSH URL:
140$ git clone -o upstream git@gitlab.com:wireshark/wireshark.git
141# If you don't you can use the HTTPS URL:
142$ git clone -o upstream https://gitlab.com/wireshark/wireshark.git
143# You can speed up cloning in either case by adding --shallow-since=1year or --depth=5000.
144----
145The clone only has to be done once.
146This will copy all the sources (including directories) from the server to your machine and check out the latest version.
147
148The `-o upstream` flag uses the origin name “upstream” for the repository instead of the default “origin” as described in the https://docs.gitlab.com/ee/user/project/repository/forking_workflow.html[GitLab documentation].
149
150Cloning may take some time depending on the speed of your internet connection.
151
152The `--shallow-since=1year` option limits cloned commits to the last 1 year.
153
154The `--depth=5000` option limits cloned commits to the last 5000.
155--
156
157[[ChSrcBuildbot]]
158==== Development Snapshots
159
160This method is useful for one-off builds or if Git is inaccessible (e.g. because of a restrictive firewall).
161
162The Buildbot server automatically generates development packages, including source packages.
163They can be found at {wireshark-snapshots-url}.
164Packages are available for recent commits in the master branch and each release branch.
165
166[[ChSrcReleased]]
167==== Official Source Releases
168
169This method is recommended for building downstream release packages.
170
171The official source releases can be found at {wireshark-download-url}.
172You should use these sources if you want to build Wireshark on your platform based on an official release with minimal or no changes, such as Linux distribution packages.
173
174[[ChSrcUpdating]]
175=== Update Your Wireshark Sources
176
177After you've obtained the Wireshark sources for the first time,
178you might want to keep them in sync with the sources at the upstream
179Git repository.
180
181[TIP]
182.Take a look at the Buildbot first
183====
184As development evolves, the Wireshark sources are compilable
185most of the time -- but not always. You should take a look at
186{wireshark-buildbot-url} before fetching or pulling to make
187sure the builds are in good shape.
188====
189
190[[ChSrcAnonUpdate]]
191// Retain ChSrcAnonUpdate for backward compatibility
192[[ChSrcGitUpdate]]
193
194==== Update Using Git
195
196From time to time you will likely want to synchronize your master branch with the upstream repository.
197You can do so by running:
198
199[source,sh]
200----
201$ git pull --rebase upstream master
202----
203
204[[ChSrcBuildFirstTime]]
205=== Build Wireshark
206
207The sources contain several documentation files. It’s a good idea to read these
208files first. After obtaining the sources, tools and libraries, the first place
209to look at is _doc/README.developer_. Inside you will find the latest
210information for Wireshark development for all supported platforms.
211
212.Build Wireshark before changing anything
213[TIP]
214====
215It is a very good idea to first test your complete build environment
216(including running and debugging Wireshark) before making any changes
217to the source code (unless otherwise noted).
218====
219
220Building Wireshark for the first time depends on your platform.
221
222==== Building on Unix
223
224Follow the build procedure in <<ChSetupUNIX>> to build Wireshark.
225
226==== Windows Native
227
228Follow the build procedure in <<ChSetupWin32>> to build Wireshark.
229
230After the build process has successfully finished, you should find a
231`Wireshark.exe` and some other files in the `run\RelWithDebInfo` directory.
232
233[[ChSrcRunFirstTime]]
234=== Run Your Version Of Wireshark
235
236
237[TIP]
238.Beware of multiple Wiresharks
239====
240An already installed Wireshark may interfere with your newly generated
241version in various ways. If you have any problems getting your Wireshark
242running the first time, it might be a good idea to remove the previously
243installed version first.
244====
245
246[[ChSrcRunFirstTimeUnix]]
247==== Unix-Like Platforms
248
249After a successful build you can run Wireshark right from the `run` directory.
250There's no need to install it first.
251
252[source,sh]
253----
254$ ./run/wireshark
255----
256
257There’s no need to run Wireshark as root user, but depending on your platform you might not be able to capture.
258Running Wireshark this way can be helpful since debugging output will be displayed in your terminal.
259You can also change Wireshark’s behavior by setting various environment variables.
260See the {wireshark-man-page-url}wireshark.html#ENVIRONMENT-VARIABLES[ENVIRONMENT VARIABLES] section of the Wireshark man page for more details.
261
262[[ChSrcRunFirstTimeWin32]]
263==== Windows Native
264
265By default the CMake-generated Visual {cpp} project places all of the files necessary to run Wireshark in the subdirectory `run\RelWithDebInfo`.
266As with the Unix-like build described above, you can run Wireshark from the build directory without installing it first.
267
268[source,cmd]
269----
270> .\run\RelWithDebInfo\Wireshark
271----
272
273
274[[ChSrcDebug]]
275=== Debug Your Version Of Wireshark
276
277[[ChSrcUnixDebug]]
278==== Unix-Like Platforms
279
280You can debug using command-line debuggers such as gdb, dbx, or lldb.
281If you prefer a graphic debugger, you can use an IDE or debugging frontend
282such as Qt Creator, CLion, or Eclipse.
283
284Additional traps can be set on Wireshark by setting the `WIRESHARK_LOG_FATAL`
285environment variable:
286
287[source,sh]
288----
289$ WIRESHARK_LOG_FATAL=critical gdb wireshark
290----
291
292If you're encountering memory safety bugs, you might want to build with
293https://en.wikipedia.org/wiki/AddressSanitizer[Address Sanitizer] so that
294Wireshark will immediately alert you to any detected issues.
295
296[source,sh]
297----
298$ cmake .. -G Ninja -DENABLE_ASAN=1
299----
300
301See https://developer.gnome.org/glib/stable/glib-running.html[]
302
303[[ChSrcWin32Debug]]
304==== Windows Native
305
306You can debug using the Visual Studio Debugger or WinDbg.  See the section
307on using the <<ChToolsDebugger, Debugger Tools>>.
308
309[[ChSrcChange]]
310=== Make Changes To The Wireshark Sources
311
312There are several reasons why you might want to change Wireshark’s sources:
313
314* Add support for a new protocol (i.e., add a new dissector)
315
316* Change or extend an existing dissector
317
318* Fix a bug
319
320* Implement a glorious new feature
321
322Wireshark’s developers work on a variety of different platforms and use a variety of different development environments.
323Although we we don't enforce or recommend a particular environment, your editor should support https://editorconfig.org/[EditorConfig] in order to make sure you pick up the correct indentation style for any files that you might edit.
324
325The internal structure of the Wireshark sources are described in <<PartDevelopment>>.
326
327.Ask the {wireshark-dev-list-email} mailing list before you start a new development task.
328[TIP]
329====
330If you have an idea what you want to add or change it’s a good idea to
331contact the developer mailing list
332(see <<ChIntroMailingLists>>)
333and explain your idea. Someone else might already be working on the same
334topic, so a duplicated effort can be reduced. Someone might also give you tips that
335should be thought about (like side effects that are sometimes very
336hard to see).
337====
338
339// XXX - Add a section on branching.
340
341[[ChSrcContribute]]
342=== Contribute Your Changes
343
344If you have finished changing the Wireshark sources to suit your needs, you might want to contribute your changes back to the Wireshark community.
345You gain the following benefits by contributing your improvements:
346
347.It’s the right thing to do.
348Other people who find your contributions useful will appreciate them, and you will know that you have helped people in the same way that the developers of Wireshark have helped you.
349
350.You get free enhancements.
351By making your code public, other developers have a chance to make improvements, as there’s always room for improvements.
352In addition someone may implement advanced features on top of your code, which can be useful for yourself too.
353
354You save time and effort.
355The maintainers and developers of Wireshark will maintain your code as well, updating it when API changes or other changes are made, and generally keeping it in tune with what is happening with Wireshark.
356So if Wireshark is updated (which is done often), you can get a new Wireshark version from the website and your changes will already be included without any effort for you.
357
358There’s no direct way to push changes to the {wireshark-gitlab-project-url}[main repository].
359Only a few people are authorised to actually make changes to the source code (check-in changed files).
360If you want to submit your changes, you should upload them to the code review system at {wireshark-code-review-url}.
361This requires you to set up git as described at <<ChSrcGit>>.
362
363[[ChSrcCreatingMergeRequests]]
364==== Creating Merge Requests
365
366// To do:
367// - Note that you can mirror your fork: https://about.gitlab.com/blog/2016/12/01/how-to-keep-your-fork-up-to-date-with-its-origin/
368// - Mention CLI utilities.
369
370GitLab uses a https://docs.gitlab.com/ee/user/project/repository/forking_workflow.html[forking workflow], which looks like this:
371
372.GitLab Workflow
373image::wsdg_graphics/git-triangular-workflow.svg[]
374
375In the diagram above, your fork can created by pressing the “Fork” button at {wireshark-gitlab-project-url}.
376Your local repository can be created as described in <<ChSrcGit>>.
377You only need to do this once.
378You should pull from the main repository on a regular basis in order to ensure that your sources are current.
379You should push any time you want to make a merge request or otherwise make your code public.
380The “Pull”, “Push”, and “Merge Request” parts of the workflow are important, so let’s look at them in more detail.
381
382First, you need to set up your environment.
383For the steps below we’ll pretend that your username is “henry.perry”.
384
385. Sign in to {wireshark-gitlab-project-url} by clicking “Sign in / Register” in the upper right corner of the web page and following the login instructions.
386
387. https://docs.gitlab.com/ce/ssh/[Add an SSH key to your account] as described in the GitLab documentation.
388
389. Make sure you have a clone of the main repository as described in <<ChSrcGit>>.
390
391. Create your own personal fork of the Wireshark project by https://docs.gitlab.com/ee/user/project/repository/forking_workflow.html[pressing the “Fork” button] at {wireshark-gitlab-project-url}.
392
393. Add a remote for your personal repository.
394The main repository remote is named “upstream”, so we'll name this one “downstream”.
395+
396--
397[source,sh]
398----
399$ git remote add downstream git@gitlab.com:henry.perry/wireshark.git
400----
401--
402
403. Double-check your remotes:
404+
405--
406[source,sh]
407----
408$ git remote -v
409$ downstream	git@gitlab.com:henry.perry/wireshark.git (fetch)
410$ downstream	git@gitlab.com:henry.perry/wireshark.git (push)
411$ upstream	git@gitlab.com:wireshark/wireshark.git (fetch)
412$ upstream	git@gitlab.com:wireshark/wireshark.git (push)
413----
414--
415
416Before you begin it’s a good idea to synchronize your local repository with the main repository.
417This is the *Pull* part of the workflow.
418You should do this periodically in order to stay up to date and avoid merge conflicts later on.
419
420. Fetch and optionally apply the latest changes.
421+
422--
423[source,sh]
424----
425# Fetch changes from upstream and apply them to the current branch...
426$ git pull --rebase upstream master
427# ...or fetch changes and leave the current branch alone
428$ git fetch upstream
429----
430--
431
432Now you’re ready to create a merge request (the *Push* and *Merge Request* parts of the workflow above).
433
434. First, create a branch for your change:
435+
436--
437[source,sh]
438----
439$ git checkout -b my-glorious-new-feature upstream/master
440----
441--
442
443. Write some code!
444See <<ChSrcGoodPatch>> and <<ChSrcCodeRequirements>> for details.
445
446. Commit your changes.
447See <<ChSrcGoodCommitMessage>> for details.
448+
449--
450[source,sh]
451----
452$ git commit -a
453----
454--
455
456. Push your changes to your personal repository.
457+
458--
459[source,sh]
460----
461$ git push downstream HEAD
462----
463--
464
465. Go to {wireshark-merge-request-url}.
466You should see a https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html#create-merge-request-button[“Create merge request”] button.
467Press it.
468
469. In the merge request page, make sure “Allow commits from members who can merge to the target branch” is selected so that core developers can rebase your change. You might want to select “Delete source branch when merge request is accepted” as well. Click the “Submit merge request” button.
470
471// XXX Add command line instructions for one or more of the following:
472// https://docs.gitlab.com/ee/user/project/push_options.html
473// https://github.com/zaquestion/lab - Go (single binary).
474// https://invent.kde.org/sdk/git-lab - Developed by the KDE team.
475// https://github.com/vishwanatharondekar/gitlab-cli - Might work well for people who don't mind using NPM.
476
477
478[[ChSrcUpdatingMergeRequests]]
479==== Updating Merge Requests
480
481At this point various automated tests will be run and someone will review your change.
482If you need to make changes you can do so by force-pushing it to the same branch in your personal repository.
483
484. Push your changes to your personal repository.
485+
486--
487[source,sh]
488----
489# First, make sure you're on the right branch.
490$ git status
491On branch my-glorious-new-feature
492----
493--
494
495. Update your code.
496
497. Push your changes to your personal repository.
498+
499--
500[source,sh]
501----
502# Modify the current commit and force-push...
503$ git commit --amend ...
504$ git push downstream +HEAD
505# ...or keep the current commit as-is add another commit on top of it
506$ git commit ...
507$ git push downstream HEAD
508----
509The `+` sign is shorthand for forcing the push (`-f`).
510--
511
512[[ChSrcGoodPatch]]
513==== Some Tips For A Good Patch
514
515Some tips that will make the merging of your changes into Git much more likely
516(and you want exactly that, don't you?):
517
518.Use the latest Git sources.
519It’s a good idea to work with the same sources that are used by the other developers.
520This usually makes it much easier to apply your patch.
521For information about the different ways to get the sources, see <<ChSrcObtain>>.
522
523.Update your sources just before making a patch.
524For the same reasons as the previous point.
525
526.Inspect your patch carefully.
527Run `git diff` or `git show` as appropriate and make sure you aren't adding, removing, or omitting anything you shouldn't.
528
529.Give your branch a brief but descriptive name.
530Short, specific names such as _snowcone-machine-protocol_ are preferred.
531
532.Don't put unrelated things into one large change.
533Merge requests should be limited in scope.
534For example, updates to the Snowcone Machine Protocol dissector and the Coloring Rules dialog box should be in separate merge requests.
535
536In general, making it easier to understand and apply your patch by one of the maintainers will make it much more likely (and faster) that it will actually be applied.
537
538.Thank you in advance for your patience.
539Wireshark is a volunteer effort.
540As a result, we can’t guarantee a quick turnaround time.
541
542.Preview the final product.
543Wireshark’s GitLab CI jobs are disabled by default for forks, but if you need to test any CI jobs you can do so under the “Pipelines” section in your repository.
544For example, if your change might affect Debian (apt) packaging you can run the “build:debian-stable” job.
545
546[[ChSrcGoodCommitMessage]]
547==== Writing a Good Commit Message
548
549When running `git commit`, you will be prompted to describe your change.
550Here are some guidelines on how to make that message more useful to other people (and to scripts that may try to parse it):
551
552.Provide a brief description (under 60 characters or so) of the change in the first line.
553If the change is specific to a single protocol, start this line with the abbreviated name of the protocol and a colon.
554If the change is not yet complete prefix the line with “WIP:” to inform this change not to be submitted yet.
555This be removed when the change is ready to be merged.
556
557.Insert a single blank line after the first line.
558This is required by various formatting tools and helpful to humans.
559
560.Provide a detailed description of the change in the lines that follow.
561Break paragraphs where needed.
562Limit each line to 80 characters.
563
564You can also reference and close issues in a commit message by prefixing the issue number with a https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically[number sign].
565For example, “closes #5” will close issue number 5.
566
567Putting all that together, we get the following example:
568
569[source]
570----
571MIPv6: Fix dissection of Service Selection Identifier
572
573APN field is not encoded as a dotted string so the first character is not a
574length. Closes #10323.
575----
576
577[[ChSrcCodeRequirements]]
578
579==== Code Requirements
580
581To ensure Wireshark’s code quality and to reduce friction in the code review process, there are some things you should consider before submitting a patch:
582
583.Follow the Wireshark source code style guide.
584Wireshark runs on many platforms, and can be compiled with a number of different compilers.
585It’s easy to write code that compiles on your machine, but doesn’t compile elsewhere.
586The guidelines at <<ChCodeStyle>> describe the techniques and APIs that you can use to write high-quality, portable, and maintainable code in our environment.
587
588.Submit dissectors as built-in whenever possible.
589Developing a new dissector as a plugin can make compiling and testing quicker, but it’s usually best to convert it to built-in before submitting for review.
590This reduces the number of files that must be installed with Wireshark and ensures your dissector will be available on all platforms.
591
592Dissectors vary, so this is not a hard-and-fast rule.
593Most dissectors are single C modules that can easily be put into “the big pile.”
594Some (most notably ASN.1 dissectors) are generated using templates and configuration files.
595Others are split across multiple source files and are often more suitable to be placed in a separate plugin directory.
596
597.Ensure that the Wireshark Git Pre-Commit Hook is in the repository.
598In your local repository directory, there will be a __.git/hooks/__ directory, with sample git hooks for running automatic actions before and after git commands.
599You can also optionally install other hooks that you find useful.
600
601In particular, the _pre-commit_ hook will run every time you commit a change and can be used to automatically check for various errors in your code.
602The sample git pre-commit hook simply detects whitespace errors such as mixed tabs and spaces.
603To install it just remove the .sample suffix from the existing _pre-commit.sample_ file.
604
605Wireshark provides a custom pre-commit hook which does additional Wireshark-specific API and formatting checks, but it might return false positives.
606If you want to install it, copy the pre-commit file from the tools directory (`cp ./tools/pre-commit .git/hooks/`) and make sure it is executable or it will not be run.
607
608If the pre-commit hook is preventing you from committing what you believe is a valid change, you can run `git commit --no-verify` to skip running the hooks.
609Warning: using --no-verify avoids the commit-msg hook, and thus if you have setup this hook it will not run.
610
611Additionally, if your system supports symbolic links, as all UNIX-like platforms do, you can use them instead of copying files.
612Running `ln -s ../../tools/pre-commit .git/hooks` creates a symbolic link that will make the hook to be up-to-date with the current master.
613
614.Choose a compatible license.
615Wireshark is released under the {spdx-license-url}GPL-2.0-or-later.html[GPL version 2 or later], and it is strongly recommended that incoming code use that license.
616If that is not possible, it *must* use a compatible license.
617The following licenses are currently allowed:
618
619* BSD {spdx-license-url}BSD-1-Clause.html[1], {spdx-license-url}BSD-2-Clause.html[2], {spdx-license-url}BSD-3-Clause.html[3] clause
620* {spdx-license-url}GPL-3.0-or-later.html[GPL version 3 or later] *with* the https://www.gnu.org/software/bison/manual/html_node/Conditions.html[Bison parser exception]
621* {spdx-license-url}ISC.html[ISC]
622* {spdx-license-url}LGPL-2.0-or-later.html[LGPL v2 or later], including {spdx-license-url}LGPL-2.1-or-later.html[v2.1]
623* {spdx-license-url}MIT.html[MIT] / {spdx-license-url}X11.html[X11]
624* {wikipedia-main-url}Public_domain[Public domain]
625* {spdx-license-url}Zlib.html[zlib/libpng]
626
627Notable incompatible licenses include {spdx-license-url}Apache-2.0.html[Apache 2.0], {spdx-license-url}GPL-3.0-or-later.html[GPL 3.0], and {spdx-license-url}LGPL-3.0-or-later.html[LGPL 3.0].
628
629.Fuzz test your changes.
630Fuzz testing is a very effective way of finding dissector related bugs.
631In our case fuzzing involves making random changes to capture files and feeding them to TShark in order to try to make it crash or hang.
632There are tools available to automatically do this on any number of input files.
633See {wireshark-wiki-url}FuzzTesting for details.
634
635[[ChSrcUpload]]
636
637////
638==== Uploading your changes
639
640When you're satisfied with your changes (and obtained any necessary
641approval from your organization) you can upload them for review at
642{wireshark-code-review-url}. This requires a Gitlab account
643as described at <<ChSrcGitRepository>>.
644
645You need to fork your repository which will became yours, and you will have write access to it. Once
646you are done with your changes, push them to a branch of your choice (as snowcone-machine). Now in the
647Gitlab's UI a message will tell you that you created a new branch and a button to create a merge request.
648
649
650[source,sh]
651----
652$ git push https://gitlab.com/wireshark/<my.username>.git HEAD:<branchname>
653----
654
655The username `my.username` is the one which was given during registration with
656the review system.
657
658You can push using any Git client.
659
660You might get one of the following responses to your patch request:
661
662* Your patch is checked into the repository. Congratulations!
663
664* You are asked to provide additional information, capture files, or other
665  material. If you haven't fuzzed your code, you may be asked to do so.
666
667* Your patch is rejected. You should get a response with the reason for
668  rejection. Common reasons include not following the style guide, buggy or
669  insecure code, and code that won't compile on other platforms. In each case
670  you'll have to fix each problem and upload another patch.
671
672* You don't get any response to your patch. Possible reason: All
673  the core developers are busy (e.g., with their day jobs or family or other commitments) and
674  haven't had time to look at your patch. Don't worry, if
675  your patch is in the review system it won't get lost.
676
677If you're concerned, feel free to add a comment to the patch or send an email
678to the developer’s list asking for status. But please be patient: most if not
679all of us do this in our spare time.
680////
681
682[[ChSrcBackport]]
683==== Backporting A Change
684
685:example-branch: master-3.2
686When a bug is fixed in the master branch it’s sometimes desirable or necessary to backport the fix to a release branch.
687You can do this in Git by cherry-picking the change from one branch to another.
688Suppose you want to backport change 1ab2c3d4 from the master branch to {example-branch}.
689You can do so as follows:
690
691[source,sh,subs="attributes+"]
692----
693# Create a new topic branch for the backport.
694$ git checkout -b backport-g1ab2c3d4 upstream/{example-branch}
695
696# Cherry-pick the change. Include a "cherry picked from..." line.
697$ git cherry-pick -x 1ab2c3d4
698
699# If there are conflicts, fix them.
700
701# Compile and test the change.
702$ ninja
703$ ...
704
705# OPTIONAL: Add entries to docbook/release-notes.adoc.
706$EDITOR docbook/release-notes.adoc
707
708# If you made any changes, update your commit.
709git commit --amend -a
710
711# Push the change to your working repository.
712git push downstream HEAD
713----
714
715You can also cherry-pick changes in the https://docs.gitlab.com/ee/user/project/merge_requests/cherry_pick_changes.html[GitLab web UI].
716
717////
718// XXX Is this relevant any more?
719[[ChSrcPatchApply]]
720=== Apply a patch from someone else
721
722Sometimes you need to apply a patch to your private source tree. Maybe
723because you want to try a patch from someone on the developer mailing
724list, or you want to check your own patch before submitting.
725
726
727.Beware line endings
728[WARNING]
729====
730If you have problems applying a patch, make sure the line endings (CR/LF)
731of the patch and your source files match.
732====
733
734[[ChSrcPatchUse]]
735==== Using patch
736
737Given the file _new.diff_ containing a unified diff,
738the right way to call the patch tool depends on what the pathnames in
739_new.diff_ look like.
740If they're relative to the top-level source directory (for example, if a
741patch to _prefs.c_ just has _prefs.c_ as the file name) you’d run it as:
742
743[source,sh]
744----
745$ patch -p0 < new.diff
746----
747
748If they're relative to a higher-level directory, you’d replace 0 with the
749number of higher-level directories in the path, e.g. if the names are
750_wireshark.orig/prefs.c_ and
751_wireshark.mine/prefs.c_, you’d run it with:
752
753[source,sh]
754----
755$ patch -p1 < new.diff
756----
757
758If they're relative to a _subdirectory_ of the top-level
759directory, you’d run `patch` in _that_ directory and run it with `-p0`.
760
761If you run it without `-pat` all, the patch tool
762flattens path names, so that if you
763have a patch file with patches to _CMakeLists.txt_ and
764_wiretap/CMakeLists.txt_,
765it'll try to apply the first patch to the top-level
766_CMakeLists.txt_ and then apply the
767_wiretap/CMakeLists.txt_ patch to the top-level
768_CMakeLists.txt_ as well.
769
770At which position in the filesystem should the patch tool be called?
771
772If the pathnames are relative to the top-level source directory, or to a
773directory above that directory, you’d run it in the top-level source
774directory.
775
776If they're relative to a *subdirectory* -- for example,
777if somebody did a patch to _packet-ip.c_ and ran `diff` or `git diff` in
778the _epan/dissectors_ directory -- you’d run it in that subdirectory.
779It is preferred that people *not* submit patches like
780that, especially if they're only patching files that exist in multiple
781directories such as _CMakeLists.txt_.
782////
783
784[[ChSrcBinary]]
785
786=== Binary Packaging
787
788Delivering binary packages makes it much easier for the end-users to
789install Wireshark on their target system. This section will explain how
790the binary packages are made.
791
792[[ChSrcVersioning]]
793
794==== Packaging Guidelines
795
796The following guidelines should be followed by anyone creating and
797distributing third-party Wireshark packages or redistributing official
798Wireshark packages.
799
800[discrete]
801===== Spelling And Capitalization
802
803Wireshark is spelled with a capital “W”, and with everything else lower
804case. “WireShark” in particular is incorrect.
805
806[discrete]
807===== Main URL
808
809The official Wireshark project URL is https://www.wireshark.org/.
810
811[discrete]
812===== Download URLs
813
814Official packages are distributed on the main web server
815(www.wireshark.org) and a
816https://www.wireshark.org/download.html#spelunking[number of download
817mirrors]. The canonical locations for packages are in the _all_versions_
818subdirectories on each server.
819
820For example, if your packaging system links to or downloads the
821source tarball and you want to download from 1.na.dl.wireshark.org,
822use
823
824https://1.na.dl.wireshark.org/download/src/all-versions/wireshark-{wireshark-version}.tar.xz
825
826instead of
827
828https://1.na.dl.wireshark.org/download/src/wireshark-{wireshark-version}.tar.xz
829
830[discrete]
831===== Artwork
832
833Logo and icon artwork can be found in the _image_ directory in the
834distribution. This is available online at
835
836{wireshark-code-browse-url}/image
837
838[discrete]
839===== Licensing
840
841Wireshark is released under the GNU General Public License version 2 or
842later. Make sure you and your package comply with this license.
843
844[discrete]
845===== Trademarks
846
847Wireshark and the “fin” logo are registered trademarks of the Wireshark
848Foundation. Make sure you and your package comply with trademark law.
849
850[discrete]
851===== Privileges
852
853All function calls that require elevated privileges are in dumpcap.
854
855WIRESHARK CONTAINS OVER THREE MILLION LINES OF SOURCE CODE. DO NOT RUN
856THEM AS ROOT.
857
858Warnings are displayed when Wireshark and TShark are run as root.
859
860There are two <<ChToolsCMake,configure-time options>> on non-Windows
861systems that affect the privileges a normal user needs to capture
862traffic and list interfaces:
863
864-DDUMPCAP_INSTALL_OPTION=capabilities::
865Install dumpcap with cap_net_admin and cap_net_raw capabilities. Linux
866only.
867
868-DDUMPCAP_INSTALL_OPTION=suid::
869Install dumpcap setuid root.
870
871These are necessary for non-root users to be able to capture on most
872systems, e.g. on Linux or FreeBSD if the user doesn't have permissions
873to access /dev/bpf*. Setcap installation is preferred over setuid on
874Linux. If `-DDUMPCAP_INSTALL_OPTION=capabilities` is used it will
875override any setuid settings.
876
877The `-DENABLE_CAP` option is only useful when dumpcap is installed
878setuid. If it is enabled dumpcap will try to drop any setuid privileges
879it may have while retaining the `CAP_NET_ADMIN` and `CAP_NET_RAW`
880capabilities. It is enabled by default, if the Linux capabilities
881library (on which it depends) is found.
882
883Note that enabling setcap or setuid installation allows packet capture
884for ALL users on your system. If this is not desired, you can restrict
885dumpcap execution to a specific group or user. The following two examples
886show how to restrict access using setcap and setuid respectively:
887
888[source,sh]
889----
890# groupadd -g packetcapture
891# chmod 750 /usr/bin/dumpcap
892# chgrp packetcapture /usr/bin/dumpcap
893# setcap cap_net_raw,cap_net_admin+ep /usr/bin/dumpcap
894
895# groupadd -g packetcapture
896# chgrp packetcapture /usr/bin/dumpcap
897# chmod 4750 /usr/bin/dumpcap
898----
899
900[discrete]
901===== Customization
902
903Custom version information can be added by running
904`tools/make-version.pl`. If your package contains significant changes we
905recommend that you use this to differentiate it from official Wireshark
906releases.
907
908[source, sh]
909----
910tools/make-version.pl --set-release --untagged-version-extra=-{vcsinfo}-FooCorp --tagged-version-extra=-FooCorp
911----
912
913See `tools/make-version.pl` for details.
914
915The Git version corresponding to each release is in _version.h_. It's
916defined as a string. If you need a numeric definition, let us know.
917
918If you have a question not addressed here, please contact
919{wireshark-dev-list-email}.
920
921
922[[ChSrcDeb]]
923
924==== Debian: .deb Packages
925
926The Debian Package is built using dpkg-buildpackage, based on information
927found in the source tree under _debian_. See
928https://www.debian.org/doc/manuals/maint-guide/build.en.html for a
929more in-depth discussion of the build process.
930
931
932In the wireshark directory, type:
933
934[source,sh]
935----
936dpkg-buildpackage -b -us -uc -jauto
937----
938
939to build the Debian Package.
940
941[[ChSrcRpm]]
942
943==== Red Hat: .rpm Packages
944
945You can build an RPM package using the `rpm-package` target. The package
946version is derived from the current git HEAD, so you must build from a
947git checkout.
948
949The package is built using https://rpm.org/[rpmbuild], which comes as
950standard on many flavours of Linux, including Red Hat, Fedora, and
951openSUSE. The process creates a clean build environment in
952_$\{CMAKE_BINARY_DIR}/packaging/rpm/BUILD_ each time the RPM is built.
953The settings that control the build are in
954_$\{CMAKE_SOURCE_DIR}/packaging/rpm/wireshark.spec.in_. The generated
955SPEC file contains CMake flags and other settings for the RPM build
956environment. Many of these come from the parent CMake environment.
957Notable ones are:
958
959* _prefix_ is set to _CMAKE_INSTALL_PREFIX_. By default this is
960  _/usr/local_. Pass `-DCMAKE_INSTALL_PREFIX=/usr` to create a package
961  that installs into _/usr_.
962
963* Whether or not to create the “wireshark-qt” package
964  (`-DBUILD_wireshark`).
965
966* Lua, c-ares, nghttp2, and other library support (`-DENABLE_...`).
967
968* Building with Ninja (`-G Ninja`).
969
970In your build directory, type:
971
972[source,sh]
973----
974ninja rpm-package
975# ...or, if you're using GNU make...
976make rpm-package
977----
978
979to build the binary and source RPMs. When it is finished there will be a
980message stating where the built RPM can be found.
981
982.This might take a while
983[TIP]
984====
985This creates a tarball, extracts it, compiles Wireshark, and constructs
986a package. This can take quite a long time. You can speed up the process
987by using Ninja. If you're using GNU make you can add the following to
988your `~/.rpmmacros` file to enable parallel builds:
989
990----
991%_smp_mflags -j %(grep -c processor /proc/cpuinfo)
992----
993====
994
995Building the RPM package requires quite a few packages and libraries
996including GLib, `gcc`, `flex`, Asciidoctor, and Qt development
997tools such as `uic` and `moc`. The required Qt packages can usually be
998obtained by installing the _qt5-devel_ package. For a complete list of
999build requirements, look for the “BuildRequires” lines in
1000_packaging/rpm/wireshark.spec.in_.
1001
1002[[ChSrcOSX]]
1003
1004==== macOS: .dmg Packages
1005
1006The macOS Package is built using macOS packaging tools, based on information found in the source tree under _packaging/macosx_.
1007It requires https://asciidoctor.org/[Asciidoctor] and https://pypi.org/project/dmgbuild/[dmgbuild].
1008
1009In your build directory, type:
1010
1011[source,sh]
1012----
1013ninja dmg_package
1014# ...or, if you're using GNU make...
1015make dmg_package
1016----
1017
1018to build the macOS Package.
1019
1020[[ChSrcNSIS]]
1021
1022==== Windows: NSIS .exe Installer
1023
1024The _Nullsoft Install System_ is a free installer generator for Windows
1025systems. Instructions on installing it can be found in <<ChToolsNSIS>>.
1026NSIS is script based. You can find the main Wireshark installer
1027generation script at _packaging/nsis/wireshark.nsi_.
1028
1029When building with CMake you must first build the _nsis_package_prep_ target,
1030followed by the _nsis_package_ target, e.g.
1031
1032[source,cmd]
1033----
1034> msbuild /m /p:Configuration=RelWithDebInfo nsis_package_prep.vcxproj
1035> msbuild /m /p:Configuration=RelWithDebInfo nsis_package.vcxproj
1036----
1037
1038Splitting the packaging projects in this way allows for code signing.
1039
1040[TIP]
1041.This might take a while
1042====
1043Please be patient while the package is compressed.
1044It might take some time, even on fast machines.
1045====
1046
1047If everything went well, you will now find something like:
1048_wireshark-setup-{wireshark-version}.exe_ in
1049the _packaging/nsis_ directory in your build directory.
1050
1051[[ChSrcPortableApps]]
1052
1053==== Windows: PortableApps .paf.exe Package
1054
1055_PortableApps.com_ is an environment that lets users run popular applications
1056from portable media such as flash drives and cloud drive services.
1057
1058Install the _PortableApps.com Platform_. Install for “all users”, which
1059will place it in `C:\PortableApps`. Add the following apps:
1060
1061- NSIS Portable (Unicode)
1062- PortableApps.com Installer
1063- PortableApps.com Launcher
1064- PortableApps.com AppCompactor
1065
1066When building with CMake you must first build the _nsis_package_prep_ target
1067(which takes care of general packaging dependencies), followed by the
1068_portableapps_package_ target, e.g.
1069
1070[source,cmd]
1071----
1072> msbuild /m /p:Configuration=RelWithDebInfo nsis_package_prep.vcxproj
1073> msbuild /m /p:Configuration=RelWithDebInfo portableapps_package.vcxproj
1074----
1075
1076[TIP]
1077.This might take a while
1078====
1079Please be patient while the package is compressed.
1080It might take some time, even on fast machines.
1081====
1082
1083If everything went well, you will now find something like:
1084_WiresharkPortable64_{wireshark-version}.paf.exe_ in
1085the _packaging/portableapps_ directory.
1086
1087[[ChSrcMimeTypes]]
1088
1089=== Mime Types
1090
1091Wireshark uses various mime-types for dragging dropping as well as file formats.
1092This chapter gives an overview over all the mimetypes being used, as well as the
1093data format in which data has to be provided for each individual mimetype.
1094
1095If not otherwise stated, the data is encoded as a Json Object.
1096
1097==== Display Filter
1098
1099**MimeType**: application/vnd.wireshark.displayfilter
1100
1101Display filters are being dragged and dropped by utilizing this mime type.
1102
1103[source,json]
1104----
1105{
1106        "filter": "udp.port == 8080",
1107        "field": "udp.port",
1108        "description": "UDP Port"
1109}
1110----
1111
1112==== Coloring Rules
1113
1114**MimeType**: application/vnd.wireshark.coloringrules
1115
1116Coloring Rules are being used for dragging and dropping color rules inside the
1117coloring rules dialog.
1118
1119[source,json]
1120----
1121{
1122        "coloringrules" :
1123        [
1124                {
1125                        "disabled": false,
1126                        "name": "UDP Ports for 8080",
1127                        "filter": "udp.port == 8080",
1128                        "foreground": "[0x0000, 0x0000, 0x0000]",
1129                        "background": "[0xFFFF, 0xFFFF, 0xFFFF]"
1130                }
1131        ]
1132}
1133----
1134
1135==== Filter List
1136
1137**MimeType**: application/vnd.wireshark.filterlist
1138
1139*_Internal Use only_* - used on the filter list for moving entries within the
1140list
1141
1142==== Column List
1143
1144**MimeType**: application/vnd.wireshark.columnlist
1145
1146*_Internal Use only_* - used on the column list for moving entries within the
1147list
1148
1149
1150// End of WSDG Chapter Sources
1151
1152// vim: set syntax=asciidoc:
1153