aboutsummaryrefslogtreecommitdiffstats
path: root/ringbuffer.c
AgeCommit message (Collapse)AuthorFilesLines
2024-01-24ringbuffer: Use g_path_get_basename to find the last componentJohn Thacker1-18/+17
On Windows, the path separator can be either G_DIR_SEPARATOR or '/' (G_DIR_SEPARATOR_S). Just use g_path_get_basename and g_path_get_dirname rather than reinventing them, or worrying about which directory separator we've passed to the function. Fix #14614
2023-02-06Remove wspcap.h and use config.h insteadJoão Valverde1-1/+1
Forcing the use of a dedicated header to replace pcap.h is unnecessary code and mental overhead in this case. We can use config.h instead for the same purpose of defining a macro symbol before including pcap.h.
2022-02-20Remove editor modelines and .editorconfig exceptions from root filesDavid Perry1-388/+382
2022-01-21Fix no-ZLib builds.Guy Harris1-0/+4
Don't use ZLib routines or data types if we're built without ZLib. Don't support --compress-type=gzip, or a gzip check box in the Output pane of the Capture Options dialog, if we're built without ZLib. Fixes #17899.
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-09-14Add tshark ringbuffer option '-b nametimenum:value'Juha Takala1-3/+9
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-06-19Replace g_assert() with ws_assert()João Valverde1-1/+0
2021-04-30Cast away the return value of g_strlcpy() and g_strlcat().Guy Harris1-1/+1
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).
2020-12-22Detect and replace bad allocation patternsMoshe Kaplan1-1/+1
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-11-27ringbuffer.c: avoid leaking gzFile handleMoshe Kaplan1-0/+1
Avoid leaking the gzFile handle when g_malloc() fails. This fixes coverity issue 1468698.
2020-10-30add support for compression of capture fileMasaru Tsuchiyama1-1/+138
2020-08-08Dumpcap: print closed ring-buffer file namesDavid Perry1-0/+50
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>
2019-05-03CMake: Remove wsutil pcap dependencyJoão Valverde1-1/+1
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-03-14dumpcap: Reallocate the IO buffer when switching the ring buffer filesVasil Velichkov1-2/+3
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-10Dumpcap: Set a bigger IO buffer (64KiB).Anders Broman1-8/+32
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-01-26dumpcap: fix memory leak in ringbuffer modePeter Wu1-1/+11
'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>
2018-02-08replace SPDX identifier GPL-2.0+ with GPL-2.0-or-later.Dario Lombardo1-1/+1
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>
2017-11-09Start using SPDX license identifiers.Gerald Combs1-13/+1
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-05-11Put the HAVE_REMOTE hack into wsutil/wspcap.h, and include that file.Guy Harris1-13/+1
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-11Force HAVE_REMOTE to be defined when including pcap.h with remote support.Guy Harris1-0/+12
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-04-18Check the result of localtime().Guy Harris1-7/+6
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>
2016-10-22More checks for localtime() and gmtime() returning NULL.Guy Harris1-0/+6
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>
2015-11-07Clean up includes of unistd.h, fcntl.h, and sys/stat.h.Guy Harris1-8/+0
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>
2014-10-12Add editor modelines; Adjust whitespace as needed.Bill Meier1-7/+20
Change-Id: I4da7b335d905dbca10bbce03aa88e1cdeeb1f8ad Reviewed-on: https://code.wireshark.org/review/4626 Reviewed-by: Bill Meier <wmeier@newsguy.com>
2014-08-24Modify includes of config.h so that out-of-tree builds, i.e. CMakeGraham Bloice1-1/+1
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-03-04Remove all $Id$ from top of fileAlexis La Goutte1-2/+0
(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-02-25Remove trailing whitespaceBill Meier1-1/+1
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>
2013-03-31coverity 990813 dereference after null checkMartin Kaiser1-2/+3
(hope I got it right this time) svn path=/trunk/; revision=48673
2013-03-13 add missing NULL checkMartin Kaiser1-1/+1
http://www.wireshark.org/download/automated/analysis/scan-build-2013-03-12-1/report-q1cLLC.html#EndPath svn path=/trunk/; revision=48283
2012-12-20fclose() and fflush() are standard C routines, so there's no need forGuy Harris1-4/+4
our own wrappers. (pcapio.c isn't using wrappers around, for example, fwrite().) svn path=/trunk/; revision=46640
2012-12-20Add ws_fclose(), ws_fflush(), and ws_fdopen() to the fileutils.Michael Tüxen1-10/+17
Retire libpcap_fdopen(), libpcap_dump_flush(), and libpcap_dump_close(). svn path=/trunk/; revision=46636
2012-09-20We always HAVE_CONFIG_H so don't bother checking whether we have it or not.Jeff Morriss1-2/+0
svn path=/trunk/; revision=45015
2012-06-28Update Free Software Foundation address.Jakub Zawadzki1-1/+1
(COPYING will be updated in next commit) svn path=/trunk/; revision=43536
2011-05-17Fix another old-style function definition.Guy Harris1-1/+1
svn path=/trunk/; revision=37224
2010-08-28As mentioned on the users-mailinglist[1], it could be useful to have groups ↵Sake Blok1-2/+5
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-05-27Set RINGBUFFER_MAX_NUM_FILES to 100000. Use it to generate file names.Gerald Combs1-1/+1
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-03-11Squelch some compiler warnings.Guy Harris1-1/+1
svn path=/trunk/; revision=32165
2009-04-26Make ringbuffer.[ch] file format agnostic.Michael Tüxen1-14/+4
Move write routines to dumpcap.c This is a preparation for pcapng support. svn path=/trunk/; revision=28155
2008-05-22Move the file utility functions from wiretap to libwsutil so thatJeff Morriss1-12/+12
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
2007-05-15Fix for bug 1591:Jaap Keuter1-4/+4
The 5 digit file number should contain the monotonic increasing file number modulo 100000 to fit the alloted space. svn path=/trunk/; revision=21775
2006-05-21name changeRonnie Sahlberg1-2/+2
svn path=/trunk/; revision=18197
2006-04-29Have the ring buffer routines take a pointer to a "bytes written" countGuy Harris1-6/+7
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-03-04When capturing, we only support writing to libpcap files. Given that,Guy Harris1-18/+21
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
2005-11-06replace *a lot* of file related calls by their GLib counterparts. This is ↵Ulf Lamping1-14/+7
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-09-14added compression support for capture file output. The Save/As dialog now ↵Ulf Lamping1-1/+1
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-08-19fix #357: increment ring buffer "file names" (again?)Ulf Lamping1-5/+5
svn path=/trunk/; revision=15440
2005-08-19Add APIs to Wiretap to return the file of the size as supplied by the OSGuy Harris1-5/+1
(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-08various code cleanup:Ulf Lamping1-5/+1
-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-03-28major capture engine rework: use two task model for EVERY capture modeUlf Lamping1-0/+6
rework of the -b command line parameter (for Ethereal and Tethereal) svn path=/trunk/; revision=13949