aboutsummaryrefslogtreecommitdiff
path: root/pcap-new.c
Commit message (Collapse)AuthorAgeFilesLines
* pcap_findalldevs_ex(): close directory handle before returning.Guy Harris2022-07-121-1/+24
| | | | This should fix Coverity CID 1507240.
* Suppress temporarily the warnings with "enable remote packet capture"Francois-Xavier Le Bail2021-06-291-0/+7
| | | | | | These were format-truncation warnings (See issue #1029). This is a workaround while waiting for a fix.
* Remove some workarounds for old compilers.Guy Harris2019-08-091-11/+11
| | | | | | | | | | | | | Require Visual Studio 2015 or later; fail if we don't have it, and remove checks for older versions. That means we have C99-compliant snprintf() and vsnprintf(); require them when configuring for UN*X, and then use them directly, rather than having wrappers for systems lacking them. If we're using MSVC, skip the tests for options to request C99 compatibility - either we have VS 2015, which is sufficient, or we don't, in which case we fail.
* Clean up some references to WinPcap.Guy Harris2019-04-191-1/+1
| | | | | | We're currently unlikely to be used with WinPcap, although you could build libpcap on Windows with the WinPcap SDK and install and use it; we are, however, built with Npcap as part of the Npcap binary.
* Handle pcap_open_live(), and other routines, using NULL to mean "any".Guy Harris2019-04-111-0/+10
| | | | | Check for it in pcap_open_live() and pcap_open() before trying to dereference it.
* Make sure asprintf() is declared if it's present.Guy Harris2019-03-191-0/+2
| | | | | | | | | | | | | | | | | GNU libc is a pain. If you don't define _GNU_SOURCE, it doesn't declare asprintf(). If you *do* define _GNU_SOURCE, the strerror_r() it declares isn't POSIX-compliant. We use asprintf() if present, so we need it to be declared; define _GNU_SOURCE in ftmacros.h. At configuration time, if we have strerror_r(), check whether it's GNU-style or POSIX-style, and define different #defines for those two cases. Handle GNU-style strerror_r() and POSIX-style strerror_r() differently in pcap_fmt_errmsg_for_errno(). Make sure everything that uses asprintf() includes ftmacros.h before including stdio.h.
* Use asprintf(), and provide a version for systems that lack it.Guy Harris2019-02-091-31/+6
| | | | | | | | | | | | | | | | | | | | | | | | This lets us get rid of places where we calculate the length that a formatted string will require, attempt to allocate a buffer for the string, and then format the string into that buffer; this way, we don't have to hope we got the calculation correct, we rely on the same code that formats strings to do the calculation. Provide versions of asprintf() for: 1) Windows and the MSVC runtime, where we use _vscprintf() to determine the length; 2) systems that have (what is presumed to be) an snprintf() that, when handed a too-short buffer, returns the number of characters that would have been written had the buffer been long enough (as C99 specifies), where we format to a one-character buffer to determine the length; 3) systems that don't have snprintf(), where we use the asprintf() provided by the missing/snprintf.c file that also provides snprintf(). While we're at it, include "portability.h" in missing/win_snprintf.c, to get declaration/definition checking done.
* Fix copy-and-pasteo.Guy Harris2019-02-071-1/+1
|
* ISO C99 has what's needed to implement asprintf(), so fix a comment.Guy Harris2019-02-071-3/+0
| | | | | | | | | (It says that that, if the result of snprintf() won't fit into the buffer, snprintf() returns how many characters would have been put into the buffer had it fit. That way, you can format into a 1-char buffer and then allocate a buffer of the specified size + 1 and pass that buffer and the appropriate size to snprintf() to format into the buffer.)
* Fix comments.Guy Harris2019-02-071-2/+2
|
* Fix whitespace.Guy Harris2019-02-071-1/+1
|
* Don't format into an on-the-stack buffer and copy it to a mallocated buffer.Guy Harris2019-02-071-20/+59
| | | | | | | | | Instead, mallocate the buffer for the name first, and then format into *that* buffer. This avoids the risk of truncating the string when formatted into the on-the-stack buffer, squelching some compiler warnings and possibly squelching truncation.
* Use strdup() to mallocate a copy of a string.Guy Harris2019-02-071-14/+2
| | | | Don't incorrectly reimplement strdup(), just use it.
* More constification of arguments.Guy Harris2018-12-251-1/+1
| | | | | | | | | | We don't modify the source argument to pcap_findalldevs_ex(), so make that a promise, so compilers don't get upset when a constant string is passed. See, for example: https://stackoverflow.com/questions/52397129/winpcap-findalldevs-const-char-incompatible-to-char
* Provide out own strlcpy() and strlcat() routines if necessary.Guy Harris2018-10-161-4/+4
| | | | | | | | | | | | | | We now depend on the *full* semantics of those routines, including the return value being usable for truncation checks. If we're building for a UN*X that has them, define pcap_strl{cpy,cat} to be strl{cpy,cat}. If we're building for Windows using MSVC, define pcap_strl{cpy,cat}, not strl{cpy,cat}. Otherwise, build our won versions of pcap_strl{cpy,cat} from BSD-derived source code.
* Add a routine to format error messages with an errno-based message at the end.Guy Harris2017-11-151-5/+15
| | | | | | | | | | | | | | That routine will use strerror_s() or strerror_r() if available, in a fashion that's thread-safe. Otherwise, it falls back on pcap_strerror(). Use it in both libpcap and rpcapd. Given that we check for errors in strerror_r(), hopefully this will squelch warnings with newer version of GCC and GNU libc; whilst the macOS (and other BSD-flavored?) strerror_r() always fills in a message, that's not required by the Single UNIX Specification, as far as I can tell, so we apparently really *do* need to check for errors.
* Plug memory leaks and clean up interface list creation.Guy Harris2017-11-131-14/+34
| | | | | | | | | | | | If we fail in the middle of constructing lists of savefiles or remote devices, free the entries we've already allocated. Use separate variables for "current device" and "last device in the list", to try to squelch some warnings. We already rely on the pointer to the place where the device list pointer should be put not being null; no need to handle the case where it is null.
* Put rpcap protocol routines common to client and server in rpcap-protocol.cGuy Harris2017-09-301-1/+0
| | | | | That way, rpcapd doesn't depend on them being exported from libpcap (which they shouldn't be).
* Fix Windows build errors.Guy Harris2017-09-061-1/+1
|
* Move the ADAPTER * out of pcap_t into the pcap-win32.c private data.Guy Harris2017-09-061-19/+9
| | | | | | | That avoids leaking packet.dll stuff into the generic code. Have, instead, a HANDLE, and set it to the hFile member of the ADAPTER structure, so we can return it from pcap_fileno().
* Move URL parsing and construction to pcap.c.Guy Harris2017-09-041-225/+0
| | | | | | | | | | Eventually, there will be new APIs allowing opening of remote interfaces in a create/activate style; they will do URL parsing and will be in pcap.c. This is part of that, as well as part of a shorter-term project to replace pcap_parsesrcstr()'s sscanf-based URL parsing with something not using sscanf(), because we want to avoid MSVC complaints about sscanf's insecurity without just replacing sscanf with sscanf_s(), as their APIs are not the same.
* Make sure sockutils.h is included before portability.h.Guy Harris2017-09-031-1/+6
| | | | | | | | sockutils.h may include <crtdbg.h> on Windows, and portability.h expects that, if <crtdbg.h> is going to be included, it'll be included before portability.h, so that, if __STDC__ is 0, strdup will have been defined by <crtdbg.h>, and portability.h won't define it only to have a later include of <crtdbg.h> redefine it and provoke warnings.
* Always include <config.h> rather than "config.h".Guy Harris2017-08-181-1/+1
| | | | | | | | This can prevent bizarre failures if, for example, you've done a configuration in the top-level source directory, leaving behind one config.h file, and then do an out-of-tree build in another directory, with different configuration options. This way, we always pick up the same config.h, in the build directory.
* Move the RPCAP-specific functions to pcap-rpcap.h.Guy Harris2017-03-201-0/+1
| | | | | | | Move the declarations of the interfaces that are currently used for RPCAP by pcap_open_live(), pcap_open(), and pcap_findalldevs_ex() to pcap-rpcap.h; in the future, that will hold the routines used by pcap_create() and any future API for enumerating interfaces.
* Get rid of extra semicolon.Guy Harris2017-03-191-1/+1
|
* Move the active-mode stuff to pcap-rpcap.c.Guy Harris2017-03-141-275/+0
| | | | | | It's not a general API, it's a hack for doing active mode with RPCAP. Make the variables it uses static, as they're not used anywhere else.
* Make this code a bit more like future code.Guy Harris2017-03-131-66/+65
| | | | | | This is a bit more like some under-development code that supports remote interfaces with pcap_create()/pcap_activate() and uses them for remote interfaces in pcap_open().
* Fix remote opening and remote open error string return.Guy Harris2017-03-131-4/+4
| | | | | | | Pass the interface name, not the full URL, to pcap_create(). If pcap_open_rpcap() fails, copy the error message from the pcap_t to errbuf, as we'll be closing and freeing the pcap_t.
* Move rpcap-protocol.h to the top-level directory.Guy Harris2017-03-131-1/+1
| | | | | | That means that everything in rpcap is part of rpcapd. Fix up the list of files included in the tarball while we're at it.
* In pcap_open(), use pcap_create() and pcap_activate() for local interfaces.Guy Harris2017-03-131-25/+57
| | | | | This allows PCAP_OPENFLAG_MAX_RESPONSIVENESS to work on UN*X (it means "immediate mode").
* Rename pcap-rpcap.h to pcap-rpcap-int.h.Guy Harris2017-03-131-1/+1
| | | | | This is preparing for more general support for different types of remote capture, using pcap_create() and pcap_activate().
* Use _WIN32 consistently, but don't use it for threads vs. subprocesses.Guy Harris2017-03-131-9/+9
| | | | | | | | | | | | Use _WIN32, rather than WIN32; the former is automatically defined, the latter isn't. Don't make "threads vs. subprocesses" a Windows-vs.-UN*X issue; at the time the daemon was written, UN*X pthreads support may not have been good, or even available, on all platforms, but it's pretty much ubiquitous these days on UN*Xes. Have a USE_PTHREADS #define; currently, just define it on Windows, but leave open the option to define it on UN*X as well.
* Put rpcap protocol definitions into rpcap/rpcap-protocol.h.Guy Harris2017-03-101-1/+2
| | | | | This is a cleanup in the process of adding the rpcap server to the project.
* Move the pcap_findalldevs_ex code for rpcap into pcap-rpcap.cGuy Harris2017-03-101-345/+11
|
* Remove unused variables, clean up comments.Guy Harris2017-03-081-5/+7
|
* Get remote capture almost working.Joerg Mayer2017-03-081-3/+3
| | | | | Pass the full interface string, rather than just the name, to pcap_open_rpcap().
* Get rid of unused structure declaration.Guy Harris2017-03-081-13/+0
|
* Clean up remote capture.Guy Harris2017-03-081-29/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a configuration option to enable remote capture in libpcap. It defaults to being disabled, and, if enabled, warns that it might expose libpcap-based programs to attack by malicious remote capture servers. (The code needs to be carefully audite to make sure there aren't any buffer overflow, etc. exploits before we remove that warning or default to enabling it.) Put the sampling parameters into the pcap_t; in theory, at least, it could be supported by all capture mechanisms, although it's currently only supported by Win32 local capture and rpcap-based capture. Have a private data structure for remote capture, just as we do for local capture sources. Have it contain only what's needed for remote capture. Have a pcap_open_rpcap() routine that does all the work of opening a pcap_t; if remote capture is enabled, call it from pcap_open() and pcap_open_live() if pcap_parsesrc() indicates that we were handed a remote capture URL. Put back the sampling code into the Win32 local capture code. Turn the static variables used for sampling into members of its private data structure, so we don't get collisions if there's more than one pcap_t open. Don't support remote capture for pcap_create()/pcap_activate() - that might ultimately involve API changes that existing programs would have to be changed to handle, such as "username/password needed" and "authentication failed" error returns for which the application might prompt or re-prompt for a user name and/or a password - we might, for example, have a new pcap_create_ routine that would be called by programs prepared to handle remote capture. NOTE: this is not the final form of the code; once full remote capture support is added, with some pcap_create_ routine handling URLs, pcap_open() and pcap_open_live() will not have to handle URLs themselves, for example.
* Mark a remote capture pcap_t as activated once it's opened.Guy Harris2017-03-071-0/+1
|
* Remove trailing spaces/tabsFrancois-Xavier Le Bail2016-08-201-3/+3
|
* Use strdup() to make mallocated copies of strings.Guy Harris2016-07-311-11/+4
|
* A pointer to an array is never null, so don't check if it is.Guy Harris2016-07-311-1/+1
|
* Add a variable that should have been in the previous commit.Guy Harris2016-07-311-0/+1
|
* Assorted cleanups.Guy Harris2016-07-311-31/+36
| | | | | | | | | | As done in pcap-rpcap.c, assign the result of sock_recv() to a variable, and check that variable against -1, rather than *adding* it to a variable and checking the *sum* against -1. Clean up the finalldevs code to avoid a "used but not set" error. Remove extra blank lines.
* Rename pcap-remote.[ch] to pcap-rpcap.[ch].Guy Harris2016-07-301-1/+1
| | | | | They're not for remote capture in general, they're just for remote capture using the rpcap protocol.
* Fix MSVC compile warnings on the WinPcap specific code.Yang Luo2016-07-291-27/+27
|
* Have rpcap_remoteact_getsock() return a SOCKET and supply an "is active" flag.Guy Harris2016-07-281-11/+8
| | | | | | Have it return a SOCKET, rather than an int, and return INVALID_SOCKET if it fails. Pass it a pointer to an int and set the int to 1 if it finds an active-mode entry for the host and 0 if it doesn't.
* Switch back to managed mode when closing the pcap if it switched it on, ↵Yang Luo2016-07-261-1/+1
| | | | don't switch it if the adapter is already in monitor mode when capture starts.
* Add back WinPcap specific functions to libpcap, the built wpcap.dll already ↵Yang Luo2016-07-261-0/+1269
works with Wireshark.