Commit Graph

785 Commits

Author SHA1 Message Date
Moshe Kaplan 180b5e5dc0 Replace more g_malloc with g_new
Replace g_malloc with g_new to improve
source code readability.
2020-12-23 11:47:17 +00:00
Uli Heilmeier 0fad19b7d9 tshark: set cf values when quiet and tempfile
When there is no do_dissection cf is missing some variables
for cf_close() call. Therefore we have to set them explicitly.

Fixes: wireshark/wireshark#17021
2020-11-23 08:34:09 +00:00
Masaru Tsuchiyama c14ea41233 add support for compression of capture file 2020-10-30 00:25:22 +00:00
Guy Harris f7c99f73e2 Revert "Apparently, WS_WIKI_URL() is unworkable not only in C++ but in C."
This reverts commit 5df2925434.

The problem only showed up in tfshark.c, and was caused by tfshark.c
using stuff from ui/urls.h but not *including* ui/urls.h.
2020-10-25 14:42:47 -07:00
Guy Harris 5df2925434 Apparently, WS_WIKI_URL() is unworkable not only in C++ but in C.
If you use it, GCC 9.3.0 seems to think there's a missing parenthesis
somewhere, just as the version of clang++ in my version of Xcode does,
even though other versions of GCC don't.  I'm clearly missing something
obscure about C here; I give up.
2020-10-24 13:53:23 -07:00
Guy Harris d0270415a9 editcap, tshark: process IDBs in the middle of input files.
Instead of grabbing the set of IDBs found at open time, have a loop
using wtap_get_next_interface_description() to read all unread IDBs run
after opening the input file, after reading a packet from the input
file, and after getting an EOF on the input file.

Add a routine wtap_uses_interface_ids() to check whether the file type
and subtype for a dump file uses interface IDs and requires IDBs.  If
so, in the aforementioned loop, add the IDBs to the dump stream.

Add a routine wtap_dump_add_idb() to add IDBs to a dump stream.  Have it
call a file-format-specific routine to add the IDBs; the only file type
that supports it is pcapng, and it 1) writes out the IDB and 2) adds it
to the set of IDBs for the stream.

Add a wtap_dump_params_init_no_idbs() routine that prevents the IDBs
from the input file from being used to initialize the output file; use
it in cases where we're using the aforementioned loop to copy over IDBs.

Don't require any IDBs to be present when opening a pcapng file for
writing; 1) the simplest pcapng file has just an SHB in it, 2) that
requirement causes dumps that don't provide IDBs at open time to fail,
and 3) the real issue is that we don't want packets with an interface ID
not corresponding to a known IDB, and we already have a check for that.

(There are some hacks here; eventually, when everything processes the
IDBs in such a loop, we may be able to get rid of the "two favors of
dump parameter initialization" hack.)

Fixes #15844.

Addresses the same issue in #15502, but there are other issues there
that also need to be addressed.

In addition, the merge code also needs to be changed to handle this.
2020-10-22 02:58:07 -07:00
Guy Harris 6e6233521a Have WTAP_ERR_INTERNAL include an err_info string giving details.
That way, users won't just see "You got an internal error", the details
will be given, so they can report them in a bug.
2020-10-14 04:51:45 +00:00
Guy Harris e013c5ec7f Clean up URLs.
Add ui/urls.h to define some URLs on various of our websites.  Use the
GitLab URL for the wiki.  Add a macro to generate wiki URLs.

Update wiki URLs in comments etc.

Use the #defined URL for the docs page in
WelcomePage::on_helpLabel_clicked; that removes the last user of
topic_online_url(), so get rid of it and swallow it up into
topic_action_url().
2020-10-02 20:13:42 -07:00
Gerald Combs 9c53ac0187 extcap: Lazily load our interface list.
Add extcap_ensure_all_interfaces_loaded, which calls
extcap_load_interface_list if our interface list is empty. Call it in
each of our public functions that require a valid interface list.

Clean up the extcap API documentation and note which routines initialize
the interface list.

In tshark, don't unconditionally call extcap_register_preferences and
instead rely on lazy loading.

Change-Id: I8493ae5f4d703b0fd767246557d17723bcf207c6
Ping-Bug: 15295
Reviewed-on: https://code.wireshark.org/review/37750
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-07-07 05:28:29 +00:00
Gerald Combs 4dc3114c05 Windows: Set our locale to ".UTF-8".
In each of our executables we were calling "setlocale(LC_ALL, "")" at
startup. This told Windows that output was encoded using the current
system code page. Unless the code page was 65001 (UTF-8), this was a lie.

We write UTF-8 to stdout and stderr, so call "setlocale(LC_ALL, ".UTF-8)"
at startup on Windows. This lets the CRT translate our output correctly
in more cases.

Clarify and expand the OUTPUT section in the tshark man page.

Bug: 16649
Change-Id: If93231fe5b332c292946c7f8e5e813e2f543e799
Reviewed-on: https://code.wireshark.org/review/37560
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2020-07-06 16:20:25 +00:00
Peter Wu a0600e02a9 tshark: fix use-after-free while closing a live capture file
wtap_cleanup() clears options which are still in use by the time
cf_close calls wtap_close. Be sure to close the capture file first.

Bug: 16487
Change-Id: Id9ef1c0321865e9574b69439870a842efb2b209b
Fixes: v3.3.0rc0-853-g3662a69036 ("Maintain cf->state, because file cleanup depends on it.")
Reviewed-on: https://code.wireshark.org/review/36755
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-04-08 21:58:21 +00:00
Peter Wu ef717da61a CMake: remove ENABLE_PCAP_NG_DEFAULT option
pcapng has been the compile-time default since 2011. If there are any
users who would like to use the libpcap format, then they should use
runtime options instead (e.g. `tshark -P` or `editcap -F pcap`).

Change-Id: I54b70368cdc3ca78bc8617bc488cc687740a1eb9
Reviewed-on: https://code.wireshark.org/review/36721
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-04-06 01:29:37 +00:00
Guy Harris 30bad8e627 Have callback function pointers in a capture_session structure.
Instead of having programs that use the capchild library define
functions with known names, with the library routines calling back
routines with those names, have function pointers for those callbacks in
the capture_session structure, and have capture_session_init() set them.

Make the callback routines in TShark and in the ui library static.

Change-Id: Ia1ba6119c5ef7708e0f87b8420f200136ba41eae
Reviewed-on: https://code.wireshark.org/review/36583
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-03-25 23:16:06 +00:00
Guy Harris 3662a69036 Maintain cf->state, because file cleanup depends on it.
If we're capturing to multiple files, whenever we are told about a new
file, we must close the old file, so we don't leak file descriptors and
wtap structures.

Have cf_close() handle the work of closing, the way it does in file.c,
and, when we *open* a file, set the state in capture_file to
FILE_READ_IN_PROGRESS.

Bug: 16457
Change-Id: I04a01c30571b7e3575dee5e7252a59bb1ee8abbc
Reviewed-on: https://code.wireshark.org/review/36580
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-03-25 20:59:37 +00:00
Gerald Combs f9af3ec4d5 tshark: Fix compilation without libpcap.
Change-Id: Ie238089cc23d1fefb976060b7d4f424da039712d
Reviewed-on: https://code.wireshark.org/review/36394
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2020-03-13 17:52:52 +00:00
Guy Harris 0c889d6f5c Require at least libpcap 0.8/WinPcap 3.1.
2004 called, they want their libpcap/WinPcap back.

RHEL 6 initially shipped with libpcap 1.0; even old Enterprise(TM)
versions of OSes ship with something shinier than 0.7.x these days.

This lets us get rid of a bunch of #ifdefs and workaround code for
missing APIs.

Change-Id: I862cb027418b0a0c0f45a26979acea82f93f833b
Reviewed-on: https://code.wireshark.org/review/36383
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2020-03-13 00:05:07 +00:00
Peter Wu 8c1e28c0b7 tshark: remove unnecessary sys/capability.h include
Since dumpcap was split off tshark, tshark never had the need to use
file capabilities. Remove the unused header.

Change-Id: I76e9d09599a4276d4be5ba105d7c6e28e9dd96da
Reviewed-on: https://code.wireshark.org/review/35984
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
2020-01-30 05:51:01 +00:00
Jaap Keuter d90a22c1cc Reorganize long option values
For long options, without corresponding short options, to be processed
they need to be assigned a value, preferably outside of the range of
all possible short options. The code in various places tries to stay
clear of these low values, but further coordination is missing, easily
leading to issues when option processing code gets extended and/or
reorganized.

This change introduces a single location from where each catagory of
command line long option can derive a base value, which should minimize
potential option value collisions.

Change-Id: Ic8861a347d0050f74002de3aa1fcfb01202866e5
Reviewed-on: https://code.wireshark.org/review/35459
Reviewed-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Petri-Dish: Jaap Keuter <jaap.keuter@xs4all.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
2019-12-15 20:02:09 +00:00
Jaap Keuter 890e2bea2e Documentation: update (long) cmd line options
Documentation of the Tshark and dumpcap command line options between
help text, manual page and user's guide diverged over time. One aspect
of this is the implementation of more long options. This change tries to
update all documentation to be complete and in sync again.

Change-Id: Ie8bee013df8d209080fcf288072774f18f9ff51f
Reviewed-on: https://code.wireshark.org/review/35261
Reviewed-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Petri-Dish: Jaap Keuter <jaap.keuter@xs4all.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2019-11-30 23:42:11 +00:00
Guy Harris 560f2e54ba Don't report EPIPE errors writing out packet information.
EPIPE almost certainly means "the next program after us in the pipeline
exited before we were finished writing", so this isn't a real error, it
just means we're done.  (We don't get SIGPIPE because libwireshark
ignores SIGPIPE to avoid getting killed if writing to the MaxMind
process gets SIGPIPE because that process died.)

