aboutsummaryrefslogtreecommitdiffstats
path: root/editcap.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-07Move ui/exit_codes.h to include/João Valverde1-32/+32
2023-02-06Do not require using wsgcrypt.hJoão Valverde1-1/+1
The reason to use wsgcrypt.h was to wrap it around DIAG_OFF() macros and that should no longer be necessary.
2023-02-04cli: Process IDBs after the final packet recordJohn Thacker1-6/+16
Process IDBs that are read after the final packet record returned by wtap_read() in tshark, editcap, and mergecap. Ping #18449
2023-01-30wiretap: Preserve NRBs with editcap, mergecap, and tsharkJohn Thacker1-1/+3
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-04editcap: add sll and sll2 headers + offsetofJonas Falkevik1-10/+47
add sll and sll2 header structs to enable the usage of offsetof into the structs. mainly to make it clear on where to read and set data.
2023-01-04editcap: flag to set unused bytes in SLL headersJonas Falkevik1-0/+45
Unused bytes in SLL Link Layer address can be random bytes. Which makes the duplicate check think the packets are different. Even if the unused bytes was the only difference. This flag enables editcap to set the unused bytes to zeros to enable the duplicate check to detect duplicates.
2022-10-08Add log init message to main()João Valverde1-0/+3
2022-08-02Make sure we don't create comment options longer than 65535 bytes.Guy Harris1-0/+30
Check in both editcap and Wireshark to make sure that comments have fewer than 65536 bytes before accepting them. This shoudl fix #18235, although there should also be checks in libwiretap to catch cases where the user interface code doesn't do the check (it should be done in the UI so that the user gets notified appropriately).
2022-06-16editcap/mergecap: swap 'v'|'V' options to match other CLI utilitiesChuck Craft1-10/+10
Closes #18134
2022-04-07editcap: Document use of stdin and stdoutJohn Thacker1-1/+1
Editcap accepts '-' for stdin or stdout, document that. Also change an incorrect statement that claims that the '-v' flag writes to standard output; it writes to standard error.
2022-04-04wsutil: Add configuration namespaces.Gerald Combs1-5/+5
Rename init_progfile_dir to configuration_init. Add an argument which specifies our configuration namespace, which can be "Wireshark" (default) or "Logwolf".
2022-03-14wiretap: have wtap_dump_close() provide a "needs to be reloaded" indication.Guy Harris1-4/+4
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-02-24wsutil: New API to gather compile/runtime infoDavid Perry1-1/+1
2022-01-07Adding secret management in DSB.Jérôme HAMM1-0/+1
2021-12-27Use a wrapper function to call strptime()João Valverde1-14/+0
Encapsulate the feature requirements for strptime() in a portability wrapper. Use _GNU_SOURCE to expose strptime. It should be enough on glibc without the side-effect of selecting a particular SUS version, which we don't need and might hide other definitions.
2021-12-19Replace g_snprintf() with snprintf()João Valverde1-2/+2
Use macros from inttypes.h with format strings.
2021-12-01nstime: Support ISO 8601 basic formatJohn Thacker1-1/+1
Add support in iso8601_to_nstime for the ISO 8601 Basic date/time format that lacks the - and : separators.
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-56/+45
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-08-09editcap: if -T was specified, change the linktype of all interfaces.Guy Harris1-8/+56
Don't just change the linktype of the file (if it has one) and the linktypes of all the packets, change the linktype of all interfaces as well. Fixes #17520.
2021-08-10[#17478] free blocks in more placesDavid Perry1-0/+3
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-07-08editcap: clean up some comments for consistency.Guy Harris1-2/+2
2021-07-08Consistently refer to blocks that have been modified as "modified".Guy Harris1-2/+2
"User" sounds as if the blocks belong to the user; at most, the current user might have modified them directly, but they might also have, for example, run a Lua script that, unknown to them, modified comments. Also, a file might have "user comments" added by a previous user, who them wrote the file and and provided it to the current user. "Modified" seems a bit clearer than "changed".
2021-07-07Use wtap_blocks for packet commentsDavid Perry1-5/+4
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-04Move version_info.[ch] to ui/João Valverde1-1/+1
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-06-26wslog: Check environment initialization for errorsJoão Valverde1-3/+3
Initialiaze the cmdarg error stream earlier. Dumpcap also needs to know earlier if it is running in capture child mode.
2021-06-21wslog: Check if we are initialized and add missing initsJoão Valverde1-0/+7
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-19Replace g_assert() with ws_assert()João Valverde1-3/+4
2021-06-17Make various names match the name of the systemd journal export block.Guy Harris1-2/+2
The name of the block, in the pcapng specification is the systemd Journal Export Block; add "export" after "journal" in various variable/enum/define names.
2021-04-30Cast away the return value of g_strlcpy() and g_strlcat().Guy Harris1-1/+1
Most of the time, the return value tells us nothing useful, as we've already decided that we're perfectly willing to live with string truncation. Hopefully this keeps Coverity from whining that those routines could return an error code (NARRATOR: They don't) and thus that we're ignoring the possibility of failure (as indicated, we've already decided that we can live with string truncation, so truncation is *NOT* a failure).
2021-04-13Add a new header defining commonly-used exit codes.Guy Harris1-4/+5
"Commonly-used" meaning "used by more than one source file". Clean up the exit codes, combining some duplicates with different names, and using some instead of raw numbers in some places.
2021-03-15Remove unnecessary inclues of wiretap/pcapng.h.Guy Harris1-1/+0
2021-03-15Add more error-reporting routines that call through a function pointer.Guy Harris1-19/+25
Have routines to report capture-file errors, using libwireshark error codes and strings, that call through a pointer, so they can pop up dialogs in GUI apps, print a message to the standard error on command-line apps, and possibly do something different on server programs. Have init_report_message() take a pointer to structure containing those function pointers, rather than the function pointers themselves, as arguments. Make other API changes to make that work.
2021-02-23wiretap: eliminate the pcap/nspcap/pcapng WTAP_FILE_TYPE_SUBTYPE_ values.Guy Harris1-1/+5
Register the pcap and pcapng file types/subtypes rather than hardwiring them into the table. Call the registration routines for them directly, rather than through a generated table; they're always supposed to be there, as some code in Wireshark either writes only one of those formats or defaults to writing one of those formats. Don't run their source code through the registration-routine-finder script. Have the file type/subtype codes for them be directly exported to the libwiretap core, and provide routines to return each of them, to be used by the aforementioned code. When reporting errors with cfile_write_failure_message(), use wtap_dump_file_type_subtype() to get the file type/subtype value for the wtap_dumper to which we're writing, rather than hardcoding it. Have the "export PDU" code capable of supporting arbitrary file types/subtypes, although we currently only use pcapng. Get rid of declarations of now-static can_write_encap and dump_open routines in various headers.
2021-02-21wiretap: have file handlers advertise blocks and options supported.Guy Harris1-6/+14
Instead of a "supports name resolution" Boolean and bitflags for types of comments supported, provide a list of block types that the file type/subtype supports, with each block type having a list of options supported. Indicate whether "supported" means "one instance" or "multiple instances". "Supports" doesn't just mean "can be written", it also means "could be read". Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to indicate that it provides, in addition to information about the interface, an ID (implicitly, in pcapng files, by its ordinal number) that is associated with every packet in the file. Emphasize that in comments - just because your capture file format can list the interfaces on which a capture was done, that doesn't mean it supports this; it doesn't do so if the file doesn't indicate, for every packet, on which of those interfaces it was captured (I'm looking at *you*, Microsoft Network Monitor...). Use APIs to query that information to do what the "does this file type/subtype support name resolution information", "does this file type/subtype support all of these comment types", and "does this file type/subtype support - and require - interface IDs" APIs did. Provide backwards compatibility for Lua. This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's iptrace; do so.
2021-02-21editcap: Fixup our help output.Gerald Combs1-1/+1
Make sure list_capture_types prints to the designated stream so that tools/update-tools-help.py works correctly for `editcap -F`.
2021-02-17wiretap: more work on file type/subtypes.Guy Harris1-20/+7
Provide a wiretap routine to get an array of all savable file type/subtypes, sorted with pcap and pcapng at the top, followed by the other types, sorted either by the name or the description. Use that routine to list options for the -F flag for various commands Rename wtap_get_savable_file_types_subtypes() to wtap_get_savable_file_types_subtypes_for_file(), to indicate that it provides an array of all file type/subtypes in which a given file can be saved. Have it sort all types, other than the default type/subtype and, if there is one, the "other" type (both of which are put at the top), by the name or the description. Don't allow wtap_register_file_type_subtypes() to override any existing registrations; have them always register a new type. In that routine, if there are any emply slots in the table, due to an entry being unregistered, use it rather than allocating a new slot. Don't allow unregistration of built-in types. Rename the "dump open table" to the "file type/subtype table", as it has entries for all types/subtypes, even if we can't write them. Initialize that table in a routine that pre-allocates the GArray before filling it with built-in types/subtypes, so it doesn't keep getting reallocated. Get rid of wtap_num_file_types_subtypes - it's just a copy of the size of the GArray. Don't have wtap_file_type_subtype_description() crash if handed an file type/subtype that isn't a valid array index - just return NULL, as we do with wtap_file_type_subtype_name(). In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_ names for the backwards-compatibility names - map those names to the current names, and then look them up. This reduces the number of uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values. Clean up the type of wtap_module_count - it has no need to be a gulong. Have built-in wiretap file handlers register names to be used for their file type/subtypes, rather than building the table in init.lua. Add a new Lua C function get_wtap_filetypes() to construct the wtap_filetypes table, based on the registered names, and use it in init.lua. Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended only for internal use in init.lua, so they can be made available from Lua without being documented. Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use it, as it can just request arrays of types, and the space of type/subtype codes can be sparse due to registration in any case, so code has to be careful using it. wtap_get_num_file_types_subtypes() is no longer used, so remove it. It returns the number of elements in the file type/subtype array, which is not necessarily the name of known file type/subtypes, as there may have been some deregistered types, and those types do *not* get removed from the array, they just get cleared so that they're available for future allocation (we don't want the indices of any registered types to changes if another type is deregistered, as those indicates are the type/subtype values, so we can't shrink the array). Clean up white space and remove some comments that shouldn't have been added.
2021-02-14Enable -Wredundant-decls.Guy Harris1-5/+10
Add it to the default list of checks, and fix some errors it causes. (Sadly, it doesn't work in CLang.)
2021-02-13wiretap: file types have a name and a description.Guy Harris1-4/+4
The "short name" is really just the name, used to look it up. The "name" is really a description intended solely for human consumption. Rename the fields, and the functions that access them, to match. The "description" maintained by Lua for file type handlers is used *only* for one debugging message; we should probably just eliminate it. Call it an "internal description" for now.
2021-02-09wiretap: clean up WTAP_BLOCK_ names.Guy Harris1-1/+1
Remove NG from the names - it adds nothing. Don't use the abbreviations for pcapng block names, spell out what the block does (e.g. "WTAP_BLOCK_DECRYPTION_SECRETS" rather than "WTAP_BLOCK_DSB"), to make it more obvious what the block does. Spell out some other abbreviations. Add WTAP_BLOCK_PACKET for future use for packet blocks; there's no need to distinguish between the Enhanced Packet Block, the Simple Packet Block, and the deprecated Packet Block here.
2021-01-11editcap: add support for epoch timestamps in `-A` and `-B` optionsChema Gonzalez1-1/+2
Inspired in https://gitlab.com/wireshark/wireshark/-/merge_requests/1618. Tested: Timestamps on file used for comparison: ``` $ tshark -r test/captures/snakeoil-dtls.pcap -T fields -e frame.time_epoch 1150121069.248818000 1150121069.249193000 1150121069.251152000 1150121069.251384000 1150121069.293686000 1150121069.319315000 1150121075.230753000 1150121105.510885000 1150121105.510934000 ``` Before: ``` $ ./build/run/editcap -B 1150121069.3 test/captures/snakeoil-dtls.pcap - editcap: "1150121069.3" isn't a valid date and time $ ./build/run/editcap -A 1150121069.3 test/captures/snakeoil-dtls.pcap - editcap: "1150121069.3" isn't a valid date and time $ ./build/run/editcap -A 1150121069 test/captures/snakeoil-dtls.pcap - editcap: "1150121069" isn't a valid date and time $ ./build/run/editcap -B 1150121069 test/captures/snakeoil-dtls.pcap - editcap: "1150121069" isn't a valid date and time ``` After: ``` $ ./build/run/editcap -A 1150121069.3 test/captures/snakeoil-dtls.pcap - | tshark -r - -T fields -e frame.time_epoch 1150121069.319315000 1150121075.230753000 1150121105.510885000 1150121105.510934000 $ ./build/run/editcap -A 1150121069 test/captures/snakeoil-dtls.pcap - | tshark -r - -T fields -e frame.time_epoch 1150121069.248818000 1150121069.249193000 1150121069.251152000 1150121069.251384000 1150121069.293686000 1150121069.319315000 1150121075.230753000 1150121105.510885000 1150121105.510934000 $ ./build/run/editcap -B 1150121069.3 test/captures/snakeoil-dtls.pcap - | tshark -r - -T fields -e frame.time_epoch 1150121069.248818000 1150121069.249193000 1150121069.251152000 1150121069.251384000 1150121069.293686000 $ ./build/run/editcap -B 1150121069 test/captures/snakeoil-dtls.pcap - | tshark -r - -T fields -e frame.time_epoch ```
2021-01-08Add iso8601_to_nstime() for editcap and nettraceDavid Perry1-69/+19
This adds a function to parse a string date-time in ISO 8601 format into a `nstime_t` structure. It's based on code from epan/tvbuff.c and wiretap/nettrace_3gpp_32_423.c and meant to eventually replace both. (Currently only replaces the latter.) Since most of Wireshark expects ISO 8601 date-times to fit a fairly strict pattern, iso8601_to_nstime() currently rejects date-times without separators between the components, even though ISO 8601 actually permits this. This could be revisited later. Also uses iso8601_to_nstime in editcap to parse the -A/-B options, thus allowing the user to specify a time zone if desired. (See #17110)
2020-12-31editcap: clarify relation between -A/-B and -rJaap Keuter1-2/+2
Change wording so that the order of processing becomes more apparent. Closes #17109
2020-12-23editcap: one more integer -> Boolean.Guy Harris1-4/+4
selected() returns a Boolean value indicating whether the packet with a given number was selected by the packet-range arguments or not.
2020-12-23editcap: make verbose a Boolean as well.Guy Harris1-2/+12
And, to catch people habituated to -r and -v toggling the flag, fail if it's already been set, to dishabituate them. Not having them toggle makes it easier to document their semantics.
2020-12-23editcap: treat the "keep packets" flag as a Boolean.Guy Harris1-3/+3
Give it the type gboolean, initialize it to FALSE, and have -r set it to TRUE. This makes it a little clearer what it's doing.
2020-12-22Let the CLI programs tell about how to show their versionJaap Keuter1-0/+1
Add to the help text the option to show the version of the CLI program.