Commit Graph

131 Commits

Author SHA1 Message Date
Guy Harris
bd22f1fd9a Clean up ESP and ISAKMP decryption.
At least as I read RFC 5996 section 3.14 and RFC 4303 section 2.4, if
the cipher has a block size of which the ciphertext's size must be a
multiple, the payload must be padded to make that happen, so the
ciphertext length must be a multiple of the block size.  Instead of
allocating a buffer, copying the ciphertext to it, and padding it to the
block size, fail if its size isn't a multiple of the block size.

(Note also that the old padding code added a block's worth of padding to
the end of a ciphertext block that *was* a multiple of the cipher block
size; this might have caused problems.)

Don't use the undocumented EVP_Cipher(); the lack of documentation means
a lack of information about whatever requirements it might impose.  Use
EVP_DecryptUpdate() instead.

Before calling it, use EVP_CIPHER_CTX_set_padding() to say "don't do
your own padding, this block is a multiple of the cipher block size".

Instead of using EVP_CipherInit() or EVP_CipherInit_ex(), use
EVP_DecryptInit() or EVP_DecryptInit_ex().  as we're always doing
decryption and never doing encryption - the extra parameter to
EVP_CipherInit() and EVP_CipherInit_ex() is always 0.

This may address GitHub issue #814.

It may also make it a bit easier to have the code use Common Crypto on
macOS (rather than requiring that OpenSSL be installed - macOS ships
with an OpenSSL shared library for binary compatibility with older
releases, but doesn't ship with the headers, because Apple wants you
using their crypto code) and use Cryptography API: Next Generation on
Windows (Vista/Server 2008 and later) (rather than requiring a Windows
build of OpenSSL).

(Hopefully this will all work with LibreSSL.)
2020-01-05 18:37:52 -08:00
Denis Ovsienko
c9e5ac541b libdnet has bugs, do not use it.
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.)
2019-11-03 23:46:28 +00:00
Guy Harris
1ed63b5d06 Remove more old-compiler compensation.
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.
2019-08-08 23:21:35 -07:00
Denis Ovsienko
40e217a816 Stick with one version of pcap_dump_ftell.c.
It looks like CMake after commit 3e9e2b6 started to use the newly added
missing/pcap_dump_ftell.c to make pcap_dump_ftell() available in tcpdump
if libpcap does not have it. However, autotools continued to use the
previously existing ./pcap_dump_ftell.c for the same purpose. Remove the
previously existing file and amend autotools files to cover
pcap_dump_ftell() the same way as the other functions in the missing/
directory files.

Amend missing/pcap_dump_ftell.c not to use pcap_dump_file(), as it may be
unavailable.

This has been tested to work with libpcap 0.6.1.
2018-07-28 13:36:17 +01:00
Petr Vorel
152acc2ece Display interface and index and name on DLT_LINUX_SLL2
Index is displayed always, name only if available.

Warn about possible wrong interfaces when in reading mode
(pcap file can be displayed on a different host then where
was captured) [1].

See: GH the-tcpdump-group/libpcap#127

[1] https://lists.sandelman.ca/pipermail/tcpdump-workers/2018-July/001019.html

Signed-off-by: Petr Vorel <pvorel@suse.cz>
Suggested-by: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Denis Ovsienko <denis@ovsienko.info>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-07-19 07:15:11 +01:00
Guy Harris
e7011808da Declare the NFLOG pseudo-header ourselves.
It's not specified by a libpcap header that might have a different
layout in different pcap releases, it's specified on the list of
link-layer header types and must remain the same forever (except for
getting additional bits defined), so we don't need to pick it up from
libpcap.

This means we get to use tcpdump's nd_ types; do so.
2018-05-23 14:43:47 -07:00
Guy Harris
e02efb5044 Declare the Bluetooth pseudo-header ourselves.
It's not specified by a libpcap header that might have a different
layout in different pcap releases, it's specified on the list of
link-layer header types and must remain the same forever (except for
getting additional bits defined), so we don't need to pick it up from
libpcap.

