Commit Graph

55 Commits

Author SHA1 Message Date
Moshe Kaplan 0120c12c5d ringbuffer.c: avoid leaking gzFile handle
Avoid leaking the gzFile handle when g_malloc()
fails. This fixes coverity issue 1468698.
2020-11-27 14:58:29 +00:00
Masaru Tsuchiyama c14ea41233 add support for compression of capture file 2020-10-30 00:25:22 +00: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
João Valverde c7d86568a0 CMake: Remove wsutil pcap dependency
Change-Id: Ic5a3653cb8bcc33e0be108c8b201567e7090f9f5
Reviewed-on: https://code.wireshark.org/review/33043
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: João Valverde <j@v6e.pt>
2019-05-03 21:57:05 +00:00
Vasil Velichkov 82b0312887 dumpcap: Reallocate the IO buffer when switching the ring buffer files
Fixes ASAN test failures for 4 suite_capture tests.

Fixes: v3.1.0rc0-261-ga55111610a ("Dumpcap: Set a bigger IO buffer(64KiB).")
Change-Id: If7b9450915af0ea751240acbde2371afa806f701
Reviewed-on: https://code.wireshark.org/review/32398
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-03-14 04:37:17 +00:00
Anders Broman a55111610a Dumpcap: Set a bigger IO buffer (64KiB).
Set a bigger IO buffer to avoid syscall overhead.
See https://github.com/the-tcpdump-group/libpcap/issues/792

Change-Id: If370da5ab2b70a9d0c925dd7c4c5c135c675c3f6
Reviewed-on: https://code.wireshark.org/review/31326
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-03-10 12:34:55 +00:00
Peter Wu 0b632861e2 dumpcap: fix memory leak in ringbuffer mode
'save_file' is used both for holding the -w command-line argument as
well as the current filename that is being written. In ringbuffer mode,
the former is already freed while the latter changes after rotation. Be
sure to free all ringbuffer filenames on exit.

Fixes test failures due to ASAN reporting memory leaks for:

    test_dumpcap_ringbuffer_filesize
    test_dumpcap_pcapng_single_in_multi_out
    test_dumpcap_pcapng_multi_in_multi_out
    test_dumpcap_ringbuffer_packets

Change-Id: Ib817d8340275d7afa7e149dcfbbc59ed78293c34
Reviewed-on: https://code.wireshark.org/review/31739
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-01-26 07:42:17 +00:00
Dario Lombardo 8cd389e161 replace SPDX identifier GPL-2.0+ with GPL-2.0-or-later.
The first is deprecated, as per https://spdx.org/licenses/.

Change-Id: I8e21e1d32d09b8b94b93a2dc9fbdde5ffeba6bed
Reviewed-on: https://code.wireshark.org/review/25661
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 14:57:36 +00:00
Gerald Combs 775bbbcded Start using SPDX license identifiers.
A while back Graham pointed out the SPDX project (spdx.org), which is
working on standardizing license specifications:

https://www.wireshark.org/lists/wireshark-dev/201509/msg00119.html

Appendix V of the specification describes a short identifier
(SPDX-License-Identifier) that you can use in place of boilerplate in
your source files:

https://spdx.org/spdx-specification-21-web-version#h.twlc0ztnng3b

Start the conversion process with our top-level C and C++ files.

Change-Id: Iba1d835776714deb6285e2181e8ca17f95221878
Reviewed-on: https://code.wireshark.org/review/24302
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Balint Reczey <balint@balintreczey.hu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-11-09 20:03:51 +00:00
Guy Harris 7321183716 Put the HAVE_REMOTE hack into wsutil/wspcap.h, and include that file.
Have a header file that defines HAVE_REMOTE if HAVE_PCAP_REMOTE is
defined, and then includes pcap.h.  Replace all other includes of
pcap.h, and the definition of HAVE_REMOTE, with includes of that file.
Check for anything other than wspcap.h including pcap.h in checkAPIs.pl.