Presumably either that program exited deliberately (for example, "head
-N" read N lines and printed them), in which case there's no error to
report, or it terminated due to an error or a signal, in which case
*that's* the error and that error has been reported.

(We don't do that for EINVAL, as that's presumably a real error.  It
shows up on Windows in bug 16192, but what we probably want to do there
is to, on Windows, use _doserrno, check for the equivalent Windows
errors, and, for the default case, convert _doserrno to the appropriate
string, using Windows APIs, and report *that* string; the MS C library
converts a whole bunch of Windows errors to EINVAL, thus losing
information and making it harder to determine what the real error is.

Therefore, I'm just marking this with Ping-Bug, as it's only fixing the
problem on UN*Xes.)

Change-Id: I94c392f478561e29501facd657487716a5882295
Ping-Bug: 16192
Reviewed-on: https://code.wireshark.org/review/35053
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-11-11 21:12:34 +00:00
Guy Harris 6d6376e81f Move the last of the routines from capture_info.c into ui/capture.c.
That means the packet-count-during-capture stuff is scattered amongst
fewer locations.

Move capture_info.h into ui; it's now a header that declares routines
whose implementations are GUI-platform-dependent.

Change-Id: I475815724a4766f6bc2511e67ebae14865e1a9d1
Reviewed-on: https://code.wireshark.org/review/26249
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2019-09-15 14:09:41 +00:00
Moshe Kaplan 5d12f7d597 tshark: Warn on overwriting protocol filter
Change-Id: I41a56cf384cda91fa6ed217f7c292f325ec8c07f
Reviewed-on: https://code.wireshark.org/review/34345
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-08-24 20:18:30 +00:00
Dario Lombardo 5f105526af tshark/tfshark: fix error message.
Bug: 15825
Change-Id: Iec8dff38dd89e3947f3fe7053e38101c3ad7b1b2
Reviewed-on: https://code.wireshark.org/review/33523
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2019-06-09 12:08:52 +00:00
Guy Harris 2ee483a222 Move the Winsock initialization and cleanup to wsutil routines.
Those routines exist on both Windows and UN*X, but they don't do
anything on UN*X (they could if it were ever necessary).

That eliminates some #ifdefs, and also means that the gory details of
initializing Winsock, including the Winsock version being requested,
are buried in one routine.

The initialization routine returns NULL on success and a pointer to a
g_malloc()ated error message on failure; report the error to the user,
along with a "report this to the Wireshark developers" suggestion.

That means including wsutil/socket.h, which obviates the need to include
some headers for socket APIs, as it includes them for you.

Change-Id: I9327bbf25effbb441e4217edc5354a4d5ab07186
Reviewed-on: https://code.wireshark.org/review/33045
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-05-02 09:29:01 +00:00
Gerald Combs cec5991f40 Windows: Modernize our WSAStartup usage.
Make sure we link each application that calls WSAStartup with ws2_32.lib.
Pass version 2.2 to WSAStartup. Wikipedia says it was introduced in 1996,
so we should be OK.

Ping-Bug: 15711
Change-Id: I431839e930e7c646669af7373789640b5180ec28
Reviewed-on: https://code.wireshark.org/review/33033
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Tomasz Moń <desowin@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2019-05-01 17:51:59 +00:00
Guy Harris 937ec02581 1514 is a better initial Buffer size than 1500.
Ethernet packets without the CRC are 1514 bytes long, not 1500 bytes
long; using 1514 bytes will avoid a reallocation for a full-sized
Ethernet packet.

Change-Id: Ie8da3f13bf3df07e23e4478b7dcf84f06dec6a9d
Reviewed-on: https://code.wireshark.org/review/32761
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-06 21:04:02 +00:00
Guy Harris 8a5b26efb1 Have wtap_read() fill in a wtap_rec and Buffer.
That makes it - and the routines that implement it - work more like the
seek-read routine.

Change-Id: I0cace2d0e4c9ebfc21ac98fd1af1ec70f60a240d
Reviewed-on: https://code.wireshark.org/review/32727
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-05 02:49:43 +00:00
Guy Harris 436278747e Reset the terminal color if we're ^C'ed when reading a capture.
Catch signals/ctrl events when we're reading a capture, and stop reading
if we get one of those.  When we close a print stream, restore the color
as appropriate.

Change-Id: I3dd936964560fb3902befe0fd2e961f80437ca72
Ping-Bug: 15659
Reviewed-on: https://code.wireshark.org/review/32716
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-04 18:53:32 +00:00
Guy Harris 67644354a1 Clean file reading code.
Put the pass 1 of a two-pass read, pass 2 of a two-pass read, and only
pass of a one-pass read into separate routines, returning success/read
error/write error status codes.

This makes the processing a bit cleaner, and makes it easier to have the
file-reading code catch signals/control events.

Change-Id: I58cd9e4b86f219f3afa2dc61b57f41978fc2f853
Reviewed-on: https://code.wireshark.org/review/32711
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-04 10:21:47 +00:00
Guy Harris 511867cdf4 Don't draw the taps if we never got a capture file.
There's nothing to draw.

Maybe we should also avoid it if we didn't get any packets.

Change-Id: If76f7909f78e66b7302d0ab2caa284ca36c43bfb
Reviewed-on: https://code.wireshark.org/review/32649
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-03-31 19:53:22 +00:00
Guy Harris 5dfde7ff83 Print extcap plugins with "tshark -G plugins".
This makes it match the "Plugins" tab of the "About" dialog.

While we're at it, use the same code to enumerate extcap plugins in that
dialog.

Change-Id: I50f402a7ab5d83d46baab070d145558ed8f688f4
Reviewed-on: https://code.wireshark.org/review/32589
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-03-26 21:53:20 +00:00
Guy Harris 946c850541 More constification, to squelch warnings.
capture_input_drops() doesn't, and shouldn't, modify or free or... the
interface name, so make the pointer to it a const pointer.

Change-Id: Iafc5c5dd9939225b3aeb8a8e36c5bdeecc394e12
Reviewed-on: https://code.wireshark.org/review/32465
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-03-18 00:21:12 +00:00
Guy Harris 4a9c686322 More constification, to squelch warnings.
capture_input_cfilter_error_message() doesn't, and shouldn't, modify or
free or... the error message, so make the pointer to it a const pointer.

Change-Id: Ic14ac306add328df369af4b6e149c856f4283912
Reviewed-on: https://code.wireshark.org/review/32464
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-03-18 00:17:54 +00:00
Guy Harris b3c5fcb67c Make some code common between pcap and no-pcap TShark.
Set the output_file_name variable for -w regardless of whether we were
built with libpcap or not.  If we were built with libpcap, also pass the
flag and its argument to capture_opts_add_opt().

In the reading-a-file code (rather than the doing-a-live-capture code),
use output_file_name as the name of the output file, regardless of
whether we were built with libpcap or not.

This takes a few twists out of the maze of #ifdefs, all different.

Change-Id: I828f1b04dacbf0ea4f3aff36f26cb9a3ffcbc480
Reviewed-on: https://code.wireshark.org/review/32011
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-02-13 22:57:30 +00:00
Peter Wu 62a8d40b5f tshark: recognize protocol aliases such as "-O ssl"
Be sure to map "ssl" to "tls" instead of silently ignoring it.

Change-Id: If1edc10ead4a9f25ee4802e1395390dc3c51796f
Reviewed-on: https://code.wireshark.org/review/31894
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-05 22:39:21 +00:00
Stig Bjørlykke 6aad32583d tshark: Improve options help texts
Align the usage help text for '-' as filename for stdin and stdout
with the text used for wireshark.

Change-Id: I67011b8234616940b7878fd5768c9e2a9e79f9f0
Reviewed-on: https://code.wireshark.org/review/31838
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-31 13:16:54 +00:00
Peter Wu 50fb318026 tshark: fix minor memleak of the interface description
Capturing with "tshark -i lo" results in capture_opts->descr being set
to "Loopback" via:

    #3 0x55c5f575720c in fill_in_interface_opts_from_ifinfo capture_opts.c:547:33
    #4 0x55c5f5750dc5 in capture_opts_add_iface_opt capture_opts.c:695:9
    #5 0x55c5f574b6bd in capture_opts_add_opt capture_opts.c:843:18
    #6 0x55c5f5785efc in main tshark.c:1087:21

but tshark overwrites it, presumably to offer textual descriptions like
"Standard input" for "-i -". Fix this memory leak, reported by ASAN for
three tests from case_tshark_capture that capture from Loopback.

Change-Id: I4f393c4440bde7a621271cca3066bef3d57e250a
Reviewed-on: https://code.wireshark.org/review/31756
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-27 09:43:55 +00:00
Dario Lombardo 86ea0055f3 tshark: remove redundant casts.
Found by clang-tidy.

Change-Id: I7fe1c3219758d8daf411d094e2df17916f2eb57b
Reviewed-on: https://code.wireshark.org/review/31330
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-01-03 19:34:10 +00:00
Dario Lombardo 30c90fa745 epan: use json_dumper for json outputs.
They include -Tjson, -Tjsonraw, -Tek.

Change-Id: Ib3d700482ce5c29727c3f778cc3c46a1bf7756c4
Reviewed-on: https://code.wireshark.org/review/31000
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-03 14:33:48 +00:00
Peter Wu e2e5b01d77 cli_main: remove real_main from stack traces for non-Windows
Restore the "main" name since that is used everywhere else except for
Windows. On Windows, "main" is renamed via a macro to avoid a conflict
with "wmain" and to allow it to be called in cli_main.c.

For those wondering, GUI applications (such as Qt) have a different
entry point, namely WinMain. In Qt5, src/winmain/qtmain_win.cpp defines
WinMain, but seems to convert its arguments from Unicode to CP_ACP
(ASCII). It might not support UTF-8, but I did not verify this.

Change-Id: I93fa59324eb2ef95a305b08fc5ba34d49cc73bf0
Reviewed-on: https://code.wireshark.org/review/31208
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-01-02 12:08:20 +00:00
Guy Harris ba589a4e44 Move some command-line-oriented routines from wsutil to ui.
cmdarg_err() is for reporting errors for command-line programs and
command-line errors in GUI programs; it's not something for any of the
Wireshark libraries to use.

The various routines for parsing numerical command-line arguments are
not for general use, they're just for use when parsing arguments.

Change-Id: I100bd4a55ab8ee4497f41d9651b0c5670e6c1e7f
Reviewed-on: https://code.wireshark.org/review/31281
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-01-01 02:07:06 +00:00
Michael Mann 785621dcca Add interface name when outputting packets dropped.
Add interface name (colon delimited) to SP_DROPS ('D') message so when dropped
packets are outputted, they include the interface name for clarity.

Bug: 13498
Change-Id: I68cdde4f20a574580f089dc5096d815cde5d3357
Reviewed-on: https://code.wireshark.org/review/31218
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-12-29 08:16:01 +00:00
Guy Harris 7eb3e47fa4 Try to squeeze some bytes out of the frame_data structure.
Make the time stamp precision a 4-bit bitfield, so, when combined with
the other bitfields, we have 32 bits.  That means we put the flags at
the same structure level as the time stamp precision, so they can be
combined; that gets rid of an extra "flags." for references to the flags.

Put the two pointers next to each other, and after a multiple of 8 bytes
worth of other fields, so that there's no padding before or between them.

It's still not down to 64 bytes, which is the next lower power of 2, so
there's more work to do.

Change-Id: I6f3e9d9f6f48137bbee8f100c152d2c42adb8fbe
Reviewed-on: https://code.wireshark.org/review/31213
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-12-27 04:34:29 +00:00
Dario Lombardo 036c3d6bc7 tshark: fix compilation with gcc-8 without pcap.
Error:
CMakeFiles/tshark.dir/tshark.c.o   -c ../tshark.c
../tshark.c: In function 'real_main':
../tshark.c:706:24: error: variable 'max_packet_count' might be clobbered by 'longjmp' or 'vfork' [-Werror=clobbered]
   int                  max_packet_count = 0;
                        ^~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
ninja: build stopped: subcommand failed.

Change-Id: I92c0e2a57f5d0d2e39188cc18f0b25e1d5136a43
Reviewed-on: https://code.wireshark.org/review/31149
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-12-21 05:26:39 +00:00
Peter Wu 7fd62bfb65 tshark: handle option -c when ENABLE_PCAP=OFF
Option '-c' is not only a capture option, it also affects offline reads
as documented in the tshark manual. Fixes failing tests since
v2.9.1rc0-18-g5bf37f63a8 ("text2pcap: allow to set interface name").

Change-Id: Iffe4fd60f62766282e1a8b02a942673ba4e605f0
Reviewed-on: https://code.wireshark.org/review/31130
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-12-19 21:50:54 +00:00
Guy Harris 05b43fc5af Clean up exp_pdu_open() API.
It really shouldn't free the comment passed to it, as the caller
allocated it, and knows how to free it if necessary; it might not even
have been allocated.

Make the comment argument a "const char *" to 1) allow passing string
constants etc. and 2) to catch any attempts to free it in
exp_pdu_open().

