Commit Graph

762 Commits

Author SHA1 Message Date
John Thacker 8ac995578c epan: Respect custom column resolved/unresolved status everywhere
Add a function to get the column text of the nth column, taking
into account whether the column is resolved or unresolved. Use
this function in the GUI, as well as in tshark, when writing
PSML, exporting dissection to PSML, etc., instead of accessing
col_data directly.

This removes the direct accesses of col_data from outside
column.c and column-utils.c

Fix #18168.
2022-07-12 00:22:11 +00:00
Uli Heilmeier 58b29b8f74 tshark: Respect -Q option
Suppress non-error messages when -Q is set.

Fixes: #18186
2022-07-11 23:06:35 +00:00
John Thacker 1eeb0c9934 cli: Copy global configuration profile to personal as with the GUI
If a configuration profile is requested on the command line that
does not exist as a personal profile but does exist as a global
profile, copy it to the personal directory and use it, the same
as when selecting a global profile in the GUI.

Add the same feature to tshark and tfshark as well, where it
is particularly useful.
2022-07-07 12:14:41 +00:00
João Valverde 04c42eace3 tshark: Add a --selected-frame option
Add a selected frame option that does pretty much what the name
indicates.

This is not meaningful in the CLI but is useful to simulate the
selected frame action in the GUI for unit testing purposes. The
option is not documented for that reason.

A selected frame is used in display filters with field references.

$ tshark  -r ../test/captures/dhcp.pcap
    1   0.000000      0.0.0.0 → 255.255.255.255 DHCP 314 DHCP Discover - Transaction ID 0x3d1d
    2   0.000295  192.168.0.1 → 192.168.0.10 DHCP 342 DHCP Offer    - Transaction ID 0x3d1d
    3   0.070031      0.0.0.0 → 255.255.255.255 DHCP 314 DHCP Request  - Transaction ID 0x3d1e
    4   0.070345  192.168.0.1 → 192.168.0.10 DHCP 342 DHCP ACK      - Transaction ID 0x3d1e

$ tshark --selected-frame=2 -2 -Y 'frame.number <= ${frame.number}' -r ../test/captures/dhcp.pcap
    1   0.000000      0.0.0.0 → 255.255.255.255 DHCP 314 DHCP Discover - Transaction ID 0x3d1d
    2   0.000295  192.168.0.1 → 192.168.0.10 DHCP 342 DHCP Offer    - Transaction ID 0x3d1d
2022-04-12 14:03:18 +00:00
João Valverde 09696f1762 Try to fix a narrowing warning
"C:\Development\wsbuild64\Wireshark.sln" (default target) (1) ->
"C:\Development\wsbuild64\epan\dfilter\dfilter.vcxproj.metaproj" (default target) (18) ->
"C:\Development\wsbuild64\epan\dfilter\dfilter.vcxproj" (default target) (108) ->
       (ClCompile target) ->
C:/Development/wireshark/epan/dfilter/scanner.l(463,54): warning C4267: '+=': conversion from 'size_t' to 'int
       ', possible loss of data [C:\Development\wsbuild64\epan\dfilter\dfilter.vcxproj]
C:/Development/wireshark/epan/dfilter/scanner.l(463,54): warning C4267:         state->location.col_start += sta
       te->location.col_len; [C:\Development\wsbuild64\epan\dfilter\dfilter.vcxproj]
C:/Development/wireshark/epan/dfilter/scanner.l(463,54): warning C4267:
                           ^ (compiling source file C:\Development\wsbuild64\epan\dfilter\scanner.c) [C:\Development\ws
       build64\epan\dfilter\dfilter.vcxproj]
2022-04-11 22:23:13 +01:00
João Valverde 2f02cd6e19 dfilter: Handle missing error location more gracefully
If we don't have an offset, don't print anything with underline.

Also it can underline filters using macros correctly now.

$ tshark -Y 'ip and ${private_ipv4:ip.sr}' -r /dev/null
tshark: Left side of "==" expression must be a field or function, not "ip.sr".
    ip and ip.sr == 192.168.0.0/16 or ip.sr == 172.16.0.0/12 or ip.sr == 10.0.0.0/8
           ^~~~~
2022-04-11 21:03:06 +00:00
João Valverde 24443fa33a tshark: Add underline to dfilter errors
$ tshark -Y 'frame.number == 123foobar and ip' -r /dev/null
tshark: "123foobar" is not a valid number.
    frame.number == 123foobar and ip
                    ^~~~~~~~~
