aboutsummaryrefslogtreecommitdiffstats
path: root/text2pcap.c
AgeCommit message (Collapse)AuthorFilesLines
2024-02-20text2pcap: Set encapsulation to WIRESHARK_UPPER_PDU with -PJohn Thacker1-0/+1
The documentation, both man page and help, claims that text2pcap automatically sets the encapsulation to WIRESHARK_UPPER_PDU if -P is given. Make the behavior match the documentation.
2023-10-13docs: Make version option handling consistentJohn Thacker1-2/+2
Document the help and version option handling, including long option form, the same for all the command line tools, both in the their help output and in any manpages. Add version option to randpkt. Fix #15483
2023-07-27Clean up the cleaning-up of wtap_dump_params structures.Guy Harris1-19/+11
Use wtap_free_idb_info() to clean up the idb_inf member, rather than duplicating what wtap_free_idb_info() does. Don't call wtap_block_array_free() on the shb_hdrs member and then call wtap_dump_params_cleanup() on the entire structure - that causes a double-free of the SHB headers. In text2pcap.c, have a routine that calls wtap_free_idb_info() and then calls wtap_dump_params_cleanup(), and replace that sequence of calls with calls to the routine. Fixes #19235.
2023-04-24text2pcap: Fix leakJohn Thacker1-0/+12
Free the SHB headers and IDB interface data from the dump parameters after we are done with them.
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-47/+47
2022-10-08Add log init message to main()João Valverde1-0/+3
2022-09-10Dissector names are not protocol names.Guy Harris1-2/+2
A given protocol's packet format may depend, for example, on which lower-level protocol is transporting the protocol in question. For example, protocols that run atop both byte-stream protocols such as TCP and TLS, and packet-oriented protocols such as UDP or DTLS, might begin the packet with a length when running atop a byte-stream protocol, to indicate where this packet ends and the next packet begins in the byte stream, but not do so when running atop a packet-oriented protocol. Dissectors can handle this in various ways: For example, the dissector could attempt to determine the protocol over which the packet was transported. Unfortunately, many of those mechanisms do so by fetching data from the packet_info structure, and many items in that structure act as global variables, so that, for example, if there are two two PDUs for protocol A inside a TCP segment, and the first protocol for PDU A contains a PDU for protocol B, and protocol B's dissector, or a dissector it calls, modifies the information in the packet_info structure so that it no longer indicates that the parent protocol is TCP, the second PDU for protocol A might not be correctly dissected. Another such mechanism is to query the previous element in the layers structure of the packet_info structure, which is a list of protocol IDs. Unfortunately, that is not a list of earlier protocols in the protocol stack, it's a list of earlier protocols in the dissection, which means that, in the above example, when the second PDU for protocol A is dissected, the list is {...,TCP,A,B,...,A}, which means that the previous element in the list is not TCP, so, again, the second PDU for protocol A will not be correctly dissected. An alternative is to have multiple dissectors for the same protocol, with the part of the protocol that's independent of the protocol transporting the PDU being dissected by common code. Protocol B might have an "over a byte-stream transport" dissector and an "over a packet transport" dissector, with the first dissector being registered for use over TCP and TLS and the other dissector being registered for use over packet protocols. This mechanism, unlike the other mechanisms, is not dependent on information in the packet_info structure that might be affected by dissectors other than the one for the protocol that transports protocol B. Furthermore, in a LINKTYPE_WIRESHARK_UPPER_PDU pcap or pcapng packet for protocol B, there might not be any information to indicate the protocol that transports protocol B, so there would have to be separate dissectors for protocol B, with separate names, so that a tag giving the protocol name would differ for B-over-byte-stream and B-over-packets. So: We rename EXP_PDU_TAG_PROTO_NAME and EXP_PDU_TAG_HEUR_PROTO_NAME to EXP_PDU_TAG_DISSECTOR_NAME and EXP_PDU_TAG_HEUR_DISSECTOR_NAME, to emphasize that they are *not* protocol names, they are dissector names (which has always been the case - if there's a protocol with that name, but no dissector with that name, Wireshark will not be able to handle the packet, as it will try to look up a dissector given that name and fail). We fix that exported PDU dissector to refer to those tags as dissector names, not protocol names. We update documentation to refer to them as DISSECTOR_NAME tags, not PROTO_NAME tags. (If there is any documentation for this outside the Wireshark source, it should be updated as well.) We add comments for calls to dissector_handle_get_dissector_name() where the dissector name is shown to the user, to indicate that it might be that the protocol name should be used. We update the TLS and DTLS dissectors to show the encapsulated protocol as the string returned by dissector_handle_get_long_name(); as the default is "Application Data", it appeaers that a descriptive name, rather than a short API name, should be used. (We continue to use the dissector name in debugging messages, to indicate which dissector was called.)
2022-05-12text2pcap: Switch default file format to pcapngJohn Thacker1-4/+3
For the upcoming 4.0 release, switch the default file format for text2pcap to pcapng from pcap, to match other tools and the GUI behavior. Update the documentation and release notes appropriately. Deprecate the old -n flag; since pcapng is the default this has no effect. Changing the output capture file format is supported with the -F option, consistent with the other command line tools. Related to #18009.
2022-03-14wiretap: have wtap_dump_close() provide a "needs to be reloaded" indication.Guy Harris1-1/+1
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-02-13text2pcap: Fix DeadStore found by Clang AnalyzerAlexis La Goutte1-1/+0
text2pcap.c:476:13: warning: Value stored to 'pcap_link_type' is never read [deadcode.DeadStores]
2022-01-16text2pcap: encap types option (instead of link type)John Thacker1-19/+80
Add an option to text2pcap to specify the encapsulation type via wiretap encapsulation type short names instead of pcap link layer types, similar to editcap. Update the documentation to reflect this.
2022-01-11text_import: Allow fake IP headers with Raw IP encapsulationJohn Thacker1-24/+45
In text2pcap and Import from Hex Dump, allow fake IP headers with the appropriate versions when the Raw IP, Raw IPv4, and Raw IPv6 encapsulations are specified. In such cases, do not add a dummy Ethernet header. Continue to reject other encapsulations besides these, Ethernet, and Wireshark Upper PDU when appropriate. Add some checks for the encapsulation type in text_import as well, instead of just assuming that the callers handle it correctly.
2022-01-11text2pcap: Use RFC 3849 addresses for documentationJohn Thacker1-1/+1
Use the RFC 3849 IPv6 address prefix reserved for documentation for the documentation and examples
2022-01-03text2pcap: Use common capture type flagJohn Thacker1-13/+43
Support all possible file formats that wiretap writes, using the same "-F" flag that other CLI tools like editcap, mergecap, and tshark support. Default is still pcap for now; a future commit will switch to pcapng and remove the "-n" option, to match other CLI tools.
2022-01-02text2pcap: add regexJohn Thacker1-22/+116
Add support in text2pcap for the regex mode added to "Import from Hex Dump" in 3.6.0 The input and output indicators cannot (yet?) be configured, and are set to the default of allowing any of "iI<" for inbound and "oO>" for outbound. This reaches feature parity between text2pcap and Import from Hex Dump, fixes #16724. (There might be some more cleanups to do, including docs.)
2021-12-30text2pcap: Move SHB and IDB setup to ui/text_importJohn Thacker1-69/+1
Move the parameter setup to text_import, so that later it can be called from the GUI, including the interface name. (This has to be a separate function because these parameters need to be set before the call to wtap_dump_open, which is different for regular files vs temp files vs stdout.)
2021-12-30text2pcap: Use standard log debug levelJohn Thacker1-11/+13
Remove the '-d' option from text2pcap, and move the two levels of debug messages in text2pcap and text_import to either LOG_LEVEL_DEBUG or LOG_LEVEL_NOISY as appropriate.
2021-12-26import_text: Add ASCII identification checkboxJohn Thacker1-5/+1
Add a checkbox for the extra detection for ASCII in a hex+ASCII hexdump even when the text looks like hexbytes to Import from Hex Dump. Save and restore it from the settings. Work towards #16724.
2021-12-26text2pcap: Add Export PDUJohn Thacker1-6/+25
Support Export PDU functionality from text2pcap. Related to #16724.
2021-12-25text2pcap: Use debug levelJohn Thacker1-5/+3
Pass the debug level parameter from text2pcap to text_import so that it is used as it was before to print internal parsing information.
2021-12-25text2pcap: Update usage for new time format optionsJohn Thacker1-6/+4
2021-12-25text2pcap: Support OFFSET_NONEJohn Thacker1-14/+7
2021-12-24text2pcap: use ws_strtou8() to process the -i flag.Guy Harris1-21/+33
Based on Gerald's !5562. Use ws_strtou8() rather than doing all the error checking ourselves. Have a common routine to call when an IP "next protocol" value is set; it does all the necessary work, and could also check for colliding settings, such as combining "-i 99" with "-s", "-S", "-u", or "-T", or combining "-u" with "-T", or....
2021-12-24text2pcap: have a Boolean flag indicating whether -i was specified.Guy Harris1-3/+12
That avoids worrying about finding an appropriate out-of-range value to indicate whether -i was specified or not.
2021-12-24text2pcap: Explicit case to keep clang happyJohn Thacker1-1/+1
2021-12-24text2pcap: Use common failure messages, exit codesJohn Thacker1-73/+73
Use the common exit codes and failure messages.
2021-12-24text_import: Reduce globalsJohn Thacker1-10/+5
A bunch of the globals are simply copied from the input parameter text_import_info_t, just use them directly. Move the count for packets read and written into the info type, so that callers like text2pcap can access them as results.
2021-12-23text2pcap: Call text_importJohn Thacker1-1181/+68
Have text2pcap call text_import to do the work. Related to #16724.
2021-12-23text2pcap: Finish setting up error handlingJohn Thacker1-7/+40
Finish up all the setup for the common command line error handling and for the report message handling when this eventually calls ui/text_import
2021-12-22text2pcap: Clean up includesJohn Thacker1-6/+0
Since we're using wtap_dump_open[_stdout] from file_access.c now, we don't need to include io.h or fcntl.h on Windows anymore, and we don't need to include pcapio either.
2021-12-22text2pcap: Use wtap_dumperJohn Thacker1-133/+167
Use wtap_dump instead of the pcapio functions for writing files. This makes it easier to unify with text_import, and also makes it easier to eventually write other file formats (with a similar option to the other CLI programs), and allows using the standard CLI error messages. Also move some of the option validation before attempting to open the output file.
2021-12-19Replace g_strdup_printf() with ws_strdup_printf()João Valverde1-1/+1
Use macros from inttypes.h.
2021-12-19Replace g_snprintf() with snprintf()João Valverde1-1/+1
Use macros from inttypes.h with format strings.
2021-12-02text2pcap: Support parsing of iso-8601 datesJörg Mayer1-49/+65
2021-09-30ws_getopt: Rename struct and macrosJoão Valverde1-3/+3
This is part of the API and should also be renamed to avoid conflicts.
2021-09-18text2pcap: Fix -Wmissing-prototypesAlexis La Goutte1-1/+1
warning: no previous prototype for function 'text2pcap_vcmdarg_err' [-Wmissing-prototypes]
2021-09-17Use the musl in-tree getopt_long() everywhereJoão Valverde1-59/+48
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-07-15Clean up handling of --capture-comment.Guy Harris1-2/+5
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-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-1/+11
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/+4
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-04-30Cast away the return value of g_strlcpy() and g_strlcat().Guy Harris1-2/+2
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-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.)
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.
2020-03-28Write the if_hardware option, if available, to pcapng files when capturing.Guy Harris1-0/+1
Change-Id: Ib9ff78d148a2364c84d84b4a9b020b3d783654a3 Reviewed-on: https://code.wireshark.org/review/36602 Petri-Dish: Guy Harris <gharris@sonic.net> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <gharris@sonic.net>
2019-07-20epan,packaging: convert http URLs to httpsPeter Wu1-3/+3
Ensure that public text in error messages and dialogs point to https. Ensure that the generated PDML files include scripts over https. Change-Id: I75d42704c2bbb33b05492261b3e1d45dc6e301f9 Reviewed-on: https://code.wireshark.org/review/34027 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-03-11Use memcpy() to copy bytes.Guy Harris1-6/+2
No need to do our own copying loop. Change-Id: Ia3f5065c7b24c5a11e6fa289aef7ca54187fe67e Reviewed-on: https://code.wireshark.org/review/32385 Reviewed-by: Guy Harris <guy@alum.mit.edu>