aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/erf.c
AgeCommit message (Collapse)AuthorFilesLines
2024-02-02ERF Interface Id ExtensionStephen Donnelly1-1/+1
Move common #defines to erf_record.h Add macro for erf_interface_id_from_flags() Fix duplicate proto fields Replace int with gboolean
2024-02-02Endace ERF Interface Id extensionStephen Donnelly1-15/+15
The Endace ERF format has extended the 'Interface Id' from 2 bits (interface 0-3) to 3 bits (interface 0-7). The Interface Id high order bit is not adjacent in the flags field. Extend wtap handling for ERF records. Extend epan dissection and display of ERF format. The existing erf.flags.cap field is retained and extended to 0-7. A new erf.flags.if_raw field is added for the unformatted value. Note proto_tree_add_split_bits_item_ret_val() cannot be used here because it only supports input from the tvb and not from a non-tvb value.
2024-01-20Undo some more double colonsMartin Mathieson1-1/+1
2023-03-30wiretap dump: automatically increase bytes_dumpedDavid Perry1-11/+0
For writing capture files, increment `wdh->bytes_dumped` within `wtap_dump_file_write()` so the caller doesn't have to manually track it. Fixes the most common case of writing a file in sequence, leaving the code clearer. A small number of file formats effectively leave the header blank, write the packets, then seek back up to the header to fill it in. In such cases, save `wdh->bytes_dumped` before filling in the header and restore it once done, so the value doesn't double-count the size of the header.
2023-03-21wiretap: rename the wtap_dumper field "encap" to "file_encap".Guy Harris1-1/+1
That indicates that it's a *per-file* encapsulation, not just some unspecified type of encapsulation such as per-packet or per-interface.
2023-03-18ERF: always use the packet encapsulation when writing to an ERF file.Guy Harris1-11/+19
ERF either has no single file encapsulation or always uses "ERF record" encapsulation, depending on how you want to think about it. Don't use wdh->encap as the packet encapsution, always use rec->rec_header.packet_header.pkt_encap.
2023-03-18erf: redo comment giving ERF spec URLs.Guy Harris1-4/+11
Give several specs, in chronological order, including older specs from the Wayback Machine. Label them all with a version indication. Note that version 16 - which we haven't found online, even on the Wayback Machine - has descriptions of records for no-longer-supported DAG cards.
2022-01-15erf(wiretap): Fix Clang Warning Uninitialized argument valueAlexis La Goutte1-1/+1
2021-12-19Replace g_strdup_printf() with ws_strdup_printf()João Valverde1-27/+27
Use macros from inttypes.h.
2021-12-19Replace g_snprintf() with snprintf()João Valverde1-3/+3
Use macros from inttypes.h with format strings.
2021-09-11Fix spelling errors.Guy Harris1-1/+1
The Ubuntu build commented on some spelling errors in executable code files. Fix the errors that don't come from external files containing the spelling errors (USB product and vendor IDs, PCI IDs, ASN.1 specifications), and fix some errors that don't show up in the executable code files (e.g., in comments and variable names).
2021-08-29wiretap: always allocate a block for a record.Guy Harris1-3/+2
Without that, you could add a comment to a record in a file format the reading code for which doesn't allocate blocks, but the comment doesn't get saved, as there's no block in which to save the comment option. This simplifies some code paths, as we're either using the record's modified block or we're using the block as read from the file, there's no third possibility. If we attempt to read a record, and we get an error, and a block was allocated for the record, unreference it, so the individual file readers don't have to worry about it.
2021-07-30erf: Fix Dead Store (found by Clang Anlyzer)Alexis La Goutte1-1/+1
Although the value stored to 'tagtotallength' is used in the enclosing expression, the value is never actually read from 'tagtotallength'
2021-07-16erf: make a copy of the first SHB comment.Guy Harris1-2/+5
We free it, but what wtap_block_get_nth_string_option_value() returns is what's stored in the block, and it might get freed up out from under us. Save a copy of it, so that when we free it, we're not double-freeing.
2021-07-14wiretap: clean up option definitions a bit.Guy Harris1-7/+7
Spell out "DESCRIPTION" for the IDB description option, as it's spelled out in the pcapng spec. Put the #defines for various options in the same order as the block types for them are in the pcapng spec.
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-13/+10
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-06-27wiretap: have the "for each option" routine return a success/fail indication.Guy Harris1-3/+8
Have the routine it calls return a Boolean value, with "true" meaning "keep going" and "false" meaning "stop iterating and return a failure indication". If the callback routine never returns "false", the routine returns "true" as a success indication.
2021-06-19erf: fix a comment to match reality.Guy Harris1-4/+25
It's not that Wireshark only supports one copy of some block options, it's that *the pcapng specification* only supports one instance of some block options, and it's not that wtap_block_set_*_value() fails on non-string values, it's that the set_XXX_option_value routines currently only support changing the value of an existing option, not adding a new instance of an option - the latter requires the add_XXX_option_value routine.
2021-06-18erf: handle errors in some routines more completely.Guy Harris1-28/+162
Have them take error code and error information string arguments and, for various failures, fill them in as "internal error" indications. Check their return codes to see if they got an error.
2021-06-18erf: set the tsprecision value of a newly-created IDB.Guy Harris1-0/+1
Don't assume the default is correct, because there's no guarantee of that - in fact, there's currently a guarantee that it's not, as it's initialized to 0, which is WTAP_TSPREC_SECS.
2021-05-24erf: clean up handling the return value when getting and option value.Guy Harris1-2/+2
Make the variable into which we put the return value of wtap_block_get_nth_string_option_value() a wtap_opttype_return_val, as that's the type of the return value - it's not a boolean, it's a status code with multiple values. Explicitly check that value against WTAP_OPTTYPE_SUCCESS. Yes, WTAP_OPTTYPE_SUCCESS is 0, so if (xxx) is equivalent to if (xxx != WTAP_OPTTYPE_SUCCESS) but it's better to make it explict, so it's clear that it's checking for failure.
2021-05-23erf: set USERAPPL if we have the application version but not the name.Guy Harris1-4/+7
Just say "(Unknown application) <version>". This also means that we don't leak the app_version string if there's no app_name string.
2021-04-16Wiretap: Fix some compiler warnings.Gerald Combs1-2/+2
Make various _dump_can_write_encap and _dump_open routines static. Add a couple of casts.
2021-03-25wsutils: add local implementation of g_memdup2.Dario Lombardo1-1/+2
g_memdup() was deprecated and replaced with g_memdup2() in GLib 2.68, we provide our own copy of g_memdup2() for older GLib versions.
2021-03-15Remove unnecessary includes of wiretap/pcap-encap.h.Guy Harris1-1/+0
2021-03-15Remove unnecessary inclues of wiretap/pcapng.h.Guy Harris1-1/+0
2021-02-23wiretap: rename wtap_register_file_type_subtypes().Guy Harris1-1/+1
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-21wiretap: have file handlers advertise blocks and options supported.Guy Harris1-2/+50
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-19wiretap: eliminate two WTAP_FILE_TYPE_SUBTYPE_ values.Guy Harris1-2/+23
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-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-02-01wiretap: redo the way we handle if_filter IDB options.Guy Harris1-16/+20
Change the data structure for that option to have a type field, indicating that it's either a pcap filter string or a BPF program, followed by a union with a string-pointer member for pcap filter strings and an instruction-count-and-pointer-to-instructions structure for BPF programs. Have routines to add, set, and fetch that option that handle that structure; discard the "generic structured option" routines. That means there's more type checking possible at compile time. Add more code to handle BPF programs. When writing pcapng files, check, both for that option and for string options, whether the option length is too big for the data to fit in a pcapng option, and don't write it if it is. (XXX - truncate the data? Report an error?)
2021-01-30Refer to options whose data isn't a simple data type as "structured".Guy Harris1-5/+5
"Custom", as in "requires custom handling of the option data, collides with "custom", as in pcapng custom options.
2020-12-22Detect and replace bad allocation patternsMoshe Kaplan1-12/+12
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-09wiretap/erf: Use memmove instead of memcpyMoshe Kaplan1-1/+1
It's possible for memcpy's source and destination to be the same address, and so therefore 'overlap'. Use memmove instead, which is safe for overlapping regions. This fixes Coverity 1450802.
2020-10-14Have WTAP_ERR_INTERNAL include an err_info string giving details.Guy Harris1-2/+2
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-11Fix many spelling errorsРоман Донченко1-4/+4
2020-10-03Update URLs pointing to the bug database.Guy Harris1-1/+2
Switch from bugs.wireshark.org to the GitLab issues list.
2020-06-01editcap: fix time adjustment for ERFMinh Phan1-0/+20
The erf_dump function in erf.c keeps the header intact and ignores the adjusted time. This adds a section for checking if the timestamp is changed and updating the header accordingly. Bug: 16578 Change-Id: I14468a302e746c7a84cf5619b73b94850142d930 Reviewed-on: https://code.wireshark.org/review/37301 Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-05-02ERF: split wiretap/erf.h into three files.Guy Harris1-4/+8
wiretap/erf_record.h has declarations for records in ERF files and in LINKTYPE_ERF packets in pcap and pcapng files. wiretap/erf-common.h has declarations of routines to be called by pcap/pcapng reader code when processing LINKTYPE_ERF packets. wiretap/erf.h is what's left, for use by wiretap/erf.c and the code with the tables of file readers and writers. Change-Id: Ia982e79b14a025a80dcbc7c812fb3b2cdb9c6aaa Reviewed-on: https://code.wireshark.org/review/37021 Petri-Dish: Guy Harris <gharris@sonic.net> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <gharris@sonic.net>
2020-05-02wiretap/erf: Get rid of no-longer-used routine.Guy Harris1-48/+0
I guess the "replace" part of "TODO: Replace uses in pcapng and pcap with erf_read_header() and/or erf_populate_interface_from_header() and delete." has been done, so we do the "delete" part. Change-Id: Icd691aa8c3defdd68c306ad9eaf1379a8ba6ec0f Reviewed-on: https://code.wireshark.org/review/37020 Petri-Dish: Guy Harris <gharris@sonic.net> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <gharris@sonic.net>
2020-05-02wiretap: add a routine that adds a wtap_block_t for an IDB to a wtap.Guy Harris1-2/+2
Change-Id: I0a2e09bc3d1a858a304ded0c42be6bf09034812e Reviewed-on: https://code.wireshark.org/review/37019 Petri-Dish: Guy Harris <gharris@sonic.net> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <gharris@sonic.net>
2020-04-14wiretap: don't use memset where possible.Dario Lombardo1-11/+4
Change-Id: Id74764242ba13fb4ed58299a475096a64e5c6b5b Reviewed-on: https://code.wireshark.org/review/36838 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-09-08erf: Use g_get_real_time() to get real timeStig Bjørlykke1-3/+3
Use g_get_real_time() to get real time because GTimeVal and g_get_current_time() was deprecated in glib 2.62. Change-Id: I78fee34e2f5b634c91c6420b01915cfc070f38a4 Reviewed-on: https://code.wireshark.org/review/34468 Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org> Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-07-28HTTPS In Even More Places, update some links.Guy Harris1-2/+4
Fall back on the Wayback Machine for some links. Change-Id: I6a44a2caaeb4fa521c2f08196e7c36069e3bb842 Reviewed-on: https://code.wireshark.org/review/34103 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-07-26HTTPS (almost) everywhere.Guy Harris1-1/+1
Change all wireshark.org URLs to use https. Fix some broken links while we're at it. Change-Id: I161bf8eeca43b8027605acea666032da86f5ea1c Reviewed-on: https://code.wireshark.org/review/34089 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-05Have wtap_read() fill in a wtap_rec and Buffer.Guy Harris1-12/+10
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-03-17Treat erf_timestamp_t's as integral values.Guy Harris1-2/+2
That's what they are, and that's how other code in erf_open() treats them; just use assignment to initialize prevts and to set prevts to ts. Maybe this will keep the Clang static analyzer from calling prevts a garbage value when compared with ts. Change-Id: I2ee2376ced5c3efa6beab34276009a3177c94416 Reviewed-on: https://code.wireshark.org/review/32455 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-01-25wiretap: fix memleaks with wtap_rec::opt_commentPeter Wu1-2/+4
The memory ownership of wtap_rec::opt_comment was not clear. Users of wtap were leaking memory (editcap.c). wtap readers were not sure about freeing old comments (erf) or simply ignored memleaks (pcapng). To fix this, ensure opt_comment is owned by wtap_rec and free it with wtap_rec_cleanup. The erf issue was already addressed since cf_get_packet_comment properly duplicates wth.opt_comment memory. - wtap file formats (readers): - Should allocate memory for new comments. - Should free a comment from an earlier read before writing a new one. - Users of wth: - Can only assume that opt_comment remains valid until the next read. - Can assume that wtap_dump does not modify the comment. - For random access (wtap_seek_read): should call wtap_rec_cleanup to free the comment. The test_tshark_z_expert_comment and test_text2pcap_sip_pcapng tests now pass when built with ASAN. This change was created by carefully looking at all users opt "opt_comment" and cf_get_packet_comment. Thanks to Vasil Velichkov for an initial patch which helped validating this version. Bug: 7515 Change-Id: If3152d1391e7e0d9860f04f3bc2ec41a1f6cc54b Reviewed-on: https://code.wireshark.org/review/31713 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Vasil Velichkov <vvvelichkov@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-07-31Relax ERF heuristicStephen Donnelly1-2/+2
Allow forward timestamp deltas up to 1 year, up from 7 days. Surprisingly this was overly restrictive in some real cases. Change-Id: I8a4bd1ca791b978aa5d2be40f7f8dd8e23db8837 Reviewed-on: https://code.wireshark.org/review/28882 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>