2022-04-11 19:25:37 +00:00
Gerald Combs 3086774fa6 wsutil: Add configuration namespaces.
Rename init_progfile_dir to configuration_init. Add an argument which
specifies our configuration namespace, which can be "Wireshark"
(default) or "Logwolf".
2022-04-04 09:39:27 -07:00
João Valverde 842f53c329 Revert "epan: Allow nested dependent packets"
This reverts commit 2d8607e7e0.

This reverts commit be915d7374.

Introduces a segmentation fault, needs more work.
2022-03-28 12:40:21 +00:00
Guy Harris 109b92b5d7 wiretap: have wtap_dump_close() provide a "needs to be reloaded" indication.
This allows the "needs to be reloaded" indication to be set in the close
process, as is the case for ERF; having a routine that returns the value
of that indication is not useful if it gets seet in the close process,
as the handle for the wtap_dumper is no longer valid after
wtap_dump_close() finishes.

We also get rid of wtap_dump_get_needs_reload(), as callers should get
that information via the added argument to wtap_dump_close().

Fixes #17989.
2022-03-14 19:12:20 +00:00
Sake Blok be915d7374 epan: Allow nested dependent packets
Save all dependent frames when there are multiple levels
of reassembly.
2022-03-06 23:43:03 +00:00
Chuck Craft 8176303d9d tshark: -G plugins - add codecs to output 2022-02-28 17:32:29 +00:00
Gerald Combs 0bb4b44e2e TShark: Don't yell at the user. 2022-02-26 19:12:18 +00:00
Chuck Craft 393c2ec9f2 tshark: -G only accepted as first option 2022-02-26 17:59:37 +00:00
John Thacker 939972800e Strip Headers: Add separate menu dialog, tshark help
Add a separate menu for Strip Headers (similar to Export PDU, but exporting
to an encapsulation other than WIRESHARK_UPPER_PDU everything for
that encapsulation). Add to the usage output of tshark for the "-U"
option which encapsulation a export tap will produce.
2022-02-25 20:29:16 -05:00
David Perry e2fab18853 wsutil: New API to gather compile/runtime info 2022-02-24 13:27:08 +00:00
David Perry 70d432c357 Remove editor modelines and .editorconfig exceptions from root files 2022-02-20 19:39:37 +00:00
David Perry fc3f061829 Differentiate `-c` from `-a packets:` 2022-02-11 01:54:53 +00:00
David Perry 1e0d117eb7 Specify directory for temporary captures 2022-02-09 14:32:28 +00:00
Dr. Lars Völker ef43fd48b4 tshark: improve robustness for PCAPNGs not starting with IDBs
The PCAPNG code assumes that PCAPNGs start with IDBs, which might not be
true. This patch adds a workaround for Tshark to process such files.
2022-01-16 08:55:24 +00:00
Jim Young b5f89dbe2d tshark: Add new long option --hexdump <hexoption> 2022-01-13 01:18:38 +00:00
Moshe Kaplan 67f05835ca Fix more repeated words throughout
Fixes more repeated words seen throughout
the code base.
2021-12-31 22:50:40 +00:00
Gerald Combs 87eca12c38 Docs: Document our diagnostic output options.
Add docs/diagnostic-options.adoc, which is a snippet that documents our
various --log-* options. Include it in the dumpcap, rawshark, and tshark
man pages.

Make the ws_log_print_usage output more consistent.
2021-12-27 08:04:25 +00:00
João Valverde 0ccd69e530 Replace g_strdup_printf() with ws_strdup_printf()
Use macros from inttypes.h.
2021-12-19 21:21:58 +00:00
João Valverde fe5248717f Replace g_snprintf() with snprintf()
Use macros from inttypes.h with format strings.
2021-12-19 20:06:13 +00:00
João Valverde 1f68f87807 CLI: Use a better error message for obsolete preferences
Say that the preference is "obsolete", not "unknown".

Wireshark GUI already uses this language.
2021-12-08 10:43:02 +00:00
Chuck Craft a541fcb528 docs/tshark: proper name is lopsided CamelCase (TShark)
This is a first pass that covers the WSDG, WSUG, man page, a code
comment and a README. Plenty left to do in the Debian files, a few
Lua examples and other misc files.
2021-10-21 19:54:20 +00:00
João Valverde 5362d0c31b ws_getopt: Rename struct and macros
This is part of the API and should also be renamed to avoid conflicts.
2021-09-30 13:59:28 +00:00
João Valverde 8df2a73594 Use the musl in-tree getopt_long() everywhere
Besides the obvious limitation of being unavailable on Windows,
the standard is vague about getopt() and getopt_long() has many
non-portable pitfalls and buggy implementations, that increase
the maintainance cost a lot. Also the GNU libc code currently
in the tree is not suited for embedding and is unmaintainable.