Make the callers free it after exp_pdu_open() returns.

(Alternatively, we could have exp_pdu_open() take the file name argument
and generate the comment itself, so that all code paths generate the
same comment.)

Change-Id: I6e6924b05565761b641a6c3b4d9a2e97f4264e1b
Ping-Bug: 15365
Reviewed-on: https://code.wireshark.org/review/31105
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-12-19 06:59:09 +00:00
Guy Harris 43dfd45faa Move more version-info-related stuff to version_info.c.
Have a ws_init_version_info() routine that, given an application name
string:

	constructs the app-name-and-version-information string, and
	saves it;

	adds the initial crash information on platforms that support it,
	and saves it.

Have show_version() use the saved information and take no arguments.

Add a show_help_header() routine to print the header for --help
command-line options, given a description of the application; it prints
the application name and version information, the description, and the
"See {wireshark.org URL}" line.

Use those routines in various places, including providing the
"application name" string in pcapng SHBs.

Change-Id: I0042a8fcc91aa919ad5c381a8b8674a007ce66df
Reviewed-on: https://code.wireshark.org/review/31029
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-12-13 03:16:13 +00:00
Guy Harris a34cc98b2a Put the main() and wmain() routines for CLI programs into a separate file.
That means that code is only in one place, rather than having copies of
it in each of those programs.

CLI programs that, on Windows, should get UTF-8 arguments rather than
arguments in the local code page should:

	include the top-level cli_main.h header;

	define the main function as real_main();

	be built with the top-level cli_main.c file.

On UN*X, cli_main.c has a main() program, and just passes the arguments
on to real_main().

On Windows, cli_main.c has a wmain() function that converts the UTF-16
arguments it's handed to UTF-8 arguments, using WideCharToMultiByte() so
that it doesn't use any functions other than those provided by the
system, and then calls real_main() with the argument count and UTF-8
arguments.

Change-Id: I8b11f01dbc5c63fce599d1bef9ad96cd92c3c01e
Reviewed-on: https://code.wireshark.org/review/31017
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-12-13 00:52:11 +00:00
Jaap Keuter a58904f387 PCAP/PCAPNG: Be consistent in documentation, etc
1) The default build configuration is to select PCAPNG as
output format, but it can be selected as PCAP. Some of the
command line tools have the option to select the output
format and default towards the build configuration.
This has to be reflected in their help output also.

2) Various documentation files are still stating that PCAP is
the default format of various tools. With the default build
configuration being PCAPNG these have to be adjusted as well.
(with lack of dynamic content the documentation can only refer
to the default build configuration format).

Change-Id: I51d19642a7ed8c99817971c1f25d20972095021e
Signed-off-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Reviewed-on: https://code.wireshark.org/review/30951
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-12-07 06:00:14 +00:00
Peter Wu df7af28f39 Add new Secrets API and allow TLS to use pcapng decryption secrets
Add a new secrets API to the core, one that can outlive the lifetime of
a single capture file. Expose decryption secrets from wiretap through a
callback and let the secrets API route it to a dissector.

Bug: 15252
Change-Id: Ie2f1867bdfd265bad11fc58f1e8d8e7295c0d1e7
Reviewed-on: https://code.wireshark.org/review/30705
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-11-20 05:14:35 +00:00
Peter Wu 656cc19fc7 Replace JSON-GLib by custom JSON dumper library
The (optional) JSON-GLib library adds dependencies on GObject, GIO. For
statically linked oss-fuzz builds it also adds libffi and more. To avoid
these dependencies, replace JSON-GLib by some custom code. This allows
`tshark -G elastic-mapping` to be enabled by default without extra deps.

API design goals of the new JSON dumper library:

- Small interface without a lot of abstraction.
- Avoid memory allocations if possible (currently none, but maybe
  json_puts_string will be replaced to improve UTF-8 support).
- Do not implement parsing, this is currently handled by jsmn.

Methods to open/close array/objects and to set members are inspired by
the JsonGlib interface. The interfaces to write values is inspired by
the sharkd code (json_puts_string is also borrowed from that).

The only observed differences in the tshark output:
- JSON-GLib ignores duplicates, json_dumper does not and may produce
  duplicates and currently print two "ip.opt.sec_prot_auth_unassigned".
- JSON-GLib adds a space before a colon (unimportant formatting detail).
- (Not observed, but UTF-8 strings will be wrong like bug 14948.)

A test was added to catch changes in the tshark output. I also fuzzed
json_dumper with libFuzzer + UBSAN/ASAN and fixed an off-by-one error.

Change-Id: I0c85b18777b04d1e0f613a3d59935ec59be87ff4
Link: https://www.wireshark.org/lists/wireshark-dev/201811/msg00052.html
Reviewed-on: https://code.wireshark.org/review/30732
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-11-20 05:03:56 +00:00
Peter Wu cb9be3850d tshark: do not print packet information when using -w without libpcap
The test_tshark_io_direct_stdout test was failing because the command
"tshark -r test/captures/dhcp.pcap -w - > some.pcap" produced a corrupt
capture file which has the packet information appended at the end.

Change-Id: I1a79e98f1475c29d7dad3ff90d4cb689f46b0e57
Fixes: 57389a0c69 ("make tshark compile and work also when pcap is not available")
Reviewed-on: https://code.wireshark.org/review/30668
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-11-16 13:54:50 +00:00
Guy Harris a1372f6d01 Use an enum for compression types in various interfaces.
This:

1) means that we don't have to flag the compression argument with a
comment to indicate what it means (FALSE doesn't obviously say "not
compressed", WTAP_UNCOMPRESSED does);

2) leaves space in the interfaces in question for additional compression
types.

(No, this is not part 1 of an implementation of additional compression
types, it's just an API cleanup.  Implementing additional compression
types involves significant work in libwiretap, as well as UI changes to
replace "compress the file" checkboxes with something to indicate *how*
to compress the file, or to always use some other form of compression).

Change-Id: I1d23dc720be10158e6b34f97baa247ba8a537abf
Reviewed-on: https://code.wireshark.org/review/30660
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-16 09:20:36 +00:00
Guy Harris 4e17bd6229 Use the dump parameters structure for non-pcapng-specific stuff.
Use it for all the per-file information, including the per-file
link-layer type and the per-file snapshot length.

