Commit Graph

72 Commits

Author SHA1 Message Date
Francois-Xavier Le Bail
42b25d9bb5 DECnet: Use %zu to print sizeof values 2020-11-03 12:06:05 +01:00
Denis Ovsienko
47d80a1f1b Use nd_mac_addr where it belongs. [skip ci] 2020-10-17 20:44:27 +01:00
Denis Ovsienko
9169e4e194 Include <string.h> only if required. 2020-10-17 17:55:37 +01:00
Denis Ovsienko
c9638df58e DECnet: Modernize packet parsing style.
Enable ND_LONGJMP_FROM_TCHECK. Remove a number of redundant
ND_TCHECK_SIZE() instances. Add and use standard invalid sections, in a
few cases print the reason for declaring the packet invalid. Make a few
functions void. Lose an unused structure. Update a test case.
2020-10-16 21:10:50 +01:00
Denis Ovsienko
3059f35812 Use __func__ from C99 in error messages. [skip ci]
This automatically fixes a few error messages that would tell an
incorrect function name.
2020-10-08 14:34:25 +01:00
Denis Ovsienko
ea0d29f743 Spell most remaining MAC_ADDR_LEN instances. [skip ci] 2020-10-04 13:36:48 +01:00
Francois-Xavier Le Bail
5595d2cbfd Remove 3 now redundant ND_TCHECK_LEN(e, sizeof(short)) calls
They are redundant because they are identical to ND_TCHECK_2(e), followed
by a GET_BE_U_2(e) or a GET_LE_U_2(e), same e, which do the bounds check.
2020-09-30 10:29:43 +02:00
Francois-Xavier Le Bail
6288c273b6 Remove useless 'return' at end of void functions (style) 2020-09-28 17:04:08 +02:00
Francois-Xavier Le Bail
abc8c2d61c Remove many (762) now redundant ND_TCHECK_n() calls
ND_TCHECK_n(e), n in { 1, 2, 3, 4, 8 }.

They are redundant because they are followed by a GET_.*_n(e) call,
same n, same e, which do the bounds check.

Remove unused 'trunc' labels and most associated codes.

Update the outputs of some tests accordingly.
2020-09-06 20:22:29 +02:00
Denis Ovsienko
5c2027db88 Rename min() and max() to ND_MIN() and ND_MAX(). [skip ci]
As discussed on tcpdump-workers, it was a place for a potential clash
with non-macros.
2020-08-24 21:53:58 +01: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
Guy Harris
dc9744f7c6 Squelch more warnings. 2019-04-17 20:21:53 -07:00
Guy Harris
bef667db65 Clean up types to squelch narrowing warnings. 2019-04-17 19:53:00 -07:00
Francois-Xavier Le Bail
ee68aa3646 Use the new GET_ macros instead of the EXTRACT_ ones
The exceptions are currently:
Some EXTRACT_ in print-juniper.c, not used on packet buffer pointer.
An EXTRACT_BE_U_3 in addrtoname.c, not always used on packet buffer
pointer.
2019-03-26 21:06:24 +01:00
Francois-Xavier Le Bail
2b59fefb18 DECnet: Avoid using EXTRACT_ macros on non packet buffer pointers
Remove two now useless variables.
2018-05-22 13:49:07 +02:00
Francois-Xavier Le Bail
366dafcf78 DECnet: Pointers to packet bytes should be u_char *, not char * 2018-05-19 21:00:02 +02:00
Francois-Xavier Le Bail
ba8936b39b Print truncations with nd_print_trunc() instead of tstr[] strings
Remove the tstr[] strings.
Update the output of some tests accordingly.

Moreover:
Add or update some ndo_protocol fields.
2018-05-04 13:47:49 +02:00
Francois-Xavier Le Bail
546558eabd Add the ndo_protocol field in the netdissect_options structure
Update this field in printer entry functions.
It will be used for some printings.
2018-03-16 19:44:47 +01:00
Francois-Xavier Le Bail
5ae22f41a8 Add a status exit code to the function ndo_error()
The status are defined in an enum in status-exit-codes.h.