Change-Id: I3cbee8208944ad6f006f568b3fe3134e10b2a883
Reviewed-on: https://code.wireshark.org/review/21605
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-05-11 19:58:15 +00:00
Guy Harris 79eab8ca07 Force HAVE_REMOTE to be defined when including pcap.h with remote support.
WinPcap made the mistake of having stuff in its public header fines
depend on a configuration #define, HAVE_REMOTE; this means that we need
to forcibly define it when building with remote capture support.

The tip of the libpcap master branch does not have that botch; hopefully
future versions of libpcap-for-Windows will be based on that libpcap and
thus lack that botch as well.

Defining HAVE_REMOTE in config.h is not the right fix, as it makes it
look like a *Wireshark* configuration option that code in Wireshark
should test, rather than a *WinPcap* configuration option that the
pcap.h that ships with the WinPcap SDK should have been changed, as part
of the build process, to correctly define or not, so that users of
WinPcap don't have to define it themselves.

Change-Id: I62d1eca6d3c900d0dcc9fbc011db77f595a86313
Reviewed-on: https://code.wireshark.org/review/21593
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-05-11 10:57:22 +00:00
Guy Harris 6a049dd755 Check the result of localtime().
Unlikely to fail, but it squelches CID 1398219.

Change-Id: Ibdabd2d71bdc2c09549f27f1ffe528005383ee3e
Reviewed-on: https://code.wireshark.org/review/21178
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-18 05:54:34 +00:00
Guy Harris 10ca4c7527 More checks for localtime() and gmtime() returning NULL.
And some comments in the case where we're converting the result of
time() - if your machine's idea of time predates January 1, 1970,
00:00:00 UTC, it'll crash on Windows, but that's not a case where a
*file* can cause the problem due either to a bad file time stamp or bad
time stamps in the file.

Change-Id: I837a438e4b875dd8c4f3ec2137df7a16ee4e9498
Reviewed-on: https://code.wireshark.org/review/18369
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-10-22 02:27:32 +00:00
Guy Harris 0162e54075 Clean up includes of unistd.h, fcntl.h, and sys/stat.h.
Have wsutil/file_util.h include them on UN*X, just as it includes io.h
on Windows, so we can have a rule of "if you do file operations, include
<wsutil/file_util.h> and use the routines in it".