Own maintainership for getopt_long() and use the musl implementation
everywhere. This way we don't need to worry if optreset is available,
or if the $OPERATING_SYSTEM version behaves in subtly different ways.

The API is under the Wireshark namespace to avoid conflicts with
system headers.

Side-note, the Mingw-w64 9.0 getopt_long() implementation is buggy
with opterr and known to crash. In my experience it's a headache to
use the embedded getopt implementation if the system provides one.
2021-09-17 00:43:54 +01:00
David Perry d3d4e4b135 Show error for `-X lua_script` if no Lua support
Wireshark/tshark may be built without Lua support. This patch adds an
error message if the user specifies the `-X lua_script` command-line
argument to a program built without Lua support, so the user is not left
wondering why their script isn't working.
2021-08-30 08:01:05 -04:00
David Perry 6e12643f19 [#17478] free blocks in more places
Bug 17478 was caused by `wtap_rec.block` being allocated for each
packet, but not freed when it was done being used -- typically at the
end of a loop.

Rather than requiring each caller of `wtap_read()` to know to free a
member of `rec`, I added a new function `wtap_rec_reset()` for a
slightly cleaner API. Added calls to it everywhere that seemed to make
sense.

Fixes #17478
2021-08-10 00:08:15 +00:00
Guy Harris 0822e8b3e5 tshark: fix the checks for --capture-comment.
Move those checks out of #ifdef HAVE_LIBPCAP/#endif, as that option is
supported even if we don't build with pcap - it's also used when reading
one file and writing another.

Don't check for pcapng when deciding whether, when reading from an
existing capture file, we can write it with added file comments; check
whether the specified file type supports file comments and, if it
doesn't, report all file formats that do as part of the error.
2021-07-15 02:10:52 -07:00
Guy Harris 0a9ef601d2 Clean up handling of --capture-comment.
Don't store the comments in a capture_options structure, because that's
available only if we're being built with capture support, and
--capture-comment can be used in TShark when reading a capture file and
writing another capture file, with no live capture taking place.

This means we don't handle that option in capture_opts_add_opt(); handle
it in the programs that support it.

Support writing multiple comments in dumpcap when capturing.

These changes also fix builds without pcap, and makes --capture-comment
work in Wireshark when a capture is started from the command line with
-k.

Update the help messages to indicate that --capture-comment adds a
capture comment, it doesn't change any comment (much less "the" comment,
as there isn't necessarily a single comment).

Update the man pages:

- not to presume that only pcapng files support file comments (even if
that's true now, it might not be true in the future);
- to note that multiple instances of --capture-comment are supported,
and that multiple comments will be written, whether capturing or reading
one file and writing another;
- clarify that Wireshark doesn't *discard* SHB comments other than the
first one, even though it only displays the first one;
2021-07-15 05:43:36 +00:00
Guy Harris dfef4a750d Rename LONGOPT_NUM_CAP_COMMENT to LONGOPT_CAPTURE_COMMENT.
The latter is what editcap calls --capture-comment, and the _NUM serves
no purpose whatsoever.  One #define name for it suffices.
2021-07-14 09:51:54 +00:00
David Perry 67b54e8b66 tshark: allow --capture-comment when reading a file
Allows adding one or more capture comments to a new pcapng file when
tshark is reading from a file. Currently, tshark only allows setting one
capture comment, and that only when doing a live capture.

The use case for this feature is given in bug #15005.
I decided to allow multiple capture comments to match the same ability
in `editcap`.

To allow this change, I changed the function signature of
`process_cap_file()` so it takes a `capture_options` struct instead of
individual parameters that affect the capture.
2021-07-14 04:34:52 +00:00
David Perry 73087d6fb4 Use wtap_blocks for packet comments
Mostly functioning proof of concept for #14329. This work is intended to
allow Wireshark to support multiple packet comments per packet.

Uses and expands upon the `wtap_block` API in `wiretap/wtap_opttypes.h`.
It attaches a `wtap_block` structure to `wtap_rec` in place of its
current `opt_comment` and `packet_verdict` members to hold OPT_COMMENT
and OPT_PKT_VERDICT option values.
2021-07-07 18:40:24 +00:00
Andre Luyer 9f8e6b1acb tshark/wireshark: Fix check ring buffer option for packets
tshark and wireshark did not allow only -b packets:value option, while dumpcap does.
This change adds the same check in tshark and wireshark as in dumpcap.

Quick fix for issue mentioned at https://ask.wireshark.org/question/23437/why-does-tshark-b-packetsvalue-not-work/
2021-07-04 19:55:59 +00:00
João Valverde 100876337a Move version_info.[ch] to ui/
Version info is an aspect of UI implementation so move it to
a more appropriate place, such as ui/. This also helps declutter
the top-level.

A static library is appropriate to encapsulate the dependencies
as private and it is better supported by CMake than object libraries.

Also version_info.h should not be installed as a public header.
2021-07-04 10:37:49 +00:00
João Valverde c6a920686c wslog: Check environment initialization for errors
Initialiaze the cmdarg error stream earlier.

Dumpcap also needs to know earlier if it is running in capture
child mode.
2021-06-26 00:18:26 +01:00
João Valverde 759bb234d0 wslog: Check if we are initialized and add missing inits
Instead of receiving the program name from GLib, pass it explicitly
to ws_log_init() instead  and use that to initialize the GLib program
name.

ws_log_parse_args() will now exit the program when it encounters an
argument error if exit_failure >= 0.
2021-06-21 16:03:29 +00:00
João Valverde 0e50979b3f Replace g_assert() with ws_assert() 2021-06-19 01:23:31 +00:00
João Valverde c5b3842639 wslog: Add more documentation 2021-06-17 12:00:10 +01:00
João Valverde e86ac706ca wslog: Parse cmd line options in one pass 2021-06-14 22:05:35 +00:00
João Valverde 5ddc007023 wslog: Include pid in format 2021-06-14 14:18:38 +01:00
João Valverde 5a662ba3fb wslog: Add support for domain filtering
A domain filter can be given in the environment variable
'WS_LOG_DOMAINS' or in a command-line options "--log-domains".

The filter is specified as a comma separated case insensitive list,
for example:

    ./tshark  --log-domains=main,capture

Domain data type switches from an enum to a string. There is no
constaint on adding new domains, neither in code or at runtime.
The string format is arbitrary, only positive matches will produce
output.
2021-06-14 13:13:12 +01:00
João Valverde dc7f0b88bb Refactor our logging and extend the wslog API
Experience has shown that:

  1. The current logging methods are not very reliable or practical.
A logging bitmask makes little sense as the user-facing interface (who
would want debug but not crtical messages for example?); it's
computer-friendly and user-unfriendly. More importantly the console
log level preference is initialized too late in the startup process
to be used for the logging subsystem and that fact raises a number
of annoying and hard-to-fix usability issues.

  2. Coding around G_MESSAGES_DEBUG to comply with our log level mask
and not clobber the user's settings or not create unexpected log misses
is unworkable and generally follows the principle of most surprise.
The fact that G_MESSAGES_DEBUG="all" can leak to other programs using
GLib is also annoying.

  3. The non-structured GLib logging API is very opinionated and lacks
configurability beyond replacing the log handler.

  4. Windows GUI has some special code to attach to a console,
but it would be nice to abstract away the rest under a single
interface.

  5. Using this logger seems to be noticeably faster.

Deprecate the console log level preference and extend our API to
implement a log handler in wsutil/wslog.h to provide easy-to-use,
flexible and dependable logging during all execution phases.

Log levels have a hierarchy, from most verbose to least verbose
(debug to error). When a given level is set everything above that
is also enabled.

The log level can be set with an environment variable or a command
line option (parsed as soon as possible but still later than the
environment). The default log level is "message".

Dissector logging is not included because it is not clear what log
domain they should use. An explosion to thousands of domains is
not desirable and putting everything in a single domain is probably
too coarse and noisy. For now I think it makes sense to let them do
their own thing using g_log_default_handler() and continue using the
G_MESSAGES_DEBUG mechanism with specific domains for each individual
dissector.

In the future a mechanism may be added to selectively enable these
domains at runtime while trying to avoid the problems introduced
by G_MESSAGES_DEBUG.
2021-06-11 09:40:28 +00:00
Stig Bjørlykke 68e360bf04 ui: Return length from ssl_export_sessions()
All users of ssl_export_sessions() calculates the length of the
returned string, so let's return the length instead.
2021-06-07 08:59:02 +02:00
Stig Bjørlykke 5dbaa8d3b2 wsutil: Add filesystem write_file_binary_mode()
Add a generic function to write content to file. Use this on write
TLS session keys from UI and tshark, and for export objects.

Remove the now unused export_object_ui.[ch].
2021-06-07 06:24:28 +00:00
Stig Bjørlykke 2b29269f5d tshark: Add option to export TLS session keys
Add a new option --export-tls-session-keys <keyfile> to tshark
to export TLS session keys.
2021-06-06 13:32:40 +02:00
John Thacker 17f2fc32f7 tshark: Correct documentation about name resolution.
The tshark help and documentation has been incorrect for at least
eight years, claiming that by default all name resolutions are
performed. Fixes #11762
2021-05-26 23:09:53 +00:00