This means we get to use tcpdump's nd_ types; do so.
2018-05-23 14:12:45 -07:00
Guy Harris
0c21656150 Configure for ether_ntohost() as libpcap does it for ether_hostton().
Check for the same header files that declare it, and handle the results
of those checks in a similar fashion.
2018-01-22 02:34:31 -08:00
Guy Harris
a7f76515c4 Again, we don't replace vfprintf(). 2018-01-21 18:42:09 -08:00
Guy Harris
45fc519a2a Don't test for __attribute__ in the configure script.
Instead, use compiler test macros to check whether *particular*
attributes are supported, and set various #defines appropriately, in
header files.

Rename the UNALIGNED structure attribute to ND_UNALIGNED, and ask
whether we still need it.
2018-01-21 17:57:20 -08:00
Guy Harris
fe225c5518 Use nd_ types, add host-endian extract routines, clean up signed vs. unsigned.
We now define the structures for Linux USB headers in print-usb.c, so it
doesn't need to include <pcap/usb.h>; don't check for it.
2018-01-11 11:10:21 -08:00
Guy Harris
ebf3f19426 Clean up handling of libdnet headers.
If we don't have dnet_htoa(), we don't need any of the headers.  Check
for them only if we have dnet_htoa().

Use AC_CHECK_DECL to see if netdnet/dnetdb.h declares dnet_htoa().

Check for netdnet/dn.h and, if we have it, check whether it declares
struct dn_naddr; if so, include it, rather than defining the structure
ourselves.