Remove includes of unistd.h, fcntl.h, and sys/stat.h that aren't
necessary (whether because of the addition of them to wsutil/file_util.h
or because they weren't needed in the first place).

Change-Id: Ie241dd74deff284e39a5f690a297dbb6e1dc485f
Reviewed-on: https://code.wireshark.org/review/11619
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-11-07 21:52:23 +00:00
Bill Meier 1b8b2a8aa8 Add editor modelines; Adjust whitespace as needed.
Change-Id: I4da7b335d905dbca10bbce03aa88e1cdeeb1f8ad
Reviewed-on: https://code.wireshark.org/review/4626
Reviewed-by: Bill Meier <wmeier@newsguy.com>
2014-10-12 18:58:32 +00:00
Graham Bloice 97546165fa Modify includes of config.h so that out-of-tree builds, i.e. CMake
don't pick up the in-tree copy.

Change-Id: I7ec473876cdba1a025c52362d7f6adc62d24ce71
Reviewed-on: https://code.wireshark.org/review/3798
Petri-Dish: Graham Bloice <graham.bloice@trihedral.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Roland Knall <rknall@gmail.com>
Reviewed-by: Graham Bloice <graham.bloice@trihedral.com>
2014-08-24 08:04:08 +00:00
Alexis La Goutte 296591399f Remove all $Id$ from top of file
(Using sed : sed -i '/^ \* \$Id\$/,+1 d')

Fix manually some typo (in export_object_dicom.c and crc16-plain.c)

Change-Id: I4c1ae68d1c4afeace8cb195b53c715cf9e1227a8
Reviewed-on: https://code.wireshark.org/review/497
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-04 14:27:33 +00:00
Bill Meier 11b5c15fdb Remove trailing whitespace
Change-Id: I8116f63ff88687c8db3fd6e8e23b22ab2f759af0
Reviewed-on: https://code.wireshark.org/review/385
Reviewed-by: Bill Meier <wmeier@newsguy.com>
Tested-by: Bill Meier <wmeier@newsguy.com>
2014-02-25 20:46:49 +00:00
Martin Kaiser 61cad5a8e2 coverity 990813 dereference after null check
(hope I got it right this time)

svn path=/trunk/; revision=48673
2013-03-31 16:19:53 +00:00
Martin Kaiser 95ab41e938 add missing NULL check
http://www.wireshark.org/download/automated/analysis/scan-build-2013-03-12-1/report-q1cLLC.html#EndPath


svn path=/trunk/; revision=48283
2013-03-13 22:39:50 +00:00
Guy Harris 0ddce65214 fclose() and fflush() are standard C routines, so there's no need for
our own wrappers.  (pcapio.c isn't using wrappers around, for example,
fwrite().)

svn path=/trunk/; revision=46640
2012-12-20 20:00:06 +00:00
Michael Tüxen 7e84abf005 Add ws_fclose(), ws_fflush(), and ws_fdopen() to the fileutils.
Retire libpcap_fdopen(), libpcap_dump_flush(), and libpcap_dump_close().

svn path=/trunk/; revision=46636
2012-12-20 14:53:09 +00:00
Jeff Morriss 3551a86c36 We always HAVE_CONFIG_H so don't bother checking whether we have it or not.
svn path=/trunk/; revision=45015
2012-09-20 01:29:52 +00:00
Jakub Zawadzki bf81b42e1e Update Free Software Foundation address.
(COPYING will be updated in next commit)

svn path=/trunk/; revision=43536
2012-06-28 22:56:06 +00:00
Guy Harris 17f8127d25 Fix another old-style function definition.
svn path=/trunk/; revision=37224
2011-05-17 23:35:12 +00:00
Sake Blok f17c5ac01f As mentioned on the users-mailinglist[1], it could be useful to have groups read access to the ringbuffer that dumpcap creates. That way, a group of people can access the capture files without having to use root access.
[1]  http://www.wireshark.org/lists/wireshark-users/201008/msg00235.html

svn path=/trunk/; revision=33978
2010-08-28 11:05:51 +00:00
Gerald Combs 8598c522b2 Set RINGBUFFER_MAX_NUM_FILES to 100000. Use it to generate file names.
Add RINGBUFFER_WARN_NUM_FILES and use it to print a warning. Print
warnings when we change the number of ringbuffer files.

svn path=/trunk/; revision=32998
2010-05-27 18:00:46 +00:00
Guy Harris e1b6881286 Squelch some compiler warnings.
svn path=/trunk/; revision=32165
2010-03-11 00:36:45 +00:00
Michael Tüxen f5547c0d78 Make ringbuffer.[ch] file format agnostic.
Move write routines to dumpcap.c
This is a preparation for pcapng support.

svn path=/trunk/; revision=28155
2009-04-26 15:51:25 +00:00
Jeff Morriss a5cee04fad Move the file utility functions from wiretap to libwsutil so that
libwireshark (and the plugins using those functions) do not depend on
wiretap on Windows.

While doing that, rename the eth_* functions to ws_*.

svn path=/trunk/; revision=25354
2008-05-22 15:46:27 +00:00
Jaap Keuter 9570ca1292 Fix for bug 1591:
The 5 digit file number should contain the monotonic increasing file number modulo 100000 to fit the alloted space.

svn path=/trunk/; revision=21775
2007-05-15 07:53:37 +00:00
Ronnie Sahlberg 89f022b12b name change
svn path=/trunk/; revision=18197
2006-05-21 05:12:17 +00:00
Guy Harris 25e8c37489 Have the ring buffer routines take a pointer to a "bytes written" count
as an argument, rather than keeping the count to themselves, so the
count kept by the capturing program can be updated correctly - including
getting reset when files are switched.  Fixes bug 895.

svn path=/trunk/; revision=18032
2006-04-29 17:54:46 +00:00
Guy Harris e6886d90ce When capturing, we only support writing to libpcap files. Given that,
bypass Wiretap; that means we don't have to run the packet through
wtap_process_pcap_packet() and then undo that conversion in Wiretap if
we're just going to write it out, shortening the code path.

svn path=/trunk/; revision=17461
2006-03-04 22:33:04 +00:00
Ulf Lamping c3187174bf replace *a lot* of file related calls by their GLib counterparts. This is necessary for the switch to GTK 2.6 (at least on WIN32).
to do this, I've added file_util.h to wiretap (would file_compat.h be a better name?), and provide compat_macros like eth_open() instead of open(). While at it, move other file related things there, like #include <io.h>, definition of O_BINARY and alike, so it's all in one place.

deleted related things from config.h.win32

As of these massive changes, I'm almost certain that this will break the Unix build. I'll keep an eye on the buildbot so hopefully everything is working again soon.

svn path=/trunk/; revision=16403
2005-11-06 22:43:25 +00:00
Ulf Lamping 84cf7ce767 added compression support for capture file output. The Save/As dialog now has a checkbox "Compress with gzip"
currently limited to Ethereal and all the variants of libpcap filetypes only.

We might want to add output compression support to the other tools as well (tethereal, mergecap, ...).

We might also want to add support for the other filetypes, but this is only possible if the filetype functions doesn't use special output operations like fseek.

One bug is still left: if the input and output filetypes while saving are the same, Ethereal currently optimizes this by simply copy the binary file instead of using wiretap (so it will be faster but it will ignore the compress setting). 

Don't know a good workaround for this, as I don't know a way to find out if the input file is currently compressed or not. One idea might be to use a heuristic on the filesize (compared to the packet size summmary). Another workaround I see is to remove this optimization, which is of course not the way I like to do it ...

svn path=/trunk/; revision=15804
2005-09-14 21:57:30 +00:00
Ulf Lamping e93b50c820 fix #357: increment ring buffer "file names" (again?)
svn path=/trunk/; revision=15440
2005-08-19 21:13:49 +00:00
Guy Harris 38ec1644e6 Add APIs to Wiretap to return the file of the size as supplied by the OS
(so if the file's gzipped, it's *NOT* the size of the file after
uncompressing), and an approximation of the amount of that data read
sequentially so far.

Use those for various progress bars and the like.

Make the fstat() in the Ascend trace reader directly use wth->fd, as
it's inside Wiretap; that gets rid of the last caller of wtap_fd() (as
we're no longer directly using fstat() or lseek() in Ethereal), so get
rid of wtap_fd().

svn path=/trunk/; revision=15437
2005-08-19 19:40:00 +00:00
Ulf Lamping 0dc9fb3d4a various code cleanup:
-use g_snprintf instead of sprintf and snprintf
-use g_strdup_printf where appropriate
-remove #include "snprintf.h" (as only g_snprintf should be used)
-replace some more alloc/realloc/calloc/free with their glib pendants

svn path=/trunk/; revision=15264
2005-08-08 18:50:39 +00:00
Ulf Lamping 7e78ef354e major capture engine rework: use two task model for EVERY capture mode
rework of the -b command line parameter (for Ethereal and Tethereal)

svn path=/trunk/; revision=13949
2005-03-28 00:19:02 +00:00
Ulf Lamping be0e6a0631 prevent ringbuffer from having to know about capture_file type at all (decoupling dependencies)
svn path=/trunk/; revision=13266
2005-02-03 21:58:33 +00:00
Ulf Lamping 949338af56 don't use two variables for keeping the current ringbuffer file number
svn path=/trunk/; revision=13009
2005-01-12 21:41:30 +00:00
Guy Harris 8a8b883450 Set the svn:eol-style property on all text files to "native", so that
they have LF at the end of the line on UN*X and CR/LF on Windows;
hopefully this means that if a CR/LF version is checked in on Windows,
the CRs will be stripped so that they show up only when checked out on
Windows, not on UN*X.

svn path=/trunk/; revision=11400
2004-07-18 00:24:25 +00:00
Guy Harris 272a2055ab On at least some platforms, a #define of O_BINARY is needed even if
<fcntl.h> is included, as <fcntl.h> doesn't define it.

svn path=/trunk/; revision=11276
2004-06-30 06:58:59 +00:00
Ulf Lamping a24b176c32 define of O_BINARY not needed, if fcntl.h is included
other #include related cleanups

svn path=/trunk/; revision=11272
2004-06-29 20:51:26 +00:00
Guy Harris 782e8b798b If, when rotating capture files, the attempt to close the current file
fails, set "rb_data.pdh" to NULL, so we know it's not open (if
"wtap_dump_close()" fails, the wtap_dumper_t is still closed - and the
file descriptor for it is probably closed, too, as, if "close()" fails,
the FD is probably closed; the Single UNIX Specification Version 3 says
the state of the FD is unspecified, but in practice most OSes probably
still close it).

