aboutsummaryrefslogtreecommitdiffstats
path: root/capture
AgeCommit message (Collapse)AuthorFilesLines
2022-08-12extcap: Do not drain stderr on process exitTomasz Moń1-13/+3
Extcap child watch callback assumed that the stderr pipe is broken. However the stdout and stderr pipes are not necessarily broken if the child process spawned new processes that inherited standard handles. Do not drain stderr in busy loop to prevent UI freeze. Stop capture session only when all extcap watches are removed. Remove stdout and stderr watches on capture stop timer (30 seconds) expiration, even if the pipes are not broken. Do not rely only on 0 bytes read to cease reading stdout and stderr. Stop reading if the status is anything else than G_IO_STATUS_NORMAL (especially it can be G_IO_STATUS_EOF).
2022-08-10extcap: Read stdout and stderr during captureTomasz Moń1-2/+3
Read extcap stdout/stderr data when available to prevent extcap hang on stdout/stderr write. Discard stdout data as it was not used earlier. Store up to 1024 bytes of stderr and display it to user after capture stops. Fixes #17827
2022-08-10extcap: Close capture session after extcap finishesTomasz Moń2-5/+57
Wait up to 30 seconds for extcap process to finish after closing pipes. The wait is achieved in non-blocking fashion, i.e. the UI is completely responsive during the wait. Only actions related to capture process like capture control, file open, save, export are inactive during the wait. On Windows extcap child watch callback gets called immediately as the process is forcefully terminated. Prior to this change the extcap was forcefully terminated on Windows anyway. The wait is possible on UNIX systems if extcap does handle SIGPIPE and SIGTERM signals. The defaults handlers for SIGPIPE and SIGTERM simply terminate the process so for large number of extcaps there is no change. If extcap does not finish within 30 seconds, it is forcefully terminated using SIGKILL signal.
2022-07-30capture: Move capture pipe polling out of UITomasz Moń2-3/+81
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-15/+4
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-16Win32: Fix child process pipe handle leaksTomasz Moń1-1/+1
Close pipe handles when spawning asynchronous processes, so only the child process holds handle to the other end of the pipe. Closing the handles makes it possible to use pipes the same way as on other OS, that is to rely on blocking read() to end when child process finishes. Do not call CloseHandle() on signal pipe in capture sync after the handle ownership was transferred to file descriptor. Close the file descriptor instead.
2022-06-20Revert "A small for for the Doxygen warning:"Gisle Vanem1-3/+3
This reverts commit 2faa7bc3132a4a0b5679231f2f9ac5a988d45084
2022-06-20A small for for the Doxygen warning: Gisle Vanem1-3/+3
capture/airpcap.h:906: warning: end of file while inside a group Since the syntax should be `/**@}*/` (or `/*!@}*/` works too.
2022-02-24dumpcap: Fix a TODO for Npcap testJoão Valverde3-53/+14
2022-02-24Windows: Fix buildJoão Valverde2-8/+8
For some reason this was not caught by the CI.
2022-02-24wsutil: New API to gather compile/runtime infoDavid Perry3-24/+69
2022-02-11Differentiate `-c` from `-a packets:`David Perry1-0/+7
2022-02-09Specify directory for temporary capturesDavid Perry1-0/+5
2022-01-06Update our Npcap URLs.Gerald Combs1-9/+2
The official Npcap web site is now https://npcap.com/. Update our URLs to match. Fixes #17838.
2021-12-22Corrects repeated words throughout the code.Moshe Kaplan4-5/+5
Repeated words were found with: egrep "(\b[a-zA-Z]+) +\1\b" . -Ir and then manually reviewed. Non-displayed strings (e.g., in comments) were also corrected, to ease future review.
2021-12-19Replace g_strdup_printf() with ws_strdup_printf()João Valverde7-49/+49
Use macros from inttypes.h.
2021-12-19Replace g_snprintf() with snprintf()João Valverde4-29/+29
Use macros from inttypes.h with format strings.
2021-11-30capture: Add header files to DoxygenMoshe Kaplan10-10/+19
Add @file markers for capture headers so that Doxygen will generate documentation for them. Additionally, update the doxygen config file per 7fee50274f36a5feba113aa9ad3e72ca37bf1466 merging the caputils and capchild directories.
2021-11-16capture: Lower log level for debug outputJoão Valverde1-3/+3
2021-10-22Add new global header wireshark.h with guidelineJoão Valverde4-8/+7
Remove ws_diag_control.h from config.h because that was a workaround for the lack of a public global header. Fix the resultant build errors.
2021-09-23Windows: Fix build without libpcapJoão Valverde1-0/+2
wireshark\capture\capture-wpcap.c:901:42: error: expected ';', ',' or ')' before '_U_' get_runtime_caplibs_version(GString *str _U_) ^~~
2021-09-14Add tshark ringbuffer option '-b nametimenum:value'Juha Takala1-0/+7
This is used to select ringbuffer savefile name template. Choose one of two savefile name templates: If value is 1, make running file number part before start time part; this is the original and default behaviour (e.g. log_00001_20210828164426.pcap). If value is greater than 1, make start time part before running number part (e.g. log_20210828164426_00001.pcap). The latter makes alphabetical sortig order equal to creation time order, and keeps related multiple file sets in same directory close to each other (e.g. while browsing in wireshark "Open file" dialog). Signed-off-by: Juha Takala <juha.takala+rauta@iki.fi>
2021-07-15Clean up handling of --capture-comment.Guy Harris2-5/+11
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-14tshark: allow --capture-comment when reading a fileDavid Perry1-2/+4
Allows adding one or more capture comments to a new pcapng file when tshark is reading from a file. Currently, tshark only allows setting one capture comment, and that only when doing a live capture. The use case for this feature is given in bug #15005. I decided to allow multiple capture comments to match the same ability in `editcap`. To allow this change, I changed the function signature of `process_cap_file()` so it takes a `capture_options` struct instead of individual parameters that affect the capture.
2021-07-14CMake: Adjust wsutil includes and linking.Gerald Combs1-4/+1
Mark wsutil's includes SYSTEM PRIVATE. This exposed a lot of targets that were indirectly picking up include paths via the wsutil target, so add direct includes where needed. The G.722 and G.726 codecs were implicilty including tiffio.h; find it explicitly instead. Mark some of wsutil's libraries PRIVATE, but leave commonly-used ones PUBLIC. Ping #17477.
2021-06-23If opening a capture device provides a warning, show it.Guy Harris5-96/+154
We start the capture anyway, but print a warning message or pop up a warning dialog first.
2021-06-21wslog: Shorten ws_log_message_is_active() nameJoão Valverde1-1/+1
2021-06-19Replace g_assert() with ws_assert()João Valverde2-43/+45
2021-06-18wslog: Add support for inverted debug matchesJoão Valverde1-1/+1
The --log-debug and --log-noisy now accepts a '!' to invert the match and disable the debug (noisy respectively) log level for the listed domains. Note this is different from --log-domains, that option enables/disables the entire log domain itself, regardless of log level.
2021-06-14capture: Lower priority for some status messagesJoão Valverde1-6/+6
2021-06-11Refactor our logging and extend the wslog APIJoão Valverde4-92/+61
Experience has shown that: 1. The current logging methods are not very reliable or practical. A logging bitmask makes little sense as the user-facing interface (who would want debug but not crtical messages for example?); it's computer-friendly and user-unfriendly. More importantly the console log level preference is initialized too late in the startup process to be used for the logging subsystem and that fact raises a number of annoying and hard-to-fix usability issues. 2. Coding around G_MESSAGES_DEBUG to comply with our log level mask and not clobber the user's settings or not create unexpected log misses is unworkable and generally follows the principle of most surprise. The fact that G_MESSAGES_DEBUG="all" can leak to other programs using GLib is also annoying. 3. The non-structured GLib logging API is very opinionated and lacks configurability beyond replacing the log handler. 4. Windows GUI has some special code to attach to a console, but it would be nice to abstract away the rest under a single interface. 5. Using this logger seems to be noticeably faster. Deprecate the console log level preference and extend our API to implement a log handler in wsutil/wslog.h to provide easy-to-use, flexible and dependable logging during all execution phases. Log levels have a hierarchy, from most verbose to least verbose (debug to error). When a given level is set everything above that is also enabled. The log level can be set with an environment variable or a command line option (parsed as soon as possible but still later than the environment). The default log level is "message". Dissector logging is not included because it is not clear what log domain they should use. An explosion to thousands of domains is not desirable and putting everything in a single domain is probably too coarse and noisy. For now I think it makes sense to let them do their own thing using g_log_default_handler() and continue using the G_MESSAGES_DEBUG mechanism with specific domains for each individual dissector. In the future a mechanism may be added to selectively enable these domains at runtime while trying to avoid the problems introduced by G_MESSAGES_DEBUG.
2021-05-27Minor style change to libpcap version stringJoão Valverde1-2/+11
2021-04-30Cast away the return value of g_strlcpy() and g_strlcat().Guy Harris2-8/+8
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-13Clean up printing of interface information.Guy Harris1-9/+0
In dumpcap, if we're being run by TShark or Wireshark, if there are no link-layer types, just provide an empty list to our caller; let them construct an empty list of link-layer types when they read our output. In the code that reads that list, don't report an error if the list is empty, rely on the caller to do so. Have capture_opts_print_if_capabilities() do more work, moving some functions from its callers to it.
2021-04-10CMake: Add ENABLE_VLD option for MSVCTomasz Moń1-0/+6
Calling cmake with -DENABLE_VLD=ON when building with Visual Studio, results in debug configuration being linked to Visual Leak Detector. By default, Visual Leak Detector outputs the leak summary to Visual Studio debug window. When ENABLE_VLD is active, VLD is linked to all wireshark libraries and executables.
2021-03-29Merge the caputils/ and capchild/ directoriesJoão Valverde22-0/+10657
The distinction between the different kinds of capture utility may not warrant a special subfolfer for each, and sometimes the distinction is not be clear or some functions could stradle multiple "categories" (like capture_ifinfo.[ch]). Simplify by having only a generic 'capture' subfolder. The separate CMake libraries are kept as a way to reuse object code efficiently.