Moreover:
Use ndo_error() instead of ndo_warning() for malloc() errors in print-esp.c.
2018-02-25 20:58:27 +01:00
Francois-Xavier Le Bail
7164cd52c5 Add comments on some memory allocations we cannot free 2018-02-23 21:25:39 +01:00
Guy Harris
c499612a7f Add nd_{v}snprintf() routines/wrappers.
Some versions of the MSVC runtime library have a non-C99-compliant
vsnprintf(), which we want to avoid.  On Windows, use snprintf() and
vsnprintf() for VS 2015 and later, where they both exist in
C99-compliant forms, and wrap _{v}snprintf_s() otherwise (they're
guaranteed to do the null termination that we want).
2018-01-29 15:48:55 -08:00
Francois-Xavier Le Bail
56a03b851a Remove unused incomplete structure declarations 2018-01-24 22:47:40 +01:00
Francois-Xavier Le Bail
8bbad56e37 DECnet: Replace ND_TCHECK call(s) by ND_TCHECK_SIZE call(s) 2018-01-23 20:42:50 +01:00
Francois-Xavier Le Bail
d22cb958d7 DECnet: Use more ND_TCHECK_n() macros 2018-01-23 19:44:21 +01:00
Guy Harris
fb2479d733 Always include <config.h> rather than "config.h".
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.
2018-01-21 12:27:28 -08:00
Francois-Xavier Le Bail
513f782ae1 Use quoted include netdissect-stdinc.h instead of angle-bracketed one 2018-01-21 10:28:15 +01:00
Francois-Xavier Le Bail
e2982e7f6f Update ND_PRINT() as a variadic macro 2018-01-07 13:36:41 +01:00
Francois-Xavier Le Bail
d526e47658 Use ND_TTEST_SIZE()/ND_TCHECK_SIZE() macros (1/n) 2018-01-03 21:32:07 +01: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
2f7e7d424e Don't use nd_ types in struct dn_naddr.
It's a type used by libdnet; it's not a packet structure.
2017-12-29 21:18:18 -08:00
Guy Harris
d7cd950f1f Use nd_ types, add EXTRACT_ calls, clean up signed vs. unsigned. 2017-12-29 20:42:10 -08:00
Guy Harris
b347189ca6 Add EXTRACT_ macros/functions for IPv4 addresses, get rid of structure wrappers.
Add EXTRACT_IPV4_TO_HOST_ORDER() and EXTRACT_IPV4_TO_NETWORK_ORDER();
the former extracts a possibly-unaligned IPv4 address, in network byte
order, returning a uint32_t in host byte order, and the latter extracts
a possibly-unaligned IPv4 address, in network byte order, returning a
uint32_t in *network* byte order.  Some APIs take an address in network
byte order, and some operations are more easily done in host byte order,
so both are useful.

Remove the structure wrappers around nd_ipv4 and nd_ipv6; that makes it
easier to pass variables of those types to functions/macros that take a
byte pointer as an argument (because they might be used either with
pointers to structure members or raw buffer pointers), and the structure
probably wouldn't do much to prevent people from using EXTRACT_BE_U_4()
when they really want to extract the value in *network* byte order;
using the above EXTRACT_IPV4_ calls should do more to encourage that.
2017-12-20 01:07:48 -08:00
Francois-Xavier Le Bail
5cea270318 Remove all storage class specifier 'register'
Let the compiler do the optimizations (or not) based on build options.

Avoid 'value has been optimized out' messages in gdb using '-O0'.
2017-12-13 19:17:47 +01:00
Francois-Xavier Le Bail
84ef17ac0e Replace ND_TTEST2()/ND_TCHECK2() macros by macros using pointers (1/n)
ND_TTEST2(var, l)  -> ND_TTEST_LEN(p, l)
ND_TCHECK2(var, l) -> ND_TCHECK_LEN(p, l)
2017-12-11 22:11:01 +01:00
Francois-Xavier Le Bail
e44bc94ad0 Use pointer expressions like in most similar cases 2017-12-10 15:17:06 +01:00
Francois-Xavier Le Bail
da20bc56d6 Rename EXTRACT_ macros
Now all the macros have a name meaning a count in bytes.