If we try to close the current file, first check to make sure it's open,
i.e. that "rb_data.pdh" is non-null.  (Or perhaps we should avoid trying
to close it if the open *or* the most recent attempt to rotate the
capture files failed.)

Note that if "wtap_dump_close()" fails we might not need to close the
underlying file descriptor (and, even if we do, there's no guarantee
that attempt won't also fail and leave the FD still open - which is why
I suspect that a failed "close()" leaves the FD closed on most OSes).

svn path=/trunk/; revision=11075
2004-06-02 18:49:40 +00:00
Guy Harris dd264ba190 Only handle as a suffix stuff following a "." in the last component of a
pathname.

svn path=/trunk/; revision=10233
2004-02-25 05:52:37 +00:00
Guy Harris 983e4f9de3 Don't unlink ringbuffer files if we haven't yet allocated the array of
ringbuffer files - yes, we can fail before that's done, so we have to
check for that.

svn path=/trunk/; revision=10232
2004-02-25 05:21:08 +00:00
Laurent Deniel 0afce7ca81 Ringbuffer rework.
Almost completely rewritten in order to:

- be able to use a unlimited number of ringbuffer files

  0 specified with -b argument or in the GUI, means that the number of file
  is unlimited.

  else the maximum number of ring buffer files is arbitrarily set to 1024.

- close the current file and open (truncating it) the next file at switch

- set the final file name once open (or reopen)

- avoid the deletion of files that could not be truncated (can't arise now)
  and do not erase empty files

The idea behind that is to remove the limitation of the maximum # of
ringbuffer files being less than the maximum # of open fd per process
and to be able to reduce the amount of virtual memory usage (having only
one file open at most) or the amount of file system usage (by truncating
the files at switch and not the capture stop, and by closing them which
makes possible their move or deletion after a switch).

svn path=/trunk/; revision=7912
2003-06-22 16:09:04 +00:00
Gerald Combs 18061d6537 From Graeme Hewson:
It can sometimes happen that capturing is stopped just after Ethereal
  has switched to a new ring buffer.  The result is that no frames
  are displayed.  The patch to ringbuffer.c displays the previous ring
  buffer if the current buffer is empty on close.

  The patch to capture.c fixes a bug where an error return from
  ringbuf_wtap_dump_close was ignored, and tidies up the code around
  the call.

svn path=/trunk/; revision=6315
2002-09-22 16:17:41 +00:00