Don't define union etheraddr ourselves; we only need to define an
etheraddr typedef.  That avoids colliding with a libdnet header
definition of union etheraddr.  (When we use etheraddr, we care about
what's on the wire, and we don't rely on system headers to tell us
what's on the wire.)
2017-12-30 14:16:15 -08:00
Guy Harris
6779fd3ba7 Rename configure.in to configure.ac.
This matches what was done with libpcap; it's what autoconf prefers.
2017-11-30 10:20:37 -08:00
Guy Harris
20af93776d Use alarm() iff we're not on Windows.
We assume "not on Windows" means "on UN*X", which means we have alarm()
(we don't care about V6 and earlier; 1978 called, they want their UNIX
back).  If somebody wants to support something that's neither UN*X nor
Windows, they'll need to contribute support, properly checking for that
other OS.
2017-11-12 13:31:57 -08:00
Ali Abdulkadir
260ad4d1bd regenerate 2017-10-24 08:17:52 +03:00
Guy Harris
f151a6d655 Add support for remote capture if libpcap supports it. 2017-10-20 11:27:12 -07:00
Guy Harris
d230f8b687 Get rid of obsolescent configure test.
All UN*Xes, these days, let you include both <time.h> and <sys/time.h>.
2017-10-16 13:48:40 -07:00
Guy Harris
2b9bfa05b6 Check for unaligned memory access support at compile time.
Don't test at configure time; that doesn't work when cross-compiling and
may be a pain to do with CMake.
2017-10-16 01:39:10 -07:00
Guy Harris
fdd0467bcd On UN*X, always use sigaction(), and always have signal handlers return void.
Some time between the mid 1980's and 1990 called; they want their
old-fashioned UNIX signal handling back.  ANSI C has had signal handlers
returning void sincer, well, 1989, and POSIX has had sigaction() since
close to forever.  No need to worry about really old UN*Xes here.

On Windows, it's also void (as per ANSI C); use signal().
2017-10-15 22:36:07 -07:00
Guy Harris
88d1467627 Get rid of an unnecessary test.
We don't care whether struct sockaddr has an sa_len field or not.
2017-10-15 22:16:01 -07:00
Guy Harris
62f2725b57 Use pcap_dump_ftell64() if we have it.
That way, even if a file offset doesn't fit in a long, we can still
handle a -C flag specifying a maximum file size >=2GB.
2017-09-30 01:10:29 -07:00
Guy Harris
14c81f0a4a Clean up the stuff we do to get <inttypes.h> stuff defined.
If we have a libpcap with <pcap/pcap-inttypes.h>, include it, so that we
don't have to worry about definitions colliding if we later include a
pcap header file that includes pcap/pcap-inttypes.h.

Otherwise, do the same stuff pcap-inttypes.h does.  This means that, on
UN*X, we require that there be an <inttypes.h> that defines everything
we need.

Don't bother doing checks that are no longer necessary as a result of
those changes.
2017-09-14 18:53:34 -07:00
Guy Harris
6f0750ee0c Make the ESP decryption not crash with OpenSSL 1.1.
While we're at it, free the cipher context if we fail to allocate the
output buffer for decryption.
2017-09-01 04:00:38 -07:00
Guy Harris
3dc736d939 Handle attributes for function pointers by checking the compiler version.
Handle attributes for function pointers the same way we handle
attributes for functions, by explicitly checking for the compiler
version with #if rather than with a configure script check.  That's one
fewer thing that, if you're not using autoconf, has to be done in some
other fashion.

While we're at it, put NORETURN in the right place to have it work with
Microsoft Visual Studio as well as various UN*X compilers.
2017-08-19 11:25:24 -07:00
Denis Ovsienko
6df678ca31 Check for __attribute__ ((fallthrough)) (GCC 7).
The documentation claims that recent GCC is now better by default at
spotting cases of code flow falling through (which is true) and that it
avoids false positives by matching nearby source code comments with
regexps. However, the latter feature doesn't seem to work as reliably
as the manual describes it, so let's have a macro for this purpose.

Tested to work on:
* x86_64, Fedora 26, GCC 7.1.1 (w/__attribute__, w/fallthrough)
* x86_64, Ubuntu 16.04, GCC 5.4.0 (w/__attribute__, w/o fallthrough)
* x86_64, FreeBSD 11.0, CLang 3.8.0 (w/__attribute__, w/o fallthrough)
* SPARC, Solaris 10, SolStudio 12.4 (w/__attribute__, w/o fallthrough)
* SPARC, Solaris 10, SunStudio 11 (w/o __attribute__)
2017-07-22 19:33:49 +01:00
Guy Harris
1fb50928ce Regenerate config files. 2017-02-02 12:19:28 -08:00
Gleb Smirnoff
cd3c5880b1 Add support for libcasper library available on FreeBSD 11.0 and newer.
The patch allows tcpdump to run sandboxed and still do name resolution.

The code is obtained from FreeBSD tree, where it was developed by

Pawel Jakub Dawidek <pjd@FreeBSD.org>
Mariusz Zaborski <oshogbo@FreeBSD.org>
2017-02-01 16:13:05 -08:00
Guy Harris
b1f305da3d Handle OpenSSL 1.1.x.
In 1.1.x, EVP_CIPHER_CTX is an opaque structure, so we can't declare it
on the stack.

Instead, if we don't have EVP_CIPHER_CTX_new() and EVP_CIPHER_CTX_free()
in libcrypto, define our own versions, with the same signatures as the
ones in OpenSSL 1.1.x's libcrypto, and have the code use
EVP_CIPHER_CTX_new() to allocate the structure and EVP_CIPHER_CTX_free()
to free it.
2016-06-22 21:14:40 -07:00
Guy Harris
817aadf8bb Use the new debugging routines in libpcap.
Newer versions of libpcap, when configured to provide debugging
printouts for the filter expression parser or optimizer, provide
routines to set the "debug the parser" and "debug the optimizer" flags;
use them if the library has them.  If the library doesn't have them, do
our best to try to use the older mechanisms for requesting debugging, if
present.
2015-12-30 18:49:37 -08:00
Francois-Xavier Le Bail
7194047efd Get rid of "TCPDUMP" in some libnetdissect codes 2015-10-08 16:36:23 +02:00
Guy Harris
11f73ad248 Don't require IPv6 library support in order to support IPv6 addresses.
Have our own routines to convert between IPv4/IPv6 addresses and
strings; that helps if, for example, we want to build binary versions of
tcpdump for Windows that can run both on NT 5 (W2K/WXP), which doesn't
have inet_ntop() or inet_pton(), and NT 6 (Vista/7/8/10), which do.  It
also means that we don't require IPv6 library support on UN*X to print
addresses (if somebody wants to build tcpdump for older UN*Xes lacking
IPv6 support in the system library or in add-on libraries).

Get rid of files in the missing directory that we don't need, and
various no-longer-necessary autoconf tests.
2015-09-17 14:56:44 -07:00
Guy Harris
3dd9240cc3 Do case-insensitive comparisons assuming ASCII strings.
Do the case-insensitive comparisons in a locale-independent fashion that
only maps ASCII letters, in the standard English-language fashion; that
way, we don't get bitten by, for example, Turkish having separate "i
with dot" and "i without dot" letters, with lower-case "i with dot" being
mapped to upper-case "I with dot" rather than being mapped to "I".
2015-06-11 15:47:44 -07:00
Guy Harris
032642d666 Don't assume you have <net/if_pflog.h> if you have <net/pfvar.h>.
Debian/kFreeBSD ships <net/pfvar.h> but not <net/if_pflog.h>.
2015-05-17 10:47:30 -07:00
Guy Harris
09b639add1 C compilers can, and some do, optimize away pointer underflow checks.
Cast the pointers to uintptr_t; use AC_TYPE_UINTPTR_T to get uintptr_t
defined on older platforms that don't define it themselves.
2015-03-02 13:25:12 -08:00
Francois-Xavier Le Bail
2d4f737c35 configure: add support for cap-ng package
It uses '--with-cap-ng', for using libcap-ng [default=yes, if available]
2015-02-15 15:32:23 +01:00
Guy Harris
d71793791f Use immediate mode if available.
If libpcap has pcap_set_immediate_mode(), then default to immediate mode
if we're printing packets to a terminal, and use immediate mode if
--immediate-mode is specified.
2015-02-10 14:55:43 -08:00
Guy Harris
56e2d8cc37 Regenerate configure script. 2014-12-19 13:38:54 -08:00
Guy Harris
37a4aa82a9 Clean up configure check for libsmi.
First, check for smi.h.  If we don't have it, don't check for anything
else.

If we do have it, check for libsmi containing smiInit.  If we don't have
it, don't check for anything else.

If we do have it, check, with our test program, whether we can use it.

If that succeeds, prepend -lsmi to LIBS, and set USE_LIBSMI.  Otherwise,
don't do either of those.

Check, in source, *only* for USE_LIBSMI.  If it's set, use libsmi,
otherwise don't - don't even include smi.h, even if we happened to have
found it, and don't print the libsmi version string.
2014-08-31 11:57:04 -07:00
Loganaden Velvindron
c8275aaf91 Add support for FreeBSD capsicum sandboxing. 2014-07-10 12:19:39 -07:00
Guy Harris
a509c52d31 Allow builds if libpcap doesn't have pcap_set_tstamp_precision().
Check for pcap_set_tstamp_precision() in the configure script and, if
it's not there, don't include the code that allows time stamp precisions
to be set.
2014-06-25 12:06:35 -07:00
Guy Harris
125e5bc5ca Check for pcap_free_datalinks().
Fixes GitHub issue #390.

Also, if all we do when checking for a function is set a HAVE_XXX
AC_CHECK_FUNC, as AC_CHECK_FUNCS will set the #define for you.
2014-05-19 10:56:52 -07:00
Guy Harris
6b9e3a5a85 Use getopt_long().
This requires us to check for it in the configure script and to include
a version of getopt_long() for the benefit of platforms that don't have
it; we pick up the FreeBSD version and tweak it a bit (eliminating some
features specific to the BSD version of getopt_long(), as we want to use
it only in a fashion portable to Linux/*BSD/Solaris/etc.)

We also get rid of the version of getopt() we supply for Windows in
favor of the version of getopt_long() we provide.
2014-04-30 15:28:06 -07:00
Guy Harris
30f0d2314d We still need u_intN_t.
Some libpcap headers use them, and even if we change libpcap to use
uintN_t, we don't require that tcpdump 4.x go with libpcap 1.x - we
allow people to install the latest tcpdump even if they have an older
libpcap and don't want to install a newer one.

However, we now define them in terms of the C99 uintN_t types, rather
than trying to guess what's appropriate; using unsigned long long for
u_int64_t meant that, on some platforms, u_int64_t didn't match
PRI[doux]64, and using unsigned long obviously won't work on ILP32
platforms.

Also, we already had calls to the autoconf macros for C99 types; get rid
of the ones we added.

Also also, clean up a comment in tcpdump-stdinc.h.
2014-04-23 10:56:20 -07:00
Guy Harris
ed85e20e4d u_intN_t is dead, long live uintN_t.
And, as we require at least autoconf 2.61, and as autoconf 2.61 and
later have AC_TYPE_UINTn_T and AC_TYPE_INTn_T macros, we use them to
define the uintN_t and intN_t macros if the system doesn't define them
for us.

This lets us get rid of bitypes.h as well.
2014-04-23 00:20:40 -07:00
Guy Harris
b485483022 Use the new libpcap <pcap/nflog.h> for NFLOG definitions and declarations.
Use the header file for information about LINKTYPE_NFLOG files.

Don't build the NFLOG printer if we don't have that header file.

Fix some checks for pcap/XXX.h header files to look for
"tcpdump-stdinc.h" rather than <tcpdump-stdinc.h>, so that we don't fail
to find that header.
2014-02-02 20:14:26 -08:00
Guy Harris
5cb460bef8 We're not using struct sockaddr_storage any more, so don't check for it. 2014-01-17 12:49:49 -08:00
Guy Harris
e462b975e2 Clean up handling of -g and -O flags.
AC_PROG_CC adds -g and -O2 to CFLAGS if you're using GCC; don't bother
adding either of them, or -O, ourselves if we're using GCC.

Add -O for all non-GCC compilers.
2013-10-17 16:50:43 -07:00
Guy Harris
a6c16ed8ab Fix build issues with the OpenFlow printer on some systems.
Don't assume we have <stdint.h>.  Instead, use the AC_TYPE_ macros to
ensure we have the C99 intN_t and uintN_t types; we already include
<inttypes.h> in tcpdump-stdinc.h iff we have it.

Get rid of the structure declarations in openflow-1.0.h, as they have
zero-length arrays (not supported by all the compilers people might be
using) and as

	1) they're only used in sizeof()

and

	2) after each one there's an assertion to check that sizeof()
returns a specific numerical value

so, instead, just #define various _LEN items to those numerical values
and use them.

Add an openflow.h header with a #define for the length of the basic
header, and move the declaration of of10_header_body_print() there.
2013-06-23 14:03:38 -07:00
Guy Harris
94bf5a24bf Avoid some warnings from Sun C.
Some versions of Sun C support __attribute__ but don't support the
"unused" or "format" attributes - they don't fail, but they whine a lot.
They also support the "noreturn" attribute, but don't allow it to be
applied to function pointers, only to functions.

Check whether they can be used without warnings, and use them only if
they can.
2013-06-22 14:06:33 -07:00
Guy Harris
a332503d7d Get rid of acconfig.h. 2013-05-12 15:28:28 -07:00