With _S_: signed, _U_: unsigned

e.g.:
EXTRACT_BE_32BITS -> EXTRACT_BE_U_4
EXTRACT_LE_32BITS -> EXTRACT_LE_U_4
...
EXTRACT_BE_INT32 -> EXTRACT_BE_S_4

and have:
EXTRACT_8BITS -> EXTRACT_U_1
EXTRACT_INT8  -> EXTRACT_S_1
2017-11-22 23:54:09 +01:00
Francois-Xavier Le Bail
5287bffd3f Remove EXTRACT_LE_8BITS() macro, use EXTRACT_8BITS() macro
This indicates that it's not specifically big-endian or little-endian.
2017-11-18 15:00:31 +01:00
Guy Harris
c6e0531b5d CVE-2017-12899/DECnet: Fix bounds checking.
If we're skipping over padding before the *real* flags, check whether
the real flags are in the captured data before fetching it.  This fixes
a buffer over-read discovered by Kamil Frankowicz.

Note one place where we don't need to do bounds checking as it's already
been done.

Add a test using the capture file supplied by the reporter(s).
2017-09-13 12:25:44 +01:00
Denis Ovsienko
c767d995cd make minor cleanups to print-decnet.c
Remove some unused code guarded by PRINT_NSPDATA, which was never
defined.

To resolve a Coverity dead code warning remove the notions of
COS_CRYPTSER as DECnet packet diagrams are pretty much non-existent in
the modern Internet so I could not figure it out what the code point was
meant to do originally.

dead_error_condition: The switch value "services & 0xc" cannot be 16
2016-10-07 22:19:36 +01:00
Francois-Xavier Le Bail
11d3a01319 Move the printer summaries from INSTALL.txt to each printer
with the tag '\summary:' for greping.
Remark: Currently some printers have no summary line.

Moreover:
Summarize all printers with a single line in INSTALL.txt
2016-08-14 17:03:43 +02:00
Francois-Xavier Le Bail
99c91c3aec Rename 'tcpdump-stdinc.h' to 'netdissect-stdinc.h'
Get the full log via: git log --follow netdissect-stdinc.h
2015-09-10 08:50:40 +02:00
Francois-Xavier Le Bail
c1c3c77463 Printers must include 'netdissect.h', not 'interface.h' 2015-09-05 23:35:58 +02:00
Francois-Xavier Le Bail
71d0745d3d Printers must use ndo_error() function (via ndo->ndo_error) 2015-09-05 20:20:57 +02:00
Guy Harris
f79d3e15d1 The official #define for 32-bit and 64-bit Windows is _WIN32.
It's _WIN32, with a leading underscore, not WIN32.  See, for example:

	https://sourceforge.net/p/predef/wiki/OperatingSystems/

and

	https://msdn.microsoft.com/en-us/library/b0084kay.aspx

*Some* environments may also define WIN32, but we shouldn't depend on
that.
2015-08-31 14:43:15 -07:00
Guy Harris
69cb46af91 Fix a bunch of de-constifications. 2015-04-26 17:24:42 -07:00
Denis Ovsienko
38700c7f24 dismiss NETDISSECT_REWORKED macro
The purpose of this macro was to enable the file-by-file switch to NDO,
after which only tcpdump.c had a use of it and the definitions guarded
by it. Update tcpdump.c not to require them any more and dismiss the
unused definitions.
2015-03-22 10:06:15 +00:00
Francois-Xavier Le Bail
e31a39e939 DECNET: Fix segmentation fault
If the 'dnet_htoa' function return NULL, '(strdup(dnet_htoa(&dna)))'
gives a segmentation fault.

Context:
- libdnet-dev installed (Thus HAVE_DNET_HTOA defined)
- Missing /etc/decnet.conf
2015-02-16 20:42:46 +01:00
Francois-Xavier Le Bail
563a00f8e8 Delete useless Control-L chars 2014-11-14 21:35:54 +01: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