aboutsummaryrefslogtreecommitdiffstats
path: root/tshark.c
AgeCommit message (Collapse)AuthorFilesLines
2023-02-10Move ui/clopts_common.[ch] to wsutilJoão Valverde1-1/+1
2023-02-10Move ui/cmdarg_err.[ch] to wsutilJoão Valverde1-1/+1
2023-02-07Move ui/version_info.[ch] to wsutilJoão Valverde1-1/+1
2023-02-07tshark: Preserve options when dissecting packets and writingJohn Thacker1-0/+10
epan_dissect_run_* and epan_dissect_reset unreference the packet block that is part of the record, which frees it if the ref count drops to zero. However, tshark needs the block later to, e.g., copy the options. process_cap_file_[single|second]_pass still unreference and free the block with wtap_rec_reset() at the end of each packet loop. Fix #18693
2023-02-07wiretap, pcapng: Distinguish WTAP_ENCAP_UNKNOWN and _NONEJohn Thacker1-18/+0
WTAP_ENCAP_UNKNOWN is used for two different cases: 1. Encapsulation type values that are unsupported by libwiretap or bogus values (and thus "unknown" to libwiretap). 2. An initial state where the encapsulation type is "not yet" known for a file type like pcapng without a single encapsulation type in the header, before any packets or interfaces that set the encapsulation type have been read. (If the file has no packets, this may be the value after the file is entirely read in.) This can be the value when an output file is written out simultaneously with reading an input file, rather than reading the entire input file first, and, e.g., there is a custom block before any IDBs. The first case can never be handled when writing out a file, but the second case can possibly be handled, so long as (for pcapng) IDBs are available to write when they become necessary, or (for file types like pcap with a single link-layer type in the header) the writer waits until a link-layer type is seen to create the output header. (It is possible, of course, that writing would fail in the middle if an unsupported encapsulation type appears, or if the encapsulation becomes per-packet for file types that don't support that, but that is an unavoidable risk when writing without reading the entire input file(s).) Introduce WTAP_ENCAP_NONE for the second case, and use it for pcapng, where we guarantee that any necessary IDBs will be passed along. Continue to use WTAP_ENCAP_UNKNOWN for the first case. Allow pcapng files to open a file for writing with WTAP_ENCAP_NONE. There are some other file types that support per-packet link-types, and could also use WTAP_ENCAP_NONE, but they require more work to generate IDBs. (Note that all of them currently are impossible to write to pcapng when they have multiple encapsulations, even if the encapsulations are all supported by pcapng, because they don't properly generate IDBs.) Remove the workaround in ef43fd48b4f981392a0c61b5e9a804e8f9c85eb4 for tshark writing to pcapng when the source file is WTAP_ENCAP_UNKNOWN, since now such files will be WTAP_ENCAP_NONE and work properly (and also work in editcap, mergcap, etc.) Along with 8cddc32d35e36d9962495c3d4358842ea88aac41, fix #18449.
2023-02-07Move ui/exit_codes.h to include/João Valverde1-73/+73
2023-02-04cli: Process IDBs after the final packet recordJohn Thacker1-3/+13
Process IDBs that are read after the final packet record returned by wtap_read() in tshark, editcap, and mergecap. Ping #18449
2023-02-03tshark: clean up indentation.Guy Harris1-1/+1
2023-02-03tshark: fix previous fix for memory leak.Guy Harris1-1/+1
Pass the correct filter variable to warn_about_capture_filter(); Fixes the fix for #18837.
2023-02-03tshark: plug a memory leak.Guy Harris1-21/+30
Put the "attempt to compile a filter string as a capture filter" code into a common routine, and, if the attempt succeeds, free up the generated capture filter code. Fixes #18837.
2023-01-30wiretap: Preserve NRBs with editcap, mergecap, and tsharkJohn Thacker1-0/+20
Use a pointer to the growing array of NRBs from the source file, as with DSBs, so as to handle reading NRBs in the middle of a file in one-pass mode. Write NRBs when reading a file with editcap, or in tshark when not dissecting packets and writing our own NRB. Continue not to write the NRB if we're supplying our own list of address info instead. If we have already read the entire source file in (such as in two-pass tshark), move all the NRBs to the beginning of the file before packets, as done with DSBs. When merging files with mergecap, write both sets of NRBs. (There is no attempt to merge the NRBs by looking for common entries.) Check for name resolution data in the middle of dumping a file, not just at the end, and check for DSBs at the end of a file, after all the packets. This means that Wireshark no longer writes the NRB at the very end of the file after all the packets (which is worse for future one-pass reads), and DSBs after all packets are preserved. Ping #15502
2023-01-28epan: Use hash table for dependent framesTomasz Moń1-2/+2
Dependent frames list order does not matter and thus significantly faster data structure can be used. Replace the list with hash table to avoid excessive CPU usage when opening files containing reassembled packets consisting of large number of fragments.
2023-01-06epan: Allow nested dependent packetsSake Blok1-2/+2
Save all dependent frames when there are multiple levels of reassembly. This is a retry of !6329, combined with the fix in !6509 which were reverted in !6545. epan: fix a segfault, introduced in !6329
2022-11-30dfilter: Replace compile booleans arguments with a bit flagJoão Valverde1-1/+1
2022-11-30dfilter: Add optimization flagJoão Valverde1-1/+1
When we are just testing code to see if it compiles performing optimizations is wasteful. Add an option to disable them.
2022-11-28dfilter: Return an error object instead of stringJoão Valverde1-6/+7
Return an struct containing error information. This simplifies the interface to more easily provide richer diagnostics in the future. Add an error code besides a human-readable error string to allow checking programmatically for errors in a robust manner. Currently there is only a generic error code, it is expected to increase in the future. Move error location information to the struct. Change callers and implementation to use the new interface.
2022-10-08Add log init message to main()João Valverde1-0/+1
2022-08-23Rename some functions and types for endpoint tables.Guy Harris1-1/+1
The "conversation table" mechanism supports two types of tables, one for the "Conversations" menu item under "Statistics" and one for the "Endpoints" menu item under "Statistics". The first of them shows statistics for conversations at various layers of the networking stack; the second of them shows statistics for endpoints at various layers of the networking stack. The latter is *not* a table of hosts; an endpoint might be a host, identified by an address at some network level (MAC, IP, etc.), or it might be a port on a host, identified by an address/port pair. Some data types, function names, etc. use "host" or "hostlist" or other terms that imply that an endpoint is a host; change them to speak of endpoints rather than hosts, using names similar to the corresponding functions for conversations. Provide wrapper functions and typedefs for backwards source and binary compatibility; mark them as deprecated in favor of the new names. Clean up some comment errors found in the process.
2022-08-22spelling: "two pass" -> two-passChuck Craft1-2/+2
2022-07-30capture: Move capture pipe polling out of UITomasz Moń1-89/+0
Both CLI and Qt interfaces spin GLib mainloop. Move the capture pipe polling into common code to reduce code duplication.
2022-07-28tshark: Run GLib mainloop during captureTomasz Moń1-72/+19
Use the timer polling approach on Windows. GLib timer callbacks execute in main thread. Remove useless mutex as there is no point in protecting resources if only can thread can access the resources. Simply wait on capture child handle instead of periodically checking process state. On Unix systems, register the pipe fd for polling inside GLib mainloop.
2022-07-12epan: Respect custom column resolved/unresolved status everywhereJohn Thacker1-10/+11
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-11tshark: Respect -Q optionUli Heilmeier1-3/+5
Suppress non-error messages when -Q is set. Fixes: #18186
2022-07-07cli: Copy global configuration profile to personal as with the GUIJohn Thacker1-0/+23
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-04-12tshark: Add a --selected-frame optionJoão Valverde1-0/+22
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-11Try to fix a narrowing warningJoão Valverde1-1/+1
"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-11dfilter: Handle missing error location more gracefullyJoão Valverde1-14/+37
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-11tshark: Add underline to dfilter errorsJoão Valverde1-3/+10
$ tshark -Y 'frame.number == 123foobar and ip' -r /dev/null tshark: "123foobar" is not a valid number. frame.number == 123foobar and ip ^~~~~~~~~
2022-04-04wsutil: Add configuration namespaces.Gerald Combs1-1/+1
Rename init_progfile_dir to configuration_init. Add an argument which specifies our configuration namespace, which can be "Wireshark" (default) or "Logwolf".
2022-03-28Revert "epan: Allow nested dependent packets"João Valverde1-2/+2
This reverts commit 2d8607e7e039db2b189403e9941ab8cbd0a9d466. This reverts commit be915d7374be9d64b6fd85819fcd98b300f511af. Introduces a segmentation fault, needs more work.
2022-03-14wiretap: have wtap_dump_close() provide a "needs to be reloaded" indication.Guy Harris1-2/+2
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-06epan: Allow nested dependent packetsSake Blok1-2/+2
Save all dependent frames when there are multiple levels of reassembly.
2022-02-28tshark: -G plugins - add codecs to outputChuck Craft1-0/+2
2022-02-26TShark: Don't yell at the user.Gerald Combs1-2/+2
2022-02-26tshark: -G only accepted as first optionChuck Craft1-0/+5
2022-02-25Strip Headers: Add separate menu dialog, tshark helpJohn Thacker1-2/+2
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-24wsutil: New API to gather compile/runtime infoDavid Perry1-10/+8
2022-02-20Remove editor modelines and .editorconfig exceptions from root filesDavid Perry1-3680/+3672
2022-02-11Differentiate `-c` from `-a packets:`David Perry1-28/+54
2022-02-09Specify directory for temporary capturesDavid Perry1-1/+10
2022-01-16tshark: improve robustness for PCAPNGs not starting with IDBsDr. Lars Völker1-0/+18
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-13tshark: Add new long option --hexdump <hexoption>Jim Young1-1/+61
2021-12-31Fix more repeated words throughoutMoshe Kaplan1-1/+1
Fixes more repeated words seen throughout the code base.
2021-12-27Docs: Document our diagnostic output options.Gerald Combs1-1/+2
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-19Replace g_strdup_printf() with ws_strdup_printf()João Valverde1-2/+2
Use macros from inttypes.h.
2021-12-19Replace g_snprintf() with snprintf()João Valverde1-8/+8
Use macros from inttypes.h with format strings.
2021-12-08CLI: Use a better error message for obsolete preferencesJoão Valverde1-1/+6
Say that the preference is "obsolete", not "unknown". Wireshark GUI already uses this language.
2021-10-21docs/tshark: proper name is lopsided CamelCase (TShark)Chuck Craft1-1/+1
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-09-30ws_getopt: Rename struct and macrosJoão Valverde1-10/+10
This is part of the API and should also be renamed to avoid conflicts.
2021-09-17Use the musl in-tree getopt_long() everywhereJoão Valverde1-89/+66
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.