Change-Id: Id75687c7faa6418a2bfcf7f8198206a9f95db629
Reviewed-on: https://code.wireshark.org/review/30616
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-11-16 02:18:26 +00:00
Guy Harris 658c30dc4b Always use the input file's encapsulation for the output file.
Using WTAP_ENCAP_PER_PACKET if there's more than one interface forces a
format supporting multiple encapsulations even if all interfaces use the
same encapsulation; there's no reason to force that - you might as well
let the user specify pcap format, for example, if that's what they
really want.

(If there are multiple interfaces and they have different
encapsulations, the file encapsulation will be WTAP_ENCAP_PER_PACKET
*anyway*.)

Change-Id: I0e65c06e1ae3ff159ccd27f72cc63014e30a58f3
Reviewed-on: https://code.wireshark.org/review/30658
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-15 23:37:39 +00:00
Guy Harris ad2bc773d6 Just pass on a snapshot length of 0 to the dumper.
It means "snapshot length unknown".

For most file formats, the snapshot length isn't recorded (even for
formats that support slicing - all they record is the on-the-network
length, and length after slicing, for each packet), so it's ignored in
the dumper.

The one exception is pcap, which records it in the file header; if it's
unknown, the pcap-writing code picks the maximum supported snapshot
length for the file's link-layer header type.

Change-Id: Ieda5dfe34c4bac63e43fdadeff31799ac3c908de
Reviewed-on: https://code.wireshark.org/review/30657
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-15 23:25:41 +00:00
Guy Harris 3faa45d4ec Don't have _ng versions of the dumper open routines.
Have the routines always take a parameters pointer; pass either null or
a pointer to an initialized-to-nothing structure in cases where we were
calling the non-_ng versions.

Change-Id: I23b779d87f3fbd29306ebe1df568852be113d3b2
Reviewed-on: https://code.wireshark.org/review/30590
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-13 03:37:29 +00:00
Peter Wu 1e76e1355a wiretap: refactor common parameters for pcapng dump routines
Four variants of wtap_dump_open_ng exists, each of them take the same
three parameters for the SHB, IDB and NRB blocks that has to be written
before packets are even written. Similarly, a lot of tools always create
these arguments based on an existing capture file session (wth).

Address the former duplication by creating a new data structure to hold
the arguments. Address the second issue by creating new helper functions
to initialize the parameters based on a wth. This refactoring should
make it easier to add the new Decryption Secrets Block (DSB).

No functional change intended.

Change-Id: I42c019dc1d48a476773459212ca213de91a55684
Reviewed-on: https://code.wireshark.org/review/30578
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-11-12 23:00:44 +00:00
Dario Lombardo 1fdc0f4a6f tshark: replace exit with abort in TRY/CATCH.
Change-Id: I3fe6c63fcf179fd10b0b722b2749c68365eb0870
Reviewed-on: https://code.wireshark.org/review/30258
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-10-19 20:52:31 +00:00
Guy Harris bce13644e9 Bring back arg_list_utf_16to8(), but have it just do UTF-16-to-UTF-8 mapping.
Call it from wmain() in the command-line tools, passing it the input
argument count and vector, and call it from main() in Wireshark, after
getting a UTF-16 argument vector from passing the result of
GetCommandLineW() to CommandLineToArgvW().

Change-Id: I0e51703c0a6c92f7892d196e700ab437bd702514
Reviewed-on: https://code.wireshark.org/review/30063
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-10-08 03:05:45 +00:00
Guy Harris a679ae6f79 Use wsetargv.obj, and wmain() rather than main(), on Windows.
Doing so for command-line programs means that the argument list doesn't
ever get converted to the local code page; converting to the local code
page can mangle file names that *can't* be converted to the local code
page.

Furthermore, code that uses setargv.obj rather than wsetargv.obj has
issues in some versions of Windows 10; see bug 15151.

That means that converting the argument list to UTF-8 is a bit simpler -
we don't need to call GetCommandLineW() or CommandLineToArgvW(), we just
loop over the UTF-16LE argument strings in argv[].

While we're at it, note in Wireshark's main() why we discard argv on
Windows (Qt does the same "convert-to-the-local-code-page" stuff); that
means we *do* need to call GetCommandLineW() and CommandLineToArgvW() in
main() (i.e., we duplicate what Qt's WinMain() does, but converting to
UTF-8 rather than to the local code page).

Change-Id: I35b57c1b658fb3e9b0c685097afe324e9fe98649
Ping-Bug: 15151
Reviewed-on: https://code.wireshark.org/review/30051
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-10-07 18:57:54 +00:00
Uli Heilmeier 8dfaa8fa7c *shark: Update help and manpage for name resolving
Add 'v' option for VLAN ID resolving and get rid of
deprecated 'C' option.

Bug: 14826
Change-Id: I63104f4a465d251048693ad02882ea7eb2c4d926
Reviewed-on: https://code.wireshark.org/review/30029
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-10-05 13:19:05 +00:00
PatrikMosko 87147cd651 tshark memory leak: g_free(cf_name) moved under 'clean_exit' label
Change-Id: Ie29af2e2ff2eac2e3a97323175391070c7bceb73
Reviewed-on: https://code.wireshark.org/review/29710
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-09-18 04:03:18 +00:00
João Valverde ff1e16055f epan: Add argument to epan_init() to disable plugins
Change-Id: I8dc76e6bf8c4d5a3081cbdc1d47b88e857415d29
Reviewed-on: https://code.wireshark.org/review/29498
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2018-09-09 02:27:34 +00:00
João Valverde 8eddb1650d epan: Remove unnecessary all protocols registration callback
We are exporting a registration function from libwireshark just
to have it passed back as a callback. Seems unnecessary.

Change-Id: I7621005c9be11691d319102326824c5e3520a6f3
Reviewed-on: https://code.wireshark.org/review/29328
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2018-08-29 23:22:44 +00:00
Adam Morrison 11b3663004 Fixed a bug related to epan initialization
In various places, <program>_epan_new was called before setting the
provider, so the wth field was null. This fix is necessary for the
next commit, adding Secrets Description Block, as it uses this field.

Change-Id: Ice8ee01c56b3e04fc71d7b2c659d9635cb366951
Reviewed-on: https://code.wireshark.org/review/28868
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-08-22 06:18:11 +00:00
Vasil Velichkov 787d61c0a4 tshark: free exp_pdu_filename and capture_opts->save_file
valgrind --tool=memcheck --leak-check=full ./run/tshark -r sctp.pcap -U "OSI layer 3" -w exported.pcap

13 bytes in 1 blocks are definitely lost in loss record 20 of 93
   at 0x4C2EBAB: malloc (vg_replace_malloc.c:299)
   by 0xB27B3C5: g_malloc (gmem.c:99)
   by 0xB294D22: g_strdup (gstrfuncs.c:363)
   by 0x117B5D: capture_opts_add_opt (capture_opts.c:889)
   by 0x118C0E: main (tshark.c:1112)

Change-Id: I9b794015aa4d2626b43a5743864c2d732c6acaa1
Reviewed-on: https://code.wireshark.org/review/29125
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-08-17 22:20:54 +00:00
Peter Wu 2d33cb67cc tshark: perform NPF driver check for capture only
In CI environments with no capture driver, the test_tshark_dump_glossary
test could fail because "tshark -G decodes" contains an error message.

Postpone the check until the moment where a capture is actually started.
It also no longer shows with tshark -L, -D, --version, etc.

Change-Id: I6674c6fe007c99576c777a025cd44b3f2e594b59
Reviewed-on: https://code.wireshark.org/review/28966
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-08-05 04:48:27 +00:00
Vasil Velichkov ad145baeee tshark: Allow exporting of PDUs to stdout
The following command will export the PDUs to stdout
tshark -r ./test.pcapng -U "OSI layer 3" -w -

Change-Id: Idddded6bfcac458d82cdc033babc7546b67f7327
Reviewed-on: https://code.wireshark.org/review/28919
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-08-01 13:04:58 +00:00
Gerald Combs c74dba69fc Windows: Fetch our version using RtlGetVersion.
GetVersionEx is deprecated. Use RtlGetVersion instead. Remove
get_windows_major_version since it's no longer needed.

Change-Id: I02f6458608c2328a96a0ac71c6b1f9187babd049
Reviewed-on: https://code.wireshark.org/review/28443
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-06-26 20:30:02 +00:00
Jiri Novak 87973bf516 RTP: Common functions for allocation/deallocation of rtpstream_info_t
Change-Id: I9a0a11d238473a7c57d85547dca0713ed421a500
Reviewed-on: https://code.wireshark.org/review/28417
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-06-25 14:16:26 +00:00
Guy Harris 0542c5b700 Do IP address resolution synchronously before printing in TShark.
Otherwise, the first N packets printed, for a value of N dependent on
various factors, won't get IP addresses resolved to names, even if the
user wants them resolved.  Unlike Wireshark, which, when a name is
resolved in asynchronously, can go back and fix up the displayed packet
when the asynchronous operation completes, once TShark has written
packet data to the standard output, it can't go back and fix it if it
did name resolution asynchronously.

Bug: 14711
Change-Id: I8ebbd83103e5780c903b5560e01b7b92fa39c924
Reviewed-on: https://code.wireshark.org/review/27668
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-05-23 03:52:09 +00:00
Guy Harris 15cfc41e94 Don't use dladdr() to get a pathname for the current executable().
Change-Id: I24ad11a659c2cb936f873339dc2b36ac9944280a
Reviewed-on: https://code.wireshark.org/review/27359
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-05-05 08:06:35 +00:00
AndersBroman 3f49c0d3ca g_slist_free_full: Use g_slist_free_full() in a couple of places.
Change-Id: I38617ee289196f9807cf285af60d670bd5477687
Reviewed-on: https://code.wireshark.org/review/27327
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-05-04 10:16:54 +00:00
Peter Wu 6144951380 dfilter: fix memleaks with functions and slice operator
Running tools/dfilter-test.py with LSan enabled resulted in 38 test
failures due to memory leaks from "fvalue_new". Problematic dfilters:
- Return values from functions, e.g. `len(data.data) > 8` (instruction
  CALL_FUNCTION invoking functions from epan/dfilter/dfunctions.c)
