aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/file_access.c
AgeCommit message (Collapse)AuthorFilesLines
2023-02-07Update comments in `wiretap/file_access.c`David Perry1-90/+128
2023-02-07wiretap, pcapng: Distinguish WTAP_ENCAP_UNKNOWN and _NONEJohn Thacker1-2/+11
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-01-30wiretap: Preserve NRBs with editcap, mergecap, and tsharkJohn Thacker1-1/+13
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-24wiretap: treat file extensions case-insensitivelyDavid Perry1-1/+8
2022-08-26DLT: Adding support to open DLT filesDr. Lars Völker1-0/+3
This patch allows Wireshark to open DLT files directly.
2022-06-02NSIS: Update some target and filenames.Gerald Combs1-1/+1
Rename the following build targets, similar to the recent macOS target name changes: nsis_package_prep to wireshark_nsis_prep nsis_package to wireshark_nsis Rename some NSIS files to reflect that they're specific to Wireshark. Update the documentation and CI configurations.
2022-06-01file: Only change the file descriptors on a Save with CopyJohn Thacker1-0/+4
If we do a save with copy, so that we just copied the binary file, everything in the wtap structure should be the same except for the filename and the file descriptors, so just change that instead of closing wtap and reopening it. The current behavior of calling wtap_open_offline does not work for files that have blocks (SHBs, IDBs, NRBs, DSBs, ISBs, etc.) in the middle of the file instead of at the beginning, but we shouldn't have to waste time rescanning the entire file either. In the case where a specific file format reader was manually selected, this will keep the same file format as selected instead of switching to the auto-detection when opening the copy, just as SAVE_WITH_MOVE already does and presumably what the user wants. Update wtap_fdreopen to change the wtap struct's pathname if wtap_fdreopen is called with a different filename than currently. Fix #17472
2022-04-13wiretap: Try opening systemd journal files before IxVeriWave.Gerald Combs1-1/+1
The Ixia IxVeriWave .vwr file reader's heuristics matched a journal file here, so place the systemd journal before it in the list.
2022-04-06wiretap: Update a comment.Gerald Combs1-1/+1
Wireshark's file formats are now listed in WiresharkInfo.plist.in.
2022-03-14wiretap: have wtap_dump_close() provide a "needs to be reloaded" indication.Guy Harris1-5/+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-03-12Move Freedesktop files to resources/freedesktop.Gerald Combs1-1/+1
2022-02-09Specify directory for temporary capturesDavid Perry1-2/+2
2021-12-19Replace g_strdup_printf() with ws_strdup_printf()João Valverde1-1/+1
Use macros from inttypes.h.
2021-12-15wiretap: have dummy IDBs set OPT_IDB_TSRESOL if neededJohn Thacker1-0/+6
In wtap_dump_init_dumper(), when constructing a dummy IDB for files that don't have one, if the tsprecision value is anything other than the default, then the OPT_IDB_TSRESOL option also needs to be set. Without it, for a pcapng the timestamps will be written according to the tsprecision and time_units_per_second values, but when it is read, the values will be interpreted incorrectly. It would probably be better if the consistency of these values were enforced.
2021-10-04Read eNode-B raw logsAnders Broman1-0/+3
2021-09-30Qt: Reload Lua FileHandler when having a capture fileStig Bjørlykke1-0/+14
Support reloading a Lua FileHandler when this is in use for a loaded capture file. Prompt to save the file if having unsaved changes because the file must be reloaded. Fixes #17615
2021-09-25libwiretap: fix test for built-in file types.Guy Harris1-1/+1
The file type/subtype for built-in types are <= wtap_num_builtin_file_types_subtypes - the plugin types are given type/subtype values after the last built-in type/subtype value. Fixes #17614.
2021-07-16BLF: Support for BLF file formatDr. Lars Völker1-2/+5
This patch adds first support for the BLF file format.
2021-06-16Replace g_log() calls with ws_log()João Valverde1-10/+12
2021-06-06Replace g_assert() with ws_assert() in placesJoão Valverde1-7/+8
2021-05-11commview: add support for newer NCFX file format.Guy Harris1-2/+4
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-03-15Remove unnecessary includes of wiretap/pcap-encap.h.Guy Harris1-1/+0
2021-03-14libwiretap: make wtap_wtap_encap_to_pcap_encap() private to the library.Guy Harris1-8/+9
Only a tiny amount of code outside libwiretap needs to know about pcap/pcapng LINKTYPE_ values, and all that code needs to know is, for a given LINKTYPE_ value, what the corresponding WTAP_ENCAP_ value is. Nothing should need to know, for a given WTAP_ENCAP_ value, what its LINKTYPE_ value is. Make it the case that nothing *does* need to know, for a given WTAP_ENCAP_ value, what its LINKTYPE_ value is. Export wtap_dump_can_write_encap() and use *that*, in the "import hex dump" code, what formats can be written to a pcap file.
2021-03-11observer: rename source and update name.Guy Harris1-2/+2
Name the source to the code to read Observer files after the file format, not the company that created it, got bought by JDSU, and then ended up in Viavi when JDSU split. Refer to the file format as "Viavi Observer" to reflect that.
2021-03-11libwiretap: don't have a central table of file type/subtype name mappings.Guy Harris1-23/+34
Let individual file type/subtype modules register their backwards-compatibility names, rather than having a centralized table that would need to be updated along with the module.
2021-03-11Observer is now a product of Viavi.Guy Harris1-1/+1
JDSU bought Network Instruments, and then split into Viavi and Lumentum, with Viavi getting Observer.
2021-02-24wiretap: make WTAP_FILE_TYPE_SUBTYPE_UNKNOWN -1 rather than an index.Guy Harris1-33/+4
And get rid of the entry for that type in the table of type/subtypes.
2021-02-24wiretap: add some additional bounds checks for file type/subtype values.Guy Harris1-83/+96
Check to make sure the value is non-negative and less than the number of file type/subtypes. Make it clearer than one check is unnecessary: * pull wtap_dump_open_check() into wtap_dump_init_dumper(), so it's clear that wtap_dump_init_dumper() ensures the validity of the file type/subtype value early on (wtap_dump_can_open() fails if it's not valid); * pull wtap_dump_alloc_wdh() into wtap_dump_init_dumper(), so that the allocation and all the initialiation is done there - that makes it clear that it sets the file_type_subtype member of the wtap_dumper structure before wtap_dump_init_dumper() returns; * have wtap_dump_open_finish() use that value rather than being passed the type/subtype value explicitly, so it's clear that it's dealing with a validated value.
2021-02-23wiretap: rename wtap_register_file_type_subtypes().Guy Harris1-3/+12
It only registers one file type/subtype, so rename it to wtap_register_file_type_subtype(). That will also force plugins to be recompiled; that will produce compile errors for some plugins that didn't change to match the new contents of the file_type_subtype_info structure. Also check to make sure that the registered file type/subtype supports at least one type of block; a file type/subtype that doesn't return *any* blocks and doesn't permit *any* block types to be written is not very useful. That should also catch most if not all other plugins that didn't change to match the new contents of the file_type_subtype_info structure. Don't make errors registering a file type/subtype fatal; just complain, don't register the bogus file type/subtype, and drive on.
2021-02-23wiretap: eliminate the pcap/nspcap/pcapng WTAP_FILE_TYPE_SUBTYPE_ values.Guy Harris1-172/+84
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-22wiretap: fix use of wrong index as array subscript.Guy Harris1-11/+14
"i" and "j" are too similar, so it's easy to use the wrong one if you're using both as array indices and not easy enough to notice the mistake. Use somewhat more meaningful names when we fix the index. Fixes #17252.
2021-02-21wiretap: have file handlers advertise blocks and options supported.Guy Harris1-76/+213
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-20BER: get rid of WTAP_FILE_TYPE_SUBTYPE_BER.Guy Harris1-8/+2
Save a copy of the pathname used to open a file in the wtap structure. This allows the BER file reader to put a pointer to it in the pseudo-header; it also would allow file readers to attempt to read "associated" files that have the same name as the file, but with a different extension. Instead of having cf_open() special-case BER files, and calling a routine in the BER dissector to specify the file name to the dissector, have separate dissectors for "dissect packet payload as BER" and "dissect a file as BER", and have the latter get the pathname of the file from the pseudo-header and determine the ASN.1 syntax from that. (Side-effect - this means that you can now dissect a BER file, and have the syntax be determined by the file extension, in TShark as well; the above cf_open() special-casing was *not* done in TShark, so it didn't work before. Now the application code doesn't need to do any of that, so it works in TShark as well as Wireshark.)
2021-02-19wiretap: eliminate two WTAP_FILE_TYPE_SUBTYPE_ values.Guy Harris1-14/+0
Eliminate WTAP_FILE_TYPE_SUBTYPE_ERF and WTAP_FILE_TYPE_SUBTYPE_SYSTEMD_JOURNAL - instead, fetch the values by name, using wtap_name_to_file_type_subtype(). This requires that wtap_init() be called before epan_init(); that's currently the case, but put in comments to indicate why it must continue to be the case.
2021-02-17wiretap: fix return value of wtap_register_file_type_subtypes().Guy Harris1-13/+15
It was returning the length of the array *after* we added the new entry, which is the index that would be used for the *next* entry added. Return, instead, the length of the array *before* we add the new entry.
2021-02-17wiretap: update the count of builtin types early.Guy Harris1-2/+5
We need to update the count of builtin types after copying over the entries from the fixed table; otherwise, slot 0, for WTAP_FILE_TYPE_SUBTYPE_UNKNOWN, will get assigned to the first non-fixed-table builtin module. Fix a comment (is a "builtin plugin" like a "square circle"?).
2021-02-17wiretap: more work on file type/subtypes.Guy Harris1-178/+421
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-14wiretap: register most built-in file types from its module.Guy Harris1-365/+0
Remove most of the built-in file types from the table in wiretap/file_access.c and, instead, have the file types register themselves, using wtap_register_file_type_subtypes(). This reduces the source code changes needed to add a new file type from three (add the handler, add the file type to the table in file_access.c, add a #define for the file type in wiretap/wtap.h) to one (add the handler). (It also requires adding the handler's source file to wiretap/CMakeLists.txt, but that's required in both cases.) A few remain because the WTAP_FILE_TYPE_SUBTYPE_ #define is used elsewhere; that needs to be fixed. Fix the wiretap/CMakefile.txt file to scan k12text.l, as that now contains a registration routine. In the process, avoid scanning files that don't implement a file type and won't ever have a registration routine. Add a Lua routine to fetch the total number of file types; we use that in some code to construct the wtap_filetypes table, which we need to do in order to continue to have all the values that used to come from the WTAP_FILE_TYPE_SUBTYPE_ types. While we're at it, add modelines to a file that lacked them.
2021-02-13iseries: report Unicode files as Unicode rather than ASCII.Guy Harris1-1/+1
While we're at it, that's "Unicode", not "UNICODE" - it's not an initialism, and isn't all-caps.
2021-02-13wiretap: remove spaces from file format names.Guy Harris1-1/+1
File format names are used on the command line, so don't require them to be quoted - replace the space in "systemd journal" with an underscore.
2021-02-13wiretap: file types have a name and a description.Guy Harris1-26/+26
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-2/+2
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-02-07btsnoop: fix writing of btsnoop files.Guy Harris1-1/+1
In answer to the question "How do we support multiple backends?", this is the answer - what they mean is "how do we support multiple encapsulation types for the *same* file format", and the answer is "you have one dump open routine that writes the appropriate encapsulation type in the header, depending on the encapulation type, and you have one dump write routine that generates the appropriate packet header and writes out the packet, depending on the encapsulation type". Fix the generation of the packet header when writing H1 and H4 packets, and *don't* strip off the first octet of the packet data when writing H1 packets - that octet isn't generated when reading H1 packets, it's read from the file. Tested by running several H1 and H4 captures through "editcap -F btsnoop" and making sure that the files are identical.
2020-12-22Detect and replace bad allocation patternsMoshe Kaplan1-2/+2
Adds a pre-commit hook for detecting and replacing occurrences of `g_malloc()` and `wmem_alloc()` with `g_new()` and `wmem_new()`, to improve the readability of Wireshark's code, and occurrences of `g_malloc(sizeof(struct myobj) * foo)` with `g_new(struct myobj, foo)` to prevent integer overflows Also fixes all existing occurrences across the codebase.
2020-12-10Linux: rename metadata according to specPeter Eszlari1-1/+1
https://www.freedesktop.org/software/appstream/docs/sect-Metadata-Application.html https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s02.html#desktop-file-id
2020-10-22editcap, tshark: process IDBs in the middle of input files.Guy Harris1-12/+35
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-21Add a routine to make a newly-allocated copy of a block.Guy Harris1-2/+1
It currently wraps wtap_block_create() and wtap_block_copy(); if there are no remaining use cases for wtap_block_copy() at some point, it can just *replace* wtap_block_copy().
2020-10-21Add a routine to get the next as-yet-unfetched interface description.Guy Harris1-0/+5
In a wtap, keep track of the first interface description not yet fetched with wtap_get_next_interface_description() and, when wtap_get_next_interface_description() is called, have it return that description, as a wtap_block_t for its IDB. If there are no as-yet-unfetched interface descriptions, return NULL; there may, in the future, be more interface descriptions for the file, so this should be called: * after the file is opened; * after wtap_read() returns TRUE, indicating that it's returned a record (and *before* you process the record that wtap_read() returns, as it might be the interface description for the interface on which the packet in that record arrived); * after wtap_read() returns FALSE, indicating an EOF or an error return (as there might have been interfaces at the end of the file or before the error point). At each of those points, the caller should loop until wtap_get_next_interface_description() returns NULL. Not used yet (but tested with capinfos, which found a reason why you have to wait until the end of the file before processing the interface information - there's now a comment in the code giving that reason). This will probably be used in the future.
2020-10-20Add an API to determine whether a file type uses interface IDs.Guy Harris1-0/+18
Currently, the only file types that use them are pcapng and IBM's iptrace; we don't support writing the latter, so this is mainly of interest for pcapng. This makes it a bit more obvious what some "is this pcapng?" tests are really trying to determine, and allows them to automatically support any new file types that use them. (With regard to interface descriptions, tere are three types of file: 1) files that contain no interface information; 2) files that contain "just FYI" interface information but that don't tie packets or other records to particular interfaces; 3) files that contain interface information and tie all packets (and possibly other records) to an interface. This tests for files of type 3.)