Commit Graph

589 Commits

Author SHA1 Message Date
João Valverde 5a662ba3fb wslog: Add support for domain filtering
A domain filter can be given in the environment variable
'WS_LOG_DOMAINS' or in a command-line options "--log-domains".

The filter is specified as a comma separated case insensitive list,
for example:

    ./tshark  --log-domains=main,capture

Domain data type switches from an enum to a string. There is no
constaint on adding new domains, neither in code or at runtime.
The string format is arbitrary, only positive matches will produce
output.
2021-06-14 13:13:12 +01:00
João Valverde 82739fc4f5 wslog: Improve code modularity and efficiency
Also tweak format for readability.
2021-06-14 13:13:12 +01:00
João Valverde dc7f0b88bb Refactor our logging and extend the wslog API
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-06-11 09:40:28 +00:00
Guy Harris fcb56bd1d4 Clean up printing of interface information.
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-13 23:14:09 -07:00
Guy Harris 60e339bba4 Don't handle -k in capture_opts_add_opt().
It's not a generic capture option also supported by TShark and dumpcap,
it's Wireshark-specific (dumpcap *always* starts a capture, and TShark
starts one iff it's passed one or more interfaces on which to capture;
only Wireshark needs it to start the capture immediately - that's a
relic of the days when Wireshark *itself* did what dumpcap now does for
Wireshark).

Handle it in commandline_other_options(), rather than in
capture_opts_add_opt().

That lets us get rid of an argument to capture_opts_add_opt(), and dummy
variables in TShark and dumpcap used to work with that extra argument.
2021-04-13 12:38:06 -07:00
João Valverde 7fee50274f Merge the caputils/ and capchild/ directories
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.
2021-03-29 06:08:02 +01:00
Dario Lombardo ea929d6401 wsutils: add local implementation of g_memdup2.
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-25 09:38:10 +00:00
Guy Harris d18e1f19e9 Add dumpcap options to set the name and description for a capture source.
Add --ifname and --ifdescr to allow the name and description for an
interface or pipe to be set; this overrides the specified name or
reported description for an interface, and overrides the pipe path name
and provides a description for a pipe.

Provide those arguments when capturing from an extcap program.