- Slice operator: `data.data[1:2] == aa:bb` (function mk_range)

These values end up in "registers", but as some values (from READ_TREE)
reference the proto tree, a new tracking flag ("owns_memory") is added.

Add missing tests for some functions and try to improve documentation.

Change-Id: I28e8cf872675d0a81ea7aa5fac7398257de3f47b
Reviewed-on: https://code.wireshark.org/review/27132
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-04-25 06:57:00 +00:00
Dario Lombardo fc6b8ab698 tshark: improve -G elastic-mapping command by adding filters.
The generated elastic mapping file is huge and it can hassle softwares
like Kibana. This change adds the ability to append desired filters
that will appear in the mapping file.

This change adds the option --elastic-mapping-filter <protocols> to tshark.

Example: tshark -G elastic-mapping --elastic-mapping-filter ip,udp,dns

make only those 3 protocols to appear in the mapping file.

Change-Id: Ie2dcd6e44be2d084e8e50cd6554bd90178da4e38
Reviewed-on: https://code.wireshark.org/review/27001
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2018-04-19 15:54:47 +00:00
Dario Lombardo ca45f88e3b tshark: put -G elastic-mapping in help under ifdef.
Change-Id: I75cfc26844ae72f4b608f0714945b1affdac64f2
Reviewed-on: https://code.wireshark.org/review/27033
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2018-04-19 14:53:48 +00:00
Dario Lombardo 511c2e166a tshark: add -G elastic-mapping report.
This option generates an ElasticSearch mapping file as described here:
https://www.elastic.co/blog/analyzing-network-packets-with-wireshark-elasticsearch-and-kibana

It leverages the Glib-json library.

Change-Id: Iff25f991e87d3da07bf06654e353fb785799dde9
Reviewed-on: https://code.wireshark.org/review/26848
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2018-04-18 08:57:39 +00:00
Anders bb81bef535 glib: Get rid of GLIB_CHECK_VERSION as we now require 2.32.0
Change-Id: Ie95cf37f9cd283545693e290340a7489cc989c95
Reviewed-on: https://code.wireshark.org/review/26970
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-04-16 16:07:46 +00:00
Jaap Keuter 2f34f26203 OID name resolv: Fix MIB/PIB path presentations
oids.c: Sort out libsmi init, add user paths once.
Qt, About WS: Stop memory leak of MIB/PIB paths.
GTK, About WS: Allow for 20 individual paths.
tshark, folders: init before getting paths, allow 20 individual.

Bug: 14539
Change-Id: I113ee2dd4394d553a16b256e66fd840eeeec78ef
Signed-off-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Reviewed-on: https://code.wireshark.org/review/26555
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-03-24 07:07:14 +00:00
Gerald Combs a1da75c554 Transition from GeoIP Legacy to MaxMindDB.
MaxMind is discontinuing its legacy databases in April in favor of
GeoIP2, which use a newer database format (MaxMind DB). The reference C
library (libmaxminddb) is available under the Apache 2.0 license which
isn't quite compatible with ours.

Add mmdbresolve, a utility that reads IPv4 and IPv6 addresses on stdin
and prints resolved information on stdout. Place it under a liberal
license (MIT) so that we can keep libmaxminddb at arm's length. Add
epan/maxmind_db.[ch], which spawns mmdbresolve and communicates with it
via stdio.

Migrate the preferences and documentation to MaxMindDB.

Change the IPv4 and IPv6 asnum fields to FT_UINT32s. Change the
geographic coordinate fields to FT_DOUBLEs.

Bug: 10658
Change-Id: I24aeed637bea1b41d173270bda413af230f4425f
Reviewed-on: https://code.wireshark.org/review/26214
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-06 18:02:21 +00:00
Guy Harris cf2a29f083 Check whether to do dissection after starting taps.
One reason to do dissection is if a tap requires it, so we have to check
after starting the taps.

Change-Id: Ic7910449c3f85df2a52065e789986d970d13c253
Reviewed-on: https://code.wireshark.org/review/25904
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-19 21:06:58 +00:00
Guy Harris c61b543e97 Get rid of more new_ prefixes for statistics functions and types.
There are no "old" versions of them that we're keeping around.

Change-Id: I3c76a14d0ec1a06df39c547da37f4dea9987df4d
Reviewed-on: https://code.wireshark.org/review/25892
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-19 00:12:51 +00:00
Guy Harris 22dc113852 Don't start command-line taps until we've opened a file or started capturing.
We shouldn't do so until we have something on which to compute
statistics and until we're in file scope, as the taps may use
file-scoped memory, given that statistics pertain to a file.

Change-Id: Ifb568480a3cbbd4dc891015b3bb42da1511ca514
Reviewed-on: https://code.wireshark.org/review/25887
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-18 20:40:47 +00:00
Guy Harris 1f5f63f8ef Generalize wtap_pkthdr into a structure for packet and non-packet records.
Separate the stuff that any record could have from the stuff that only
particular record types have; put the latter into a union, and put all
that into a wtap_rec structure.

Add some record-type checks as necessary.

Change-Id: Id6b3486858f826fce4b096c59231f463e44bfaa2
Reviewed-on: https://code.wireshark.org/review/25696
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-09 00:29:51 +00:00
Dario Lombardo 8cd389e161 replace SPDX identifier GPL-2.0+ with GPL-2.0-or-later.
The first is deprecated, as per https://spdx.org/licenses/.

Change-Id: I8e21e1d32d09b8b94b93a2dc9fbdde5ffeba6bed
Reviewed-on: https://code.wireshark.org/review/25661
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 14:57:36 +00:00
Pascal Quantin fc9af81a13 wiretap: add a parameter to wtap_init() indicating whether plugins must be loaded
g995812c5f1 moved wiretap plugins registration from applications to
wiretap library init function.
As we do not want to load plugins for all users of libwiretap, let's
make it configurable.

Bug: 14314
Change-Id: Id8fdcc484e2d0d31d3ab0bd357d3a6678570f700
Reviewed-on: https://code.wireshark.org/review/25194
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-01-09 21:25:06 +00:00
Guy Harris af0f49e80d Use pcapng as the name of the file format.
At one point, I remember a discussion resulting in the official name of
the next-generation replacement for pcap format being changed to
"pcapng", with no hyphen.

Make Wireshark reflect that.

Change-Id: Ie66fb13a0fe3a8682143106dab601952e9154e2a
Reviewed-on: https://code.wireshark.org/review/25214
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-09 00:38:51 +00:00
Jon DeVree 51e0d22ec6 Do not automatically enable the linux kernel's BPF JIT compiler
The default value of kernel.unprivileged_bpf_disabled is 0 which means
this is enabling the BPF JIT compiler for unprivileged users. Given that
this is a known attack vector for Spectre variant 1 (CVE-2017-5753) this
is not a setting that a utility should be tampering with.

Tshark's and dumpcap's help message is changed by Balint Reczey to suggest
enabling BPF manually after considering security-related implications.

Change-Id: I1cc34cbd6e84485eba9dee79a8700aa388354885
Signed-off-by: Balint Reczey <balint.reczey@canonical.com>
Bug: 14313
Reviewed-on: https://code.wireshark.org/review/25192
Reviewed-by: Balint Reczey <balint@balintreczey.hu>
Petri-Dish: Balint Reczey <balint@balintreczey.hu>
Reviewed-by: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-01-08 23:12:09 +00:00
Dario Lombardo e80b40adbe extcap: remove conditional compilation.
Change-Id: Ia54bba388755cf27a343fe6d69d244bf1ab897f9
Reviewed-on: https://code.wireshark.org/review/25186
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-01-08 05:50:15 +00:00
Merlin Chlosta af6dee3571 Add columns (_ws.col) to output formats json, ek, pdml
Bug: 13020
Change-Id: Ia83797a4e390be7cc59a9718735edc1c7f9a5712
Reviewed-on: https://code.wireshark.org/review/24928
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-01-02 05:27:51 +00:00
João Valverde 995812c5f1 Refactor plugin registration and loading
Put different types of plugins (libwiretap, libwireshark) in different
subdirectories, give libwiretap and libwireshark init routines that
load the plugins, and have them scan the appropriate subdirectories
so that we don't even *try* to, for example, load libwireshark plugins
in programs that only use libwiretap.

Compiled plugins are stored in subfolders of the plugin folders, with
the subfolder name being the Wireshark minor version number (X.Y). There is
another hierarchical level for each Wireshark library (libwireshark, libwscodecs
and libwiretap).

The folder names are respectively plugins/X.Y/{epan,codecs,wiretap}.

Currently we only distribute "epan" (libwireshark) plugins.

Change-Id: I3438787a6f45820d64ba4ca91cbe3c8864708acb
Reviewed-on: https://code.wireshark.org/review/23983
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2017-12-14 08:43:57 +00:00
João Valverde 5fc43fe63a Rewrite make-tap-reg.py in C
Change-Id: Ief5b1fffecc9712c01ff10292c403b7c84a5908a
Reviewed-on: https://code.wireshark.org/review/24756
Reviewed-by: João Valverde <j@v6e.pt>
2017-12-11 02:52:28 +00:00
Guy Harris 8aa14236f8 Have the frame_tvbuff.c routines not use the global cfile.
Have the routines that create them take a pointer to a struct
packet_provider_data, store that in the tvbuff data, and use it to get
the wtap from which packets are being read.

While we're at it, don't include globals.h in any header files, and
include it in source files iff the source file actually uses cfile.  Add
whatever includes that requires.

