summaryrefslogtreecommitdiff
path: root/tcpdump.c
Commit message (Collapse)AuthorAgeFilesLines
* child_cleanup: reap as many child processes as possibleDominique Martinet2023-04-191-1/+1
| | | | | | | | | | | | | Under load it's possible multiple child processes have been killed before we start processing the SIGCHILD signal, leaving zombie processes behind everytime we miss a process. Reap as many processes as possible instead of assuming one handler call = one process like we currently did. Can be reproduced by running the following commands in parallel: - tcpdump -i lo -w /tmp/test -C 1 -z /usr/bin/true - iperf3 -s - iperf3 -c localhost
* tcpdump.c: fix a comment. [skip ci]Guy Harris2023-02-251-1/+1
| | | | | | | Some versions of Mac OS X (as it was then called) *did*, in fact, ship with a libpcap that had pcap_findalldevs() but a pcap.h that didn't define pcap_if_t; it's not a question of "may ship", it's a fact of "did ship".
* Detect OS IPv6 support using AF_INET6 only.Denis Ovsienko2023-02-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | tcpdump source code has not been using struct in6_addr since commit 0c9cfdc in 2019, so lose the conditional structure declaration, which is a no-op. Since commit de7c619 in 2015 netdissect-stdinc.h on Windows defines HAVE_OS_IPV6_SUPPORT if AF_INET6 if defined, which makes it equivalent to AF_INET6. On Unix-like systems taking struct in6_addr out of scope would make HAVE_OS_IPV6_SUPPORT equivalent to AF_INET6, thus after removing struct in6_addr remove HAVE_OS_IPV6_SUPPORT together with Autoconf and CMake checks that define it. Leave an unrelated CMake workaround in place for later debugging. On Windows do not define AF_INET6 if it is not defined, which makes AF_INET6 a universal indicator of the OS IPv6 support on all supported OSes. The few remaining use cases that genuinely need AF_INET6 use it to make OS API calls, so if the macro is not defined, it most likely means such an API call in the best case would return just a well-formed error status. With this in mind, in win32_gethostbyaddr() and ip6addr_string() guard all IPv6-specific code with #ifdef AF_INET6. In tcpdump.c add a comment to note why a guard is not required for Casper-specific conditional code that uses AF_INET6. This way when the OS does not support IPv6, IPv6 addresses will not resolve to names, which is expected. Other than that, tcpdump should be able to process IPv6 addresses the usual way regardless if the OS would be able to process the packets with these addresses.
* tcpdump: plug a memory leak.Guy Harris2023-02-051-0/+2
| | | | | | | If the -V flag is used, and not all files in the -V file have the same link-layer type, when the filter is recompiled for a new link-layer type, the old filter program is leaked. Free the old filter before compiling the new filter.
* Have a common routine for converting dates and times to strings.Guy Harris2023-02-021-2/+20
| | | | | | | | | | | | | | | | | | | | | | | Have a routine that takes a buffer, a strftime format, and a struct tm * as arguments, and: * checks whether the struct tm * is null and, if so, returns a string indicating that the date and time couldn't be converted; * otherwise, passes it to strftime(), along with the buffer and the format argument and, if strftime() returns 0, meaning the string didn't fit into the buffer and thus that the buffer's contents are undefined, returns a string indicating that the date and time didn't fit into the buffer; * otherwise, returns a pointer to the buffer. Call that routine instead of directly calling strftime() in printers; that prevents printing a buffer with undefined data if the buffer isn't big enough for the string. Also, when generating file names using an strftime format, check the return value of strftime() to make sure the buffer didn't overflow.
* Set SA_RESTART on non-lethal signals (REQ_INFO, FLUSH_PCAP) to avoid ↵Alexandre Ferrieux2022-07-161-1/+8
| | | | corrupting binary pcap output
* Use more S_SUCCESS and S_ERR_HOST_PROGRAM in main()Francois-Xavier Le Bail2022-02-041-1/+1
|
* Add --print-sampling option to print every Nth packetNathan O'Sullivan2022-01-171-2/+14
| | | | | | | | | New option `--print-sampling=NTH` will parse and print every NTH packet, with all other packets producing no output. This option enables `--print` and `-S` flags. Print sampling is useful for real-time inspection of an interface with a high packet rate, or initial inspection of large capture files.
* Initial support to parse QUIC packets.Rui Paulo2021-11-091-0/+2
|
* Remove the space I added to provoke a rebuild.Guy Harris2021-08-111-1/+1
| | | | | (This should also provoke a rebuild; the NetBSD libpcap build should no longer have the issue that caused tcpdump to fail when built with it.)
* Add a space at the end of the first line, to provoke a build.Guy Harris2021-08-111-1/+1
| | | | | | | (There doesn't appear to be an obvious way to force a rebuild, and a change to libpcap doesn't force a rebuild of programs such as tcpdump for which the CI build includes a build with the tip of the main branch of libpcap.)
* Use basename() and dirname() right on FreeBSD. [skip appveyor]Denis Ovsienko2021-08-051-3/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | On FreeBSD CMake runs Clang with -std=gnu99, which used to emit three warnings in a Capsicum-specific block along the following lines: tcpdump.c:2432:32: warning: '_Generic' is a C11 extension [-Wc11-extensions] /usr/include/libgen.h:61:21: note: expanded from macro 'basename' basename)(x) /usr/include/sys/cdefs.h:325:2: note: expanded from macro '__generic' _Generic(expr, t: yes, default: no) (In the same context Autoconf does not request a specific C standard from Clang, so it happens to use C17 and there is no warning.) Type-generic expressions support in C99 mode seems to be a quirk of Clang that cannot be disabled and is harmless in this context, so introduce and use another pair of diagnostic control macros (for Clang only) to squelch the warnings. While at it, study the reason for _Generic use in /usr/include/libgen.h and realize that tcpdump.c still assumes the behaviour before FreeBSD 12.0. Add two temporary buffers around basename() and dirname() calls to get consistent results regardless of which FreeBSD version it is. Remove the last remaining exemption rule.
* Squelch a warning with Capsicum enabled. [skip appveyor]Denis Ovsienko2021-08-041-1/+3
| | | | | | | | | | | The Capsicum workaround I added in commit 706c79e causes a side effect on FreeBSD 11.4, 12.2 and 13.0 with local libpcap when Capsicum is enabled, that is, in CMake builds (Capsicum detection is broken in Autoconf builds, as it turns out). Add a workaround for the side effect as well and get rid of another warning and respective exemption: tcpdump.c:2286:3: warning: implicit declaration of function 'bpf_dump' is invalid in C99 [-Wimplicit-function-declaration]
* Move capdns from tcpdump.c to addrtoname.c.Denis Ovsienko2021-08-021-4/+0
| | | | | | | | Address the warning below (specific to a few versions of Clang, CMake and FreeBSD) and update the exemption rule comment in build.sh. tcpdump.c:244:16: warning: no previous extern declaration for non-static variable 'capdns' [-Wmissing-variable-declarations]
* Suppress "casting away const" warnings in missing/getopt_long.c.Guy Harris2021-07-241-10/+12
| | | | | | | | | | | | | | | | | It's explicitly cheating in some places; just cast away the warnings. Add a Clang version testing macro to compiler-tests.h. Move the diagnostic control #defines from netdissect-stdinc.h to diag-control.h, libpcap-style, so that they can be used by code that doesn't use (or need) netdissect-stdinc.h. This also means that we can limit the inclusion of diag-control.h, and the definition of those Do them more libpcap-style, with separate DIAG_OFF/DIAG_ON pairs for particular issues, rather than having DIAG_OFF() and DIAG_ON() macros that take -W option names as arguments; that way, if we need to define them for compilers that don't have the GCC/Clang syntax for those pragmas, e.g. MSVC, we can do so.
* Improve the handling of size suffixes for -C.Guy Harris2021-07-101-15/+61
| | | | | | | | | Support upper-case suffixes (K/M/G) as well as lower-case suffixes. Make sure nothing *follows* the suffix. We don't need to check for the suffix before parsing the number; the parsing routines stop if they see a non-digit character.
* Merge pull request #916 from stevekay/masterGuy Harris2021-07-101-4/+17
|\ | | | | optional unit suffix on -C file size
| * optional unit suffix on -CSteve Kay2021-05-081-4/+17
| |
* | Print the supported time stamp types (-J) to stdout instead of stderrFrancois-Xavier Le Bail2021-07-081-3/+3
| | | | | | | | It is not an error, thus print them to stdout.
* | Factorize some codeFrancois-Xavier Le Bail2021-07-081-2/+4
| |
* | Print the list of data link types (-L) to stdout instead of stderrFrancois-Xavier Le Bail2021-07-071-6/+6
|/ | | | It is not an error, thus print it to stdout.
* Lose a few forward declarations in tcpdump.c.Denis Ovsienko2021-03-291-29/+15
| | | | Reinstate a few comments in print.c for consistency.
* Print the optional packet count (--count) to stdout instead of stderrFrancois-Xavier Le Bail2020-11-041-1/+1
| | | | | | It is not an error, thus print it to stdout. [skip ci]
* Use __func__ from C99 in error messages. [skip ci]Denis Ovsienko2020-10-081-8/+8
| | | | | This automatically fixes a few error messages that would tell an incorrect function name.
* Handle very large -f files by rejecting them.Guy Harris2020-09-301-3/+12
| | | | | | | | | | | | _read(), on Windows, has a 32-bit size argument and a 32-bit return value, so reject -f files that have more than 2^31-1 characters. Add some #defines so that, on Windows, we use _fstati64 to get the size of that file, to handle large files. Don't assume that our definition for ssize_t is the same size as size_t; by the time we want to print the return value of the read, we know it'll fit into an int, so just cast it to int and print it with %d.
* Make version and usage printing more consistent. [skip ci]Denis Ovsienko2020-09-101-26/+26
| | | | | | When there is an error, print to stderr and exit with a non-0 status. Otherwise print to stdout and exit with a status 0. See also tcpslice commit 5015245.
* Report periodic stats only when safe to do so. [skip ci]tcpdump-4.10.0-bpDenis Ovsienko2020-08-291-1/+4
| | | | | | | | | | | | | | | | As explained in GH #155, when tcpdump is given -r, -w and -v and it takes long enough to read from the input file (because it is stdin connected through network or a pipe to stdout of another tcpdump doing a live capture), pcap_loop() will error before long. One of the ways to reproduce the fault is as follows: $ tcpdump -i eno1 -w - | tcpdump -r - -w /tmp/tmp.pcap -v tcpdump: listening on eno1, link-type EN10MB (Ethernet), snapshot length 262144 bytes reading from file -, link-type EN10MB (Ethernet), snapshot length 262144 tcpdump: pcap_loop: error reading dump file: Interrupted system call Skip the verbose_stats_dump() timer setup in this specific corner case for the time being and document it.
* Apply the last step of the new way to update the link-layer header lengthFrancois-Xavier Le Bail2020-08-061-3/+3
| | | | | | | | | | | All the link-layer dissectors are now void functions. All the functions were moved to the void_printers[] array. Rename this array to printers[]. Remove the uint_printers[] array, now empty. Remove the 'ndo_void_printer' flag field, now useless, from netdissect_options. Remove other transitional code.
* Use \ rather than / as a pathname separator in Windows.Guy Harris2020-06-111-1/+11
|
* Set default linktype LINUX_SLL2 when capturing on the "any" deviceFrancois-Xavier Le Bail2020-05-081-1/+10
|
* Update the message about the verbose optionFrancois-Xavier Le Bail2020-04-241-1/+1
| | | | | | The -v (verbose) option can be repeated more than two times. [skip ci]
* Show MemorySanitizer presence in version outputFrancois-Xavier Le Bail2020-04-221-1/+3
| | | | | | | | | This may help to understand some bug reports. Moreover: s/CLang/Clang/ [skip ci]
* Update to avoid duplicate words detectionFrancois-Xavier Le Bail2020-03-301-1/+1
| | | | [skip ci]
* Add "domain" as an option for -TFrancois-Xavier Le Bail2020-03-021-0/+2
| | | | | | This allows tcpdump to handle DNS running on non-standard ports. Add two test files with DNS over TCP and DNS over UDP, port 8053.
* Don't show in the usage the removed in 2003 -a optionFrancois-Xavier Le Bail2020-02-271-1/+1
|
* Print an optional packet count on stderr instead of printing packetsFrancois-Xavier Le Bail2020-02-261-2/+14
| | | | | | | | | | This change add an option to print only on stderr the packet count when reading capture file(s) instead of parsing/printing the packets. If a filter is specified on the command line, tcpdump counts only packets that were matched by the filter expression. The option name is '--count'.
* Autosar SOME/IP protocol supportFrancesco Fondelli2020-02-191-0/+2
|
* Push the floating-point test into a separate file.Guy Harris2020-02-041-8/+3
| | | | | | Hopefully, that will make sure we don't optimize away anything that will, for example, cause us not to do things differently on 32-bit x86 using the x87 instructions.
* Do the floating-point tests closer to what we need.Guy Harris2020-02-041-11/+7
| | | | | | | | | It's All Very Complicated, so mirror what print-lmp.c does - just do a calculation based on a particular input value and print the result using the same format print-lmp.c does, and have tests/TESTrun see what that result is. Just do that inside tcpdump.c, so we don't need the fptype stuff.
* Do some tests based on the type of floating-point arithmetic tcpdump does.Guy Harris2020-02-041-0/+24
| | | | | | | | | Add a --fp-type flag to tcpdump, which causes it to do a floating-point operation and, based on the result of the operation, prints out "FPTYPE{n}", where {n} is a number indicating the result. Have tests/TESTrun run "./tcpdump --fp-type" and set a HAVE_ key based on that. Run some tests only for FPTYPE1.
* Use a short timeout, rather than immediate mode, for text output.Guy Harris2020-01-191-13/+15
| | | | | | | | That means that we do some buffering of packets. It also means we don't depend on the immediate-mode APIs being available. While we're at it, use the short timeout if we're doing text output in "line-buffered mode" as well as if we're doing it to a terminal.
* Move some code to better show how to handle pcap_activate() failure.Guy Harris2019-11-231-2/+2
| | | | | | | | | | | | | | If you call pcap_activate() and it fails, you still have a pcap_t from pcap_create(), and should close it. Moving the code after the error() calls doesn't make a difference, as error() exits, but it may make it clearer to those reading tcpdump.c for help in figuring out how to use libpcap that you should close the pcap_t if pcap_activate() fails. (In the future, there may also be the option of changing some options and trying again, e.g. changing the user name or password for a remote capture.)
* The ptp (precision time protocol) with UDP as the transport protocol.Partha Ghosh2019-11-221-0/+2
| | | | | | | | | - the print routines for ptp different ptp messages - test completed for sync message, announce message, delay request message, delay response message and follow up message. - integration of the ptp v2 code with the tcpdump code. Signed-off-by: Partha S. Ghosh <psglinux@gmail.com>
* Do not open an interface if not needed for -dBill Fenner2019-11-131-0/+23
|
* libdnet has bugs, do not use it.Denis Ovsienko2019-11-031-3/+0
| | | | | | | | | | | | | | | | | | The only function tcpdump used in libdnet was dnet_htoa(), which tries to translate a binary DECnet address to a nodename through a lookup in /etc/decnet.conf. The translation is slow and has a bug, so stop using the function and remove the dependency on libdnet. This makes tcpdump always print DECnet addresses in numeric format, if anybody needs the translation back they are welcome to fix libdnet or (more realistically) add an implementation of dnet_htoa() to the tcpdump source code and use it. (This is a forward-port of commit 9a6eb27 from tcpdump-4.9 to master. Sadly, together with libdnet this change removes the fine work that Guy had done in the master branch in commits ebf3f19 and 4ef8d63 to put libdnet usage right whilst my original "do not use libdnet" commit was aging in the pipeline.)
* Fix -V to fail invalid input safelyDenis Ovsienko2019-10-271-2/+4
| | | | | | | | | | | | | | This change fixes CVE-2018-14879. get_next_file() did not check the return value of strlen() and underflowed an array index if the line read by fgets() from the file started with \0. This caused an out-of-bounds read and could cause a write. Add the missing check. This vulnerability was discovered by Brian Carpenter & Geeknik Labs. Cherry picked from 9ba91381954ad325ea4fd26b9c65a8bd9a2a85b6 in 4.9 branch.
* Use MAXIMUM_SNAPLEN macroFrancois-Xavier Le Bail2019-10-081-1/+1
|
* Remove more old-compiler compensation.Guy Harris2019-08-081-3/+3
| | | | | | | | | | | | We require an environment with a C99-compatible snprintf(), so we don't need to work around older implementations. Make the configuration process fail if we don't have snprintf() and vsnprintf(). We require at least VS 2015, so we don't have to check for _MSC_VER >= 1400. Make the build fail if we don't have at least VS 2015. We apparently do, however, have to use __inline, as the VS 2015 documentation doesn't meaning plain old "inline". Update a comment.
* Fix a warningFrancois-Xavier Le Bail2019-08-041-1/+1
| | | | | | | ./tcpdump.c:1951:13: warning: assigning to 'char *' from 'const char [7]' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers] username = WITH_USER; ^ ~~~~~~~~~
* Fix a warningFrancois-Xavier Le Bail2019-08-041-0/+2
| | | | | | | | No chroot on Windows. The warning was: C:\projects\tcpdump\tcpdump.c(1450): warning C4189: 'chroot_dir': local variable is initialized but not referenced