This is mainly for extcaps, so you have something more meaningful than
some random path name as the interface name and something descriptive
for the description.
2021-03-25 07:34:37 +00:00
João Valverde 41a172cc95 if_capabilities: Use a structured error msg from dumpcap
Have dumpcap in child mode return an error message with a primary and
secondary string, instead of using stderr. When writing to the console
log we ignore the second message to prevent flooding the log with
tutorial-like info on permissions.
2021-03-06 12:56:11 +00:00
Guy Harris c0711693ab Enable -Wredundant-decls.
Add it to the default list of checks, and fix some errors it causes.
(Sadly, it doesn't work in CLang.)
2021-02-14 14:43:42 -08:00
Guy Harris 99c712ff5a dumpcap: don't mention Npcap if we're not using it. 2021-02-09 11:38:51 -08:00
Guy Harris b09514f3b3 dumpcap: provide more information to put into an Npcap bug.
Turn the sequence of details to supply in an Npcap bug into a list, with
one element per line, and provide the interface name, Windows version
string, and Npcap version string.  Put that into a common routine.
2021-02-08 23:08:49 -08:00
Guy Harris 9b771d2c14 dumpcap: use the display name in error messages.
That adds the description, if present, on UN*X, and replaces the ugly
GUID-based name with a friendly name on Windows.
2021-02-08 15:16:33 -08:00
Guy Harris 37f5e0f7fd dumpcap: give details on how to fix Npcap bugs.
Give a whole bunch of details to put into the bug, in the (vain?) hope
that the user will put them in the bug, to try to help Daniel and
possibly Microsoft networking stack folk figure out what's happening.

(Remove an extra report_capture_error() left over from the previous
commit.)
2021-02-08 13:10:54 -08:00
Guy Harris b3db9e3aa1 dumpcap: show the interface name in capture errors.
dumpcap can capture on more than one interface at a time.  If the
capture stops due to an error on an interface, report the name of the
interface on which the error occurred.
2021-02-08 12:35:43 -08:00
Guy Harris d28021cacb "The device has been removed." can happen if it has, indeed, been removed.
So only tell the user to report that as an Npcap bug if they *haven't*
removed the device.
2021-02-08 00:40:36 -08:00
Guy Harris 27cbb68525 dumpcap: look for "PacketReceivePacket error: .* (1617)".
The error message text for ERROR_DEVICE_REMOVED (1617) might be in the
user's language; just look for the numeric error code.
2021-02-07 22:51:44 -08:00
Guy Harris 152fd1fdab dumpcap: improve some secondary error emssages.
For "PacketReceivePacket error: The device has been removed. (1617)",
report the error in that fashion, indicate that the interface is no
longer attached, *and* suggest that this may be an Npcap bug and that
the user should report it as such; give the URL for the Npcap issue
list.

For "The other host terminated the connection", report the error in that
fashion, and suggest that it might be a problem with the host on which
the capture is being done.

Hopefully this will mean fewer bugs filed as *Wireshark* bugs for those
issues.

(And, with any new capture API in libpcap, these should all turn into
specific PCAP_ERROR_ codes, to make it easier to detect them in callers
of libpcap.)
2021-02-07 19:12:44 -08:00
Guy Harris c15a37db51 dumpcap: Improve the secondary error for promiscuous mode failure.
On Windows, some devices don't let promiscuous mode be enabled, and
return an error rather than silently ignoring the request to use
promiscuous mode (as UN*X devices tend to do).  Check for the error
message from that error, and suggest that the user turn off promiscuous
mode on that device.
2020-12-27 12:55:31 -08:00
Moshe Kaplan 180b5e5dc0 Replace more g_malloc with g_new
Replace g_malloc with g_new to improve
source code readability.
2020-12-23 11:47:17 +00:00
Moshe Kaplan e16166a74c Detect and replace bad allocation patterns
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-22 14:56:38 +00:00
Guy Harris f1ab1f0b5b Put the XXX_pipe_open_live() calls after the file type determination.
That way, there's only one pcap_pipe_open_live() call, as was the case
in the past.
2020-11-25 12:43:00 -08:00
Guy Harris eb02336e28 Update a comment, and add some comments. 2020-11-25 11:58:26 -08:00
Guy Harris 884bae3317 Fix previous change to use WSAGetLastError() only on sockets.
On Windows, we do pipe I/O in a separate thread, as we can't do select()
- or even WaitForMultipleObjects() - on pipes, so
cap_pipe_read_data_bytes() is used only on sockets.

Update a comment.
2020-11-25 11:25:10 -08:00
Guy Harris 84bdd086cd Make sure a pcapng block's length is a multiple of 4.
We check for that when *writing* the block, but the error message for
that is not at all clear; check for it after we've read the block total
length, and report it with a better error message.

Clean up some other error messages while we're at it.
2020-11-25 10:41:05 -08:00
Guy Harris b904fc69ab Have capture_loop_init_pcapng_output() report an error code.
It *can* get errors with error codes, so it should pass them to its
caller so it can report the error correctly.
2020-11-25 00:43:43 -08:00
Guy Harris 8c4d0bb131 Expand a comment to note that pcapng_read_shb() does a synchronous read. 2020-11-25 08:08:24 +00:00
Guy Harris 5fcedcf8f4 Various code and comment cleanups.
Doing a blocking read from a pipe on Windows is done in several places,
using similar sequences of code; put that sequence into a subroutine,
with the parts that differ in arguments to the routine.

Add some comments, and update some comments, to better clarify what the
code is doing in various places.

In the switch statement that tests the first 4 bytes read from a pipe or
socket, call pcap_pipe_open_live() at the end of all of the cases where
the file appears to be a pcap file; that makes the handling of pcap
files look a bit more like the handling of pcapng files.
2020-11-22 17:51:37 +00:00
Guy Harris e3047d9b38 Pass an address-family-appropriate socket length to connect().
Some UN*Xes (4.4-lite-derived, such as the obscure, little-known macOS,
FreeBSD, NetBSD, OpenBSD, and DragonFly BSD) have a length field in the
socket address structure.

That was originally done for OSI address support; unlike most transport
addresses, such as IPv4 (and IPv6) addresses, where the size of the
address is fixed, the size of an OSI transport layer address is *not*
fixed, so it cannot be inferred from the address type.

With the dropping of OSI support, that field is no longer necessary in
userland.  System calls that take a socket address argument also take an
address length argument; in newer (all?) versions of the {macOS,
FreeBSD, NetBSD, OpenBSD, DragonFly BSD} kernel, the system call code
sets the length field in the kernel's copy of the address to the address
length field value.

However, that means that you have to pass in the appropriate length; if
you have a sockaddr_storage that might contain an IPv4 address or an
IPv6 address, connect() (and bind()) calls should use the IPv4 address
size for IPv4 addresses and the IPv6 address size for IPv6 addresses,
otherwise, at least on macOS, the call fails.

In cap_open_socket(), report socket() and connect() errors separately,
to make it easier to determine where TCP@ captures fail, if they do
fail.  (That's how I got here in the first place.)
2020-11-15 07:33:50 +00:00
Masaru Tsuchiyama c14ea41233 add support for compression of capture file 2020-10-30 00:25:22 +00:00
Guy Harris 4fd7983b04 dumpcap: fix the macOS "no permission to capture" message.
The macOS installer works differently from the way it did when that
message was written (it's now a drag-install for Wireshark, with
separate installers for ChmodBPF and for files to add the Wireshark
binary directory to the default $PATH), and the macOS main screen now
offers a "click this to install" link, running the ChmodBPF installer,
if the user doesn't have permissions to capture.  Update the message
to reflect that (although that's wrong if you directly run dumpcap or
run it via TShark - this needs to be cleaned up in some fashion).

Fix a capitalization error while we're at it.

In the code that generates the main screen message to which the dumpcap
message refers, add a comment saying that, if the main screen message
changes, dumpcap's message should also be updated.
2020-10-24 00:44:36 -07:00
Guy Harris e013c5ec7f Clean up URLs.
Add ui/urls.h to define some URLs on various of our websites.  Use the
GitLab URL for the wiki.  Add a macro to generate wiki URLs.

Update wiki URLs in comments etc.

Use the #defined URL for the docs page in
WelcomePage::on_helpLabel_clicked; that removes the last user of
topic_online_url(), so get rid of it and swallow it up into
topic_action_url().
2020-10-02 20:13:42 -07:00
David Perry e4379f0ea1 Dumpcap: print closed ring-buffer file names
This proposal adds a new option '-b printname:<filename>' to dumpcap. If
used, dumpcap will print the name of each ring buffer file it creates
after it is closed. Allows the use of '-'/'stdout' and 'stderr'.

Use case: Since the file name is printed after the file is closed for
writing, an automated capture process can do something like the
following with the guarantee that the file in question will not be
changed.

    dumpcap -i eth0 -b files:2 -b printname:stdout [-b ...] | \
    while read cap_file_name ; do
        # Do something with $cap_file_name
    done

This sort of scripting is difficult in dumpcap's current form. Dumpcap
prints the names of new files to stderr as it *opens* them, so a script
attempting to use this must sleep for "-b duration:value" seconds plus
some fudge time to be sure it's getting a closed, unchanging file.

Change-Id: Idb288cc7c8c30443256d35c8cd4460a2e3f0861c
Reviewed-on: https://code.wireshark.org/review/37994
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-08-08 08:04:13 +00:00
Guy Harris 608835bf56 Don't call any routines from WinPcap/Npcap packet32.dll.
We aren't using them now; stick to libpcap APIs (including Windows-only
libpcap APIs).

Change-Id: I812eaa31ba1e6e611418853105d3e00c9130a420
Reviewed-on: https://code.wireshark.org/review/37852
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-07-14 07:30:59 +00:00
Gerald Combs 36ca304359 dumpcap: Initialize a couple of variables.
Initialize err in capture_loop_init_output, as caught by both clang's
scan-build and Visual Studio's code analysis. Initialze err in
capture_loop_init_pcapng_output to match.

Move another variable to the code block in which it is used.

Change-Id: I0306ae6a02a02a8e1ebda89b7c574a7cae01b68f
Reviewed-on: https://code.wireshark.org/review/37274
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2020-05-21 15:33:05 +00:00
Guy Harris 0975bf792a Handle -k better on platforms that don't support it.
Have ws80211_init() return an indication that channel setting isn't
supported on those platforms.

In dumpcap, try to set up ws80211 before checking the channel argument
and, if it fails, report the failure, rather than failing because the
"convert channel name to channel code" routine fails.

See

    https://ask.wireshark.org/question/15535/dumpcap-k-is-not-accepting-channel-type-values/

for an example of confusion caused by the previous behavior.

Change-Id: I303f560704700bbcd4f0ecea041f8632744212f3
Reviewed-on: https://code.wireshark.org/review/36659
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-04-01 20:31:14 +00:00
Guy Harris fd88bfa348 Write the if_hardware option, if available, to pcapng files when capturing.
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>
2020-03-28 03:34:18 +00:00
Guy Harris c4f652397b Don't check for ancient libpcap versions on HP-UX.
We require libpcap 0.8 or later, so somebody's *really* have to go out
of their way to get a version of Wireshark running with a pre-0.6
libpcap.

Change-Id: I329b3a37cd37ca5d9e76db447daabfe1dc47e75d
Reviewed-on: https://code.wireshark.org/review/36422
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2020-03-15 00:55:37 +00:00
Guy Harris 0c889d6f5c Require at least libpcap 0.8/WinPcap 3.1.
2004 called, they want their libpcap/WinPcap back.

RHEL 6 initially shipped with libpcap 1.0; even old Enterprise(TM)
versions of OSes ship with something shinier than 0.7.x these days.

This lets us get rid of a bunch of #ifdefs and workaround code for
missing APIs.

Change-Id: I862cb027418b0a0c0f45a26979acea82f93f833b
Reviewed-on: https://code.wireshark.org/review/36383
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2020-03-13 00:05:07 +00:00
Michael Mann 2925fb0850 Use g_file_open_tmp within create_tempfile
Much better to use a known library than create it ourselves.

Also remove get_tempfile_path as it's not used.

Bug: 15992
Change-Id: I17b9bd879e8bdb540f79db83c6c138f8ee724764
Reviewed-on: https://code.wireshark.org/review/34420
Reviewed-by: Tomasz Moń <desowin@gmail.com>
Petri-Dish: Tomasz Moń <desowin@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
2019-12-20 19:26:38 +00:00
Jaap Keuter abd83d9961 cmdline: cleanup option string definitions
Option string composition has grown organically over time and is
depending on compilation options also. This results in somewhat complex
macro definitions and the use of the string concatenation feature of the
C compiler. This change tries to clean up some of this magic by removing
definitions of empty strings and merging of adjacent strings.

Change-Id: I968449ea9b564915bee468a0cac0e114983ceebe
Reviewed-on: https://code.wireshark.org/review/35429
Reviewed-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Petri-Dish: Jaap Keuter <jaap.keuter@xs4all.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2019-12-13 22:29:01 +00:00
Jaap Keuter 890e2bea2e Documentation: update (long) cmd line options
Documentation of the Tshark and dumpcap command line options between
help text, manual page and user's guide diverged over time. One aspect
of this is the implementation of more long options. This change tries to
update all documentation to be complete and in sync again.

Change-Id: Ie8bee013df8d209080fcf288072774f18f9ff51f
Reviewed-on: https://code.wireshark.org/review/35261
Reviewed-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Petri-Dish: Jaap Keuter <jaap.keuter@xs4all.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2019-11-30 23:42:11 +00:00
João Valverde 5d18c9b4df dumpcap: Add support for TCP@IPv6 socket captures
Bug: 15820
Change-Id: Id32f376190c115b0808ba72e5b63e019e2a70274
Reviewed-on: https://code.wireshark.org/review/35030
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2019-11-11 17:17:36 +00:00
Pascal Quantin 2cac9d47af dumpcap: fix capture library version display on Windows
Ensure to call load_wpcap() berfore building the version info string.

Bug: 16108
Change-Id: Ida7ecf6ad5186f816e1bf33902a0ae70f7f36b40
Reviewed-on: https://code.wireshark.org/review/34719
Reviewed-by: Pascal Quantin <pascal@wireshark.org>
Petri-Dish: Pascal Quantin <pascal@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-10-06 18:40:23 +00:00
Tomasz Moń e52f33f66c extcap: Multiple extcap instance support on Windows
Wireshark does create named pipes and waits for the child process to
connect. The named pipe server handle is inheritable and thus available
in child dumpcap process. Pass the handle identifier instead of named
pipe name so dumpcap can use it.

Bug: 13653
Change-Id: Id2c019f67a63f1ea3d98b9da2153d6de5078cd01
Reviewed-on: https://code.wireshark.org/review/34503
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-09-23 04:38:00 +00:00
Tomasz Moń 893a2d9c62 MSVC: Warn about unused formal parameters
Provide _U_ macro definition for Visual Studio.

Change the way _U_ macro is ifdefed for some targets to allow Visual
Studio to recognize it.

Ping-Bug: 15832
Change-Id: Ic7ce145cbe9e8aa751d64c9c09ce8ba6c1bbbd30
Reviewed-on: https://code.wireshark.org/review/34530
Tested-by: Petri Dish Buildbot
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-09-21 08:51:34 +00:00
Guy Harris 303f6f1b39 Boost the maximum packet size for LINKTYPE_USBPCAP in pcap/pcapng.
Bug: 15985
Change-Id: I8e043431bbf874d640d4407335d525a44815ee73
Reviewed-on: https://code.wireshark.org/review/34327
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-08-20 04:57:17 +00:00
Guy Harris 22e7952e06 HTTPS In Even More Places, update some links.
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-28 04:21:18 +00:00
Peter Wu 1f52712444 dumpcap: fix uninitialized memory read on dumpcap -d errors
Reproduce with: dumpcap -pdf bad

Change-Id: I8c1f80c9d88262bc57651e886740083ea8e6ad52
Fixes: 4d6cb744df ("Add a "-d" flag to dumpcap")
Reviewed-on: https://code.wireshark.org/review/33863
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-07-08 03:56:51 +00:00
Guy Harris 37ff9dacb9 Distinguish "Interface went down" from "Interface disappeared".
Have separate errors for "the interface went down" on Linux and "the
interface no longer exists" on *BSD/Darwin/Windows.

Change-Id: I1951c647e88eb7ebeb20a72d9e03a2072168c8e5
Reviewed-on: https://code.wireshark.org/review/33794
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-07-01 07:13:17 +00:00