Change-Id: I9f1ee391f951dc427ff62c80f67aa4877a37c229
Reviewed-on: https://code.wireshark.org/review/24733
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-12-08 08:31:41 +00:00
Guy Harris 48e65c4af4 Hand the packet provider functions to epan_new().
Have separate packet_provider_data structures and packet_provider_funcs
structures; the latter holds a table of functions that libwireshark can
call for information about packets, the latter holds the data that those
functions use.

This means we no longer need to expose the structure of an epan_t
outside epan/epan.c; get rid of epan/epan-int.h.

Change-Id: I381b88993aa19e55720ce02c42ad33738e3f51f4
Reviewed-on: https://code.wireshark.org/review/24732
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-12-08 04:33:55 +00:00
Guy Harris 797d2f6a87 Move the frame_set stuff back into the capture_file structure.
libwireshark now expects an epan_t to be created with a pointer to a
"packet provider" structure; that structure is opaque within
libwireshark, and a pointer to it is passed to the callbacks that
provide interface names, interface, descriptions, user comments, and
packet time stamps, and that set user comments.  The code that calls
epan_new() is expected to provide those callbacks, and to define the
structure, which can be used by the providers.  If none of the callbacks
need that extra information, the "packet provider" structure can be
null.

Have a "file" packet provider for all the programs that provide packets
from a file.

Change-Id: I4b5709a3dd7b098ebd7d2a7d95bcdd7b5903c1a0
Reviewed-on: https://code.wireshark.org/review/24731
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-12-08 03:32:25 +00:00
Guy Harris 1834dca365 Move the parts of a capture_file used by libwireshark to a new structure.
Embed one of those structures in a capture_file, and have a struct
epan_session point to that structure rather than to a capture_file.
Pass that structure to the routines that fetch data that libwireshark
uses when dissecting.

That separates the stuff that libwireshark expects from the stuff that
it doesn't look at.

Change-Id: Ia3cd28efb9622476437a2ce32204597fae720877
Reviewed-on: https://code.wireshark.org/review/24692
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-12-04 05:02:18 +00:00
Guy Harris 02944c412b Use cfile fields for some frame_data pointers.
Those fields weren't being used in TShark/TFShark/rawshark/sharkd, so we
can use them, instead of defining our own static variables.

This makes the non-Wireshark code paths a bit more like the Wireshark
code paths.

Change-Id: I55da4cf525e37598f314efca22f20d3e80cb547c
Reviewed-on: https://code.wireshark.org/review/24691
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-12-04 03:20:45 +00:00
Guy Harris eb8ffb74e2 Use cfile.h to define the capture_file type.
Have cfile-int.h declare the structure, and use it in files that
directly access the structure.

Have cfile.h just incompletely declare the structure and include it
rather than explicitly declaring it in source files or other header
files.

Never directly refer to struct _capture_file except when typedeffing
capture_file.

Add #includes as necessary, now that cfile.h doesn't drag in a ton of

Change-Id: I7931c8039d75ff7c980b0f2a6e221f20e602a556
Reviewed-on: https://code.wireshark.org/review/24686
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-12-03 18:54:37 +00:00
Gerald Combs 28b6616ea0 Get rid of some void pointers.
Explictly struct _capture_file * in epan_session and its callbacks.

Change-Id: I63703015c661a08f3350a7448a7bcdaf98f119dc
Reviewed-on: https://code.wireshark.org/review/24675
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-12-01 21:09:24 +00:00
João Valverde 7540ac6938 Move the protocol registration routines back into libwireshark
Follow-up to b695b3e2f7.

Change-Id: I7e36519f2c3806c1205d05437671325080974257
Reviewed-on: https://code.wireshark.org/review/24524
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2017-11-21 20:21:50 +00:00
Gerald Combs 775bbbcded Start using SPDX license identifiers.
A while back Graham pointed out the SPDX project (spdx.org), which is
working on standardizing license specifications:

https://www.wireshark.org/lists/wireshark-dev/201509/msg00119.html

Appendix V of the specification describes a short identifier
(SPDX-License-Identifier) that you can use in place of boilerplate in
your source files:

https://spdx.org/spdx-specification-21-web-version#h.twlc0ztnng3b

Start the conversion process with our top-level C and C++ files.

Change-Id: Iba1d835776714deb6285e2181e8ca17f95221878
Reviewed-on: https://code.wireshark.org/review/24302
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Balint Reczey <balint@balintreczey.hu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-11-09 20:03:51 +00:00
Orgad Shaneh 8730b2037a tshark/tfshark: Replace global prefs with a boolean
This partially reverts dc0e6ccc9f in favor
of a cleaner solution.

Change-Id: Ie57329020b5a7d15eb7d99aad3103843a14f07a6
Reviewed-on: https://code.wireshark.org/review/24278
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2017-11-08 15:00:04 +00:00
Orgad Shaneh dc0e6ccc9f tshark/tfshark: Do not apply console.log.level before it is set
The user has no way to apply this setting while loading dissectors in order
to enable g_debug messages during init for example.

Change the behavior to be as documented in the comment.

Change-Id: I9317f12b207d4621508212b02ca1ebd46b55aadc
Reviewed-on: https://code.wireshark.org/review/24184
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Richard Sharpe <realrichardsharpe@gmail.com>
2017-11-07 13:51:38 +00:00
Michael Mann 7ddfee9aea tshark: Use -G help instead of -G ?
Not all platforms handle ? or -? *predictably* at the command line.
As long as "?" isn't replaced with a file name, it works, but if it
gets replaced by a file name...

Bug: 13984
Change-Id: I4496bb27fdef121967e7baf7b7f4a1bb0a44b00a
Reviewed-on: https://code.wireshark.org/review/24125
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-10-28 03:22:59 +00:00
Gerald Combs bfad9c56f9 CMake: Don't check for windows.h or winsock2.h.
If we're building on Windows we're going to have windows.h and
winsock2.h. Don't bother checking for them.

Change-Id: I0004c44d7364ab3f41682f34b8c84cd8617c9603
Reviewed-on: https://code.wireshark.org/review/24068
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-10-26 07:08:41 +00:00
Peter Wu 1dea7f3dc1 Rename ui_util.h -> ws_ui_util.h
In preparation for possibly using AUTOUIC in CMake which treats "ui_*.h"
files specially, rename ui_util.h. No other changes.

Change-Id: Id026572c000b713ff0e9388dc7fff8d81d4df73e
Reviewed-on: https://code.wireshark.org/review/23916
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-10-15 01:14:26 +00:00
Christoph Wurm af09db8bd3 Tshark: Optional packet summary for Elasticsearch
Currently, the Elasticsearch output exports the packet details and,
if -x is specified, the raw hex data.

This change adds the option of exporting the packet summary as well.

The default stays the same (packet details only), but now the existing
-P switch turns on printing of the packet summary. It also turns off
printing packet details, which can be turned back on with -V to print
both, and combined with -x to print all three: summary, details and
raw hex.

The packet summary is especially useful when exploring and visualizing
the data in Kibana, e.g. by displaying the summary "Info" field/column
in a table, as in the Wireshark GUI.

Change-Id: I2030490cfdd905572397bc3d5457ba49d805a5c4
Reviewed-on: https://code.wireshark.org/review/22716
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-10-15 00:58:42 +00:00
Guy Harris 9551aca9a6 Add --print as an alias for -P, to match tcpdump.
tcpdump just got a --print option, which causes packet information to be
printed even if the raw packets are being saved to a file with -w.  We
have -P for the same purpose; make --print another name for it.

While we're at it:

	document --help and --version;

	just speak of -P/--print as causing printing even of the packet
	details, even though -V forces printing with -w, for consistency
	with how --print is documented for tcpdump;

	fix the description of -h/--help.

Change-Id: Idf650a202a09a2d1682edbd9d76123f1b1412b55
Reviewed-on: https://code.wireshark.org/review/23888
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-10-11 19:32:43 +00:00
Gerald Combs e8492934d6 WSUG: More tools updates.
Add links to the online man page for each tool. Make sure tshark
generates pre-commit-compatible output on Linux.

Change-Id: I00d2973475f27460065bc8a65471abef152ded33
Reviewed-on: https://code.wireshark.org/review/23754
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-09-26 21:40:12 +00:00
João Valverde a269ae1b6a Rename "ws_version_info.h", also .c
It's not installed so like most other files it doesn't need or benefit
from the prefix.

Change-Id: I01517e06f12b3101fee21b68cba3bc6842bbef5c
Reviewed-on: https://code.wireshark.org/review/23751
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
2017-09-26 17:32:08 +00:00
João Valverde 25ba538bc5 plugins: Be more descriptive in "about wireshark"->"folders"
Display separate entries for binary plugins and lua scripts.

This is explained in the user guide, that the binary folder is
a subfolder of the lua folder, but it's probably a good idea to be more
explicit about it, at the risk of cluttering the interface a bit.

Move GeoIP information down because it seems the least important.

Add helper functions to provide plugin version subdir.

Change some #ifdefs while at it for legibility.

Change-Id: Ieb8665df029b3c14de19e2c973bd9b1cc4ec4621
Reviewed-on: https://code.wireshark.org/review/23609
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
2017-09-20 16:41:21 +00:00
João Valverde 8db4ddd40c Rename get_plugin_dir() for consistency
WS_DLL_PUBLIC const char *get_plugin_dir(void);
WS_DLL_PUBLIC const char *get_plugins_pers_dir(void);

Opt for the plural form consistently (for public functions at least).

Change-Id: I8a5861ad7f90f9c87168bd3275bd9dbc5c83b749
Reviewed-on: https://code.wireshark.org/review/23608
Petri-Dish: João Valverde <j@v6e.pt>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-09-20 01:00:37 +00:00
João Valverde 69f0cb0cef wsutil: Initialize and store plugin personal dir
Obviate allocation on every call to get_plugins_pers_dir().

