| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
| |
This should fix Coverity CID 1507240.
|
|
|
|
|
|
| |
These were format-truncation warnings (See issue #1029).
This is a workaround while waiting for a fix.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
Check for it in pcap_open_live() and pcap_open() before trying to
dereference it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
|
|
|
| |
(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.)
|
| |
|
| |
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
Don't incorrectly reimplement strdup(), just use it.
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
That way, rpcapd doesn't depend on them being exported from libpcap
(which they shouldn't be).
|
| |
|
|
|
|
|
|
|
| |
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().
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
| |
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 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.
|
| |
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
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().
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
This allows PCAP_OPENFLAG_MAX_RESPONSIVENESS to work on UN*X (it means
"immediate mode").
|
|
|
|
|
| |
This is preparing for more general support for different types of remote
capture, using pcap_create() and pcap_activate().
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
This is a cleanup in the process of adding the rpcap server to the
project.
|
| |
|
| |
|
|
|
|
|
| |
Pass the full interface string, rather than just the name, to
pcap_open_rpcap().
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
They're not for remote capture in general, they're just for remote
capture using the rpcap protocol.
|
| |
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
don't switch it if the adapter is already in monitor mode when capture starts.
|
|
works with Wireshark.
|