Change-Id: I089ae499f93739d490d4552f59b5db5996f7d26f
Reviewed-on: https://code.wireshark.org/review/23495
Petri-Dish: João Valverde <j@v6e.pt>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Reviewed-by: João Valverde <j@v6e.pt>
2017-09-11 16:48:49 +00:00
Jim Young 7a71ec887c tshark: Add delimiter to both sides of packetlist arrows
Depending on how packetlist columns are arranged certain columns may have a
Unicode arrow character inserted between it and the subsequent column to
indicate source vs destination column directionality when displayed in
tshark.  Currently any inserted Unicode arrow characters are
unconditionally prefaced with an ASCII SPACE character.

Tshark's `-T tabs` option causes the various packetlist columns to be
delimited with ASCII TAB characters.  The unconditional use of the SPACE
character before any inserted Unicode arrows makes it difficult to directly
compare a -T tabs report of column N values to column N+1 values without
dealing with the SPACE/Unicode Arrow suffix appended to all of the column
N values.

The inserted Unicode directionality arrows are effectively another
packetlist column of data that should be delimited like all other columns.
This patch ensures that any Unicode directionality arrows inserted between
packet list columns are delimited on both sides of the arrows with the
selected delimiter character.

Change-Id: I4eb7c6015a538afdc2c41be746eca4eec1ace36f
Reviewed-on: https://code.wireshark.org/review/23222
Petri-Dish: Jim Young <jim.young.ws@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-08-29 03:57:56 +00:00
Mikael Kanstrup 3b16cc8b21 iface_lists: Access ifaces member by reference
Change access of ifaces elements from by val to by reference.
With this change unnecessary copying of the whole struct is avoided
but even more important is that elements no longer have to be
removed and inserted whenever data is updated.

This change aims to make it more clear that ifaces elements shall
never directly be removed from the array. Instead use function
capture_opts_del_iface

NOTE: Code for GTK UI not updated

Ping-Bug: 13864
Change-Id: I04b65d5ee36526b30d959b8e5a2a48a3c7c4f15b
Reviewed-on: https://code.wireshark.org/review/23204
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-08-28 14:43:13 +00:00
Ahmad Fatoum aca55a29f7 Add hardware timestamping support
pcap provides a pcap_set_tstamp_type function, which can be used to request
hardware timestamps from a supporting kernel.

This patch adds support for aforementioned function as well as two new
command line options to dumpcap, wireshark and tshark:

    --list-time-stamp-types
                             List time stamp types supported for the interface
    --time-stamp-type <type>
                             Change the interface's timestamp method

Name choice mimics those used by tcpdump(1), which already supports this
feature. However, unlike tcpdump, we provide both options unconditionally.
If Wireshark was configured without pcap_set_tstamp_type being available,
--list-time-stamp-types reports an empty list.

Change-Id: I418a4b2b84cb01949cd262aad0ad8427f5ac0652
Signed-off-by: Ahmad Fatoum <ahmad.fatoum@siemens.com>
Reviewed-on: https://code.wireshark.org/review/23113
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-08-22 07:55:26 +00:00
Dario Lombardo 68f295d605 tshark: assert edt before calling print_packet (CID 1405107).
Change-Id: Iacde5514dc355cbb06fe45f5e342ddd45700999d
Reviewed-on: https://code.wireshark.org/review/22749
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-07-23 19:41:33 +00:00
Sake Blok 3803e00367 Add option to use wall-clock intervals
Add the "interval" option to "-b". Each new capture starts at the
exact start of a time interval. For instance, using -b interval:3600
will start a new capture file at each whole hour.

Changed the duration option in the GUI interfaces to use the new
interval option.

Change-Id: I0180c43843f5d2f0c2f50153c9ce42ac7fa5aeae
Reviewed-on: https://code.wireshark.org/review/22428
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Sake Blok <sake.blok@SYN-bit.nl>
2017-07-03 16:41:37 +00:00
Daan De Meyer 07f576ffeb Add --no-duplicate-keys tshark option.
Adds the --no-duplicate-keys option to tshark. If -T json is specified,
this option can be specified in order to transform the duplicate keys
produced by -T json into single keys with as value a json array of all
separate values.

Specifying --no-duplicate-keys changes the function which groups node
children that is passed to write_json_proto_tree. Instead of a function
that puts each node in a separate group (proto_node_group_children_by_unique)
a function is passed that groups children that have the same json key
together (proto_node_group_children_by_json_key). This will lead to
some groups having multiple values. Groups with multiple values are
written to the output as a json array. This includes normal json keys
but also keys with the "_raw" and "_tree" suffix.

If --no-duplicate-keys is specified with an option other than "-T json"
or "-T jsonraw" or without -T an error is shown and tshark will exit.

"Export Packet Dissections -> As JSON" in the GUI is hardcoded to use
the duplicated keys format.

Fixes one regression in the output where a filtered json key (-j) with
both a value and children would not have the "_tree" suffix added to the
json key containing the children.

Includes a little code cleanup (removes one instance of code
duplication and simplifies a while loop).

Fixes a memory leak (I thought this fix was already included in the
previous refactor patch but something must have gone wrong when updating
the patch so I'm including it again in this patch).

Bug: 12958
Change-Id: I401f8fc877b5c590686567c3c44cdb832e9e7dfe
Reviewed-on: https://code.wireshark.org/review/22166
Petri-Dish: Jaap Keuter <jaap.keuter@xs4all.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-06-22 19:31:01 +00:00
Daan De Meyer 7c28d26d71 Refactor JSON output functions
Refactors the print.c json output functions to be more intuitive and
to allow easy switching to single json keys with a json array of values
instead of duplicate json keys. With this commit the json output does
not change at all.

These changes have been tested on multiple decrypted http2 traces with
the following testing method:
- Save the pcap file as json with a build of the current master branch.
- Save the pcap file as json with a build of the master branch + this
commit.
- Compare the files for changes with the "cmp" utility.

No differences were found between files for multiple different decrypted
http2 traces. Printing with the "-x" or "-j" options also does not
produce any changes either.

Bug: 12958
Change-Id: Ibd3d39119c3a08906389aa8bbf4e2a2b21dd824e
Reviewed-on: https://code.wireshark.org/review/22064
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-06-16 07:41:27 +00:00
Michael Mann 585d17ae7f Add support for color xml attributes in psml and pdml formats.
Bug: 6682
Change-Id: I19330d06aa3d5692503c61369c3c650d595971f5
Reviewed-on: https://code.wireshark.org/review/22077
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stephen Donnelly <stephen.donnelly@endace.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-06-12 03:23:38 +00:00
Guy Harris 9f4671f674 Don't colorize a line if we have no color filter.
There's no guarantee that there's a color filter that matches, so the
color filter pointer might be null.

Change-Id: Ia11845824a4ca9c0cc153a89aa2fba876084a796
Reviewed-on: https://code.wireshark.org/review/22079
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-11 19:04:48 +00:00
Dave Goodell 2be411a215 tshark: add "--color" option emulating wireshark colors
With this commit, tshark will mimic the packet coloring present in the
Wireshark GUI whenever "--color" is passed.  This initial commit only
adds such support for the standard text output format.  A future commit
could potentially broaden this support to other output modes (such as
"-V" mode).

Bug: 5158
Change-Id: I59329e32475b0c67e28802e79610544d4868ea2d
Reviewed-on: https://code.wireshark.org/review/21325
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-06-11 13:36:19 +00:00
Guy Harris d0865fd619 Allow bigger snapshot lengths for D-Bus captures.
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except
for D-Bus captures.  Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for
them, because that's the largest possible D-Bus message size.  See

	https://bugs.freedesktop.org/show_bug.cgi?id=100220

for an example of the problems caused by limiting the snapshot length to
256KB for D-Bus.

Have a snapshot length of 0 in a capture_file structure mean "there is
no snapshot length for the file"; we don't need the has_snap field in
that case, a value of 0 mean "no, we don't have a snapshot length".

In dumpcap, start out with a pipe buffer size of 2KB, and grow it as
necessary.  When checking for a too-big packet from a pipe, check
against the appropriate maximum - 128MB for DLT_DBUS, 256KB for
everything else.

Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20
Reviewed-on: https://code.wireshark.org/review/21952
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-05 05:28:26 +00:00
Peter Wu c9b0e9c813 Report syntax errors in UAT prefs parsing
Add the cause for a syntax error while parsing UATs. Example output:

    $ tshark -ouat:ssl_keys:,
    tshark: Invalid -o flag "uat:ssl_keys:,": ssl_keys:1: No IP address given.
    $ tshark -ouat:unknown:,
    tshark: Invalid -o flag "uat:unknown:,": Unknown preference

Change-Id: I549406c4e31a81d29f487ef47bdb3c22da084947
Reviewed-on: https://code.wireshark.org/review/21748
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Jakub Zawadzki <darkjames-ws@darkjames.pl>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-05-26 17:31:01 +00:00
Guy Harris a8228fa80b Fix Windows build without pcap.
Change-Id: Ib79da01124a7f1b44f168ce19691d3ceaa7d5a68
Reviewed-on: https://code.wireshark.org/review/21619
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-05-12 18:44:10 +00:00
Alexis La Goutte 33f3866fb4 tshark: Fix Dead Store (Dead assignement/Dead increment) Warning found by Clang
Change-Id: I4425be3bbee0e781dff59a07d7de65f5eba81bdd
Reviewed-on: https://code.wireshark.org/review/21564
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-05-09 13:42:24 +00:00
Hessam Jalali dd884611ac Auto reset epan session
Automatically resets intarnal epan session after reaching to
specified number of packets, for example
-M 1000
will reset the session every 1000 packets.

this is more like a proposal since the usage is very specific
it is useful for 24/7 live capture with dissection and sending
data directly to another application.

example:

tshark -Y "gtp" -M 100000 -T fields -e gtp.message -e gtp.teid

Change-Id: I8ee8b0380017c684120a93cb3fb43f41615a9c04
Reviewed-on: https://code.wireshark.org/review/21312
Reviewed-by: Evan Huus <eapache@gmail.com>
Petri-Dish: Evan Huus <eapache@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-05-05 00:51:58 +00:00
Guy Harris 2a3f1a4f67 Eliminate some double-frees.
The cfile_ error-reporting routines free err_info; the caller doesn't
have to and, in fact, mustn't do so themselves.

While we're at it, make sure wtap_seek_read() always zeroes out *err and
nulls out *err_info, so the latter either points to a freshly-allocated
string or is null.

Change-Id: Idfe05a3ba2fbf2647ba14e483187617ee53e3c69
Reviewed-on: https://code.wireshark.org/review/21407
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-29 11:29:34 +00:00
Guy Harris e52c95c6c8 Move UI-only stuff out of libwireshark.
Packet ranges are used only in the UI; move the packet range stuff into
libui.

Don't pass a print_args_t structure to libwireshark packet-printing
routines, just pass the few parameters they need.  Move the declaration
of print_args_t into file.h.

Change-Id: Icff5991eea7d7d56f33b4716105895263d275bcf
Reviewed-on: https://code.wireshark.org/review/21308
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-24 03:38:21 +00:00
Guy Harris 751e078d2b Print first-pass read errors at the end.
That way, they don't, for example, get lost as a result of being
scrolled off the screen by output from the second pass.

Also, do the post-processing of output regardless of whether we got read
errors or not, and fix a code error hidden by a call to tshark_debug().

Change-Id: I389c7c794f4dd5fda6e4c50ce480802c92701866
Reviewed-on: https://code.wireshark.org/review/21305
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-23 20:18:46 +00:00
Jakub Zawadzki e2f76f991c tshark: make success volatile.
/home/wireshark/builders/ubuntu-x86-64-petri-dish/ubuntu-x86-64-petri-dish/build/tshark.c: In function ‘main’:
/home/wireshark/builders/ubuntu-x86-64-petri-dish/ubuntu-x86-64-petri-dish/build/tshark.c:653:12:
error: variable ‘success’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered]

Change-Id: I793962c71b0ebfafc7c09b1d865cfa774456bb3a
Reviewed-on: https://code.wireshark.org/review/21303
Petri-Dish: Jakub Zawadzki <darkjames-ws@darkjames.pl>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-23 19:08:28 +00:00
Guy Harris dc9127ddff Rename read{_cap}_file() to process{_cap+_file().
They might read the file once or twice, but the key is that they (and
what they call) are doing the work of processing the file's contents.

Change-Id: I2df6257c55ff5ace944f1a1db5e2aec456ed2038
Reviewed-on: https://code.wireshark.org/review/21293
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-23 08:29:55 +00:00
Guy Harris e9f5e045f7 Just have read_cap_file()/read_file() return a success/failure indication.
No need to report the precise error code - it's already reported the
error.

Change-Id: Ib52daf094253deac2a10d16793ebf0f42581afd6
Reviewed-on: https://code.wireshark.org/review/21292
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-23 08:21:26 +00:00
Guy Harris a4eb68be97 Rename some routines to better reflect what they do.
In TShark, rename load_cap_file() to read_cap_file(); this is TShark,
not Wireshark, so you're not "loading" a file to be manipulated through
the GUI.

In TFShark, rename it to "read_file()"; not only are we not loading it,
it's not even necessarily a capture file.

Change-Id: I122b46ecd8cb7de9c1e1c249ba6c08fdeb93f7e2
Reviewed-on: https://code.wireshark.org/review/21291
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-23 05:22:38 +00:00
Guy Harris 9e9d284d91 Have separate routines for open-for-reading and open-for-writing errors.
Expand comments while we're at it.

Change-Id: I6dcc791eab1c9e323a9572f3d54720d223bdd64b
Reviewed-on: https://code.wireshark.org/review/21252
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-20 18:24:20 +00:00
Guy Harris d09ef61459 Make the command-line and alert-box failure messages more similar.
Change-Id: I94af221a0ce8b6b3ff8e0e1b94d5379351ac0962
Reviewed-on: https://code.wireshark.org/review/21251
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-20 17:15:22 +00:00
Guy Harris 7312019eac Fix a compiler warning.
(Clang FTW!  Is this not an issue on x86-64 macOS, so that it doesn't
warn about it, or does it, unlike GCC, require a particular -W flag to
warn about non-volatile variables being stomped by setjmp/longjmp?)

Change-Id: I253c1ea324feac1372aa4077aaba03c787a47d9f
Reviewed-on: https://code.wireshark.org/review/21248
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-20 16:56:11 +00:00
Guy Harris bce5ec919e Use the new cfile_XXX_failure_message() routines more broadly.
Change-Id: I7814b3fd0353f4836ae61cbdbd4e13f659cbcb59
Reviewed-on: https://code.wireshark.org/review/21239
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-20 07:19:41 +00:00
Guy Harris 347a19ae96 Add common routines for command-line libwiretap error reporting.
These are similar to the routines added to ui/alert_box.c for dialog-box
libwiretap error reporting.

This centralizes the knowledge about what to say for various libwiretap
errors, removing some duplicate code, and giving more details in some
programs.

Change-Id: I737405c4edaa0e6c27840f78a8c587a8b3ee120b
Reviewed-on: https://code.wireshark.org/review/21234
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-20 02:21:58 +00:00
Guy Harris 8fb828ff0c Have a common "print a capture file open error message" routine.
Use that for both "open for input" and "open for output" errors.

Change-Id: Id17b732a2ca91bd080957b9fa010f781a1c65471
Reviewed-on: https://code.wireshark.org/review/21175
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-18 02:14:45 +00:00
Guy Harris 067ef3e08a Clean up documentation and help messages for protocol enabling/disabling.
List all of --enable-protocol, --disable-protocol, --enable-heuristic,
and --disable-heuristic in the SYNOPSIS section of the man pages.

Undent after the list of taps for the -z option, so the following
options are at the same indentation as other options.

List --enable-protocol in the DESCRIPTION, above --disable-protocol.

Include --enable-protocol in the help message.

Change-Id: I680a54430789f3543b2d539fbded22b0b57f7f76
Reviewed-on: https://code.wireshark.org/review/21159
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-17 03:48:14 +00:00
Guy Harris 407a2b07e5 Rename some routines and structure members.
They deal with sets of hfids, which can belong to protocols as well as
fields (I guess you could argue that a protocol is a field, but...).

Change-Id: Ibd103cfa26427ead4ef54be89f1251908004cfae
Reviewed-on: https://code.wireshark.org/review/21154
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-17 01:49:01 +00:00
Guy Harris 847c25c5a7 Prime the epan_dissect_t with postdissector wanted fields if necessary.
This makes sure that postdissectors that indicate that they need certain
fields in the first pass will get them.

While we're at it:

Fix the field-fetching code in TRANSUM not to assume it got any
instances of the field being fetched.

Rename process_packet_first_pass() in sharkd to process_packet(), as
it's the only routine in sharkd that processes packets.

Rename process_packet() in tshark and tfshark to
process_packet_single_pass(), as it's what's used if we're only doing
one-pass analysis.

Clean up comments and whitespace.

Change-Id: I3769af952c66f5ca4b68002ad6213858ab9cab9b
Reviewed-on: https://code.wireshark.org/review/21063
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-12 23:33:37 +00:00
Guy Harris 4d2d423106 Rename routines to clarify what they do.
XXX_prime_with_YYY makes it a bit clearer than does XXX_prime_YYY that
we're not priming YYY, we're priming XXX *using* YYY.

Change-Id: I1686b8b5469bc0f0bd6db8551fb6301776a1b133
Reviewed-on: https://code.wireshark.org/review/21031
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-12 04:56:49 +00:00
Guy Harris c079255539 Add an API to let a postdissector specify fields whose values it needs.
Currently, this is only used to determine whether a protocol tree needs
to be built on the first pass or not - if there are postdissectors that
need fields, it does - but eventually we should be able to use it to
prime the dissection to deliver those fields in cases where we don't
need the *entire* protocol tree (rather than using a hack such as
cooking up a fake tap with a fake filter to do that).

Update MATE and TRANSUM to use it.

Clean up code to check whether we need a protocol tree, and add comments
before that code indicating, in each case, what the criteria are.

The array of postdissectors includes a length, so we don't need to
separately keep track of the number of postdissectors.

Clean up indentation while we're at it.

Change-Id: I71d4025848206d144bc54cc82941089a50e80ab7
Reviewed-on: https://code.wireshark.org/review/21029
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-12 04:31:19 +00:00
Guy Harris 6b3714254d Pull all the "load settings" calls into a epan_load_settings() routine.
That way, nothing using libwireshark needs to know what settings need to
be loaded, they just call epan_load_settings().

Change-Id: I9390e259e286fc4f5acaeaac2767e4c3c4b656af
Reviewed-on: https://code.wireshark.org/review/20983
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-09 22:40:30 +00:00
Guy Harris 7d5ce06cbe Pull the error reporting into {read,save}_filter_list.
Change-Id: I4d9582661f2f1728d400eeb2a1b1dea98f32ce7f
Reviewed-on: https://code.wireshark.org/review/20982
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-09 17:57:52 +00:00
Guy Harris 77cad8561c Move the filter file reading code to libui.
It doesn't belong in libwireshark, as it doesn't affect dissection, but
it *does* belong in libui, as it's helper code for the UIs.

Change-Id: I8a5e0640a299a08e9ec1917dd253197438ebfdbc
Reviewed-on: https://code.wireshark.org/review/20974
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-09 04:25:52 +00:00