Commit Graph

105 Commits

Author SHA1 Message Date
Guy Harris
a08e63fd7a Move NTOH and HTON macros into addrname.c
We don't want to encourage people to use them in code that pulls data
out of packets, as we want that code to use the EXTRACT_ macros.
2017-12-16 19:52:35 -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
Guy Harris
7068209574 Use nd_ types in 802.x and FDDI headers.
Use EXTRACT_U_1() as required by those changes.  Remove
no-longer-necessary & operators from other EXTRACT_ calls.

While we're at it, add MAC_ADDR_LEN to netdissect.h, and use it instead
of ETHER_ADDR_LEN; eliminate ETHER_ADDR_LEN.

Move the maximum Ethernet length field value to ethertype.h, under the
name MAX_ETHERNET_LENGTH_VAL.

Move the Ethernet header structure, and the #define for the Ethernet
header length, to print-ether.c; in non-Ethernet dissectors that were
using the Ethernet header structure, just declare two nd_mac_addr
variables for the source and destination MAC addresses and use them
instead of the Ethernet header (we don't need the type field there).

These changes leave nothing in ether.h, so eliminate it.
2017-12-12 10:36:21 -08: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
a7fc606fd5 Remove the protoid_string() unused function 2017-11-21 08:21:40 +01:00
Francois-Xavier Le Bail
577621026d Rename EXTRACT_nBITS() macros to EXTRACT_BE_nBITS()
It indicates clearly that these macros are used to extract big-endian
integral values.
2017-11-18 13:56:40 +01:00
Ali Abdulkadir
18568bc044 Made up for missing getservent() and endservent() 2017-10-24 08:11:33 +03: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
b09a65ece6 This is an array of 16 character values, not a C character string.
Don't initialize it with a string, so no compiler whinges about there
being no room for a null terminator.
2017-09-14 11:59:38 -07:00
Guy Harris
b1928b44a5 That array only needs 16 elements.
No need for a 17th null terminator.

This might, or might not, give Coverity a clue that

	u_char *p;

	hex[*p >> 4]
	hex[*p & 0xf]

are both safe, no matter how "tainted" p is, because if you shift an
8-bit unsigned value right 4 bits, the result is between 0 and 15.  (See
CID 1206732.)
2017-09-13 12:25:44 +01:00
Guy Harris
777edc563a Further fix the fix to CVE-2017-5485.
1) Take the length of the NSAP into account.  Otherwise, if, in our
search of the hash table, we come across a byte string that's shorter
than the string we're looking for, we'll search past the end of the
string in the hash table.

2) The first byte of the byte string in the table is the length of the
NSAP, with the byte *after* that being the first byte of the NSAP, but
the first byte of the byte string passed into lookup_nsap() is the first
byte of the NSAP, with the length passed in as a separate argument.  Do
the comparison correctly.

This fixes a vulnerability discovered by Kamil Frankowicz.

Add a test using the capture file supplied by the reporter(s).

While we're at it, clean up the fix to lookup_bytestring():

1) Get rid of an unused structure member and an unused #define.

2) Get rid of an incorrect "+ 1" when calculating the size of the byte
array to allocate - that was left over from the NSAP table, where the
length was guaranteed to fit in 1 byte and we used the first byte of the
array to hold the length of the rest of the array.
2017-09-13 12:25:44 +01:00
Guy Harris
730fc35968 CVE-2017-12894/In lookup_bytestring(), take the length of the byte string into account.
Otherwise, if, in our search of the hash table, we come across a byte
string that's shorter than the string we're looking for, we'll search
past the end of the string in the hash table.

This fixes a buffer over-read discovered by Forcepoint's security
researchers Otto Airamo & Antti Levomäki.

Add a test using the capture file supplied by the reporter(s).
2017-09-13 12:25:44 +01:00
Guy Harris
b8c56aa092 Merge pull request #588 from glebius/casper
Add support for libcasper library available on FreeBSD 11.0 and newer.
2017-02-02 12:18:56 -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
2817174698 CVE-2017-5485/Fix lookup_nsap() to match what isonsap_string() expects.
Change cddcb5632d changed isonsap_string()
to take, as arguments, a pointer to the first octet of an NSAP and the
length of the NSAP, rather than a pointer to a string of octets the
first octet of which is the NSAP length and the subsequent octets are
the octets of the NSAP.

However, lookup_nsap() was not changed in a similar fashion, and
isonsap_string() handed it a pointer to the first octet of the NSAP,
which lookup_nsap() treated as the NSAP length.

This should fix GitHub issue #563.
2017-01-18 09:16:42 +01:00
Francois-Xavier Le Bail
12857bf113 Improve code readability: A pointer should not be compared to zero
Using Coccinelle script badzero.cocci
2016-08-25 09:48:49 +02:00
Guy Harris
e64b287afd Keep our own Ethertype-to-name map.
Don't use a hack to get the table from libpcap; have our own table.
That cleans up the hack, and lets us add stuff to our table without
having to worry about libpcap.
2015-11-03 19:06:41 -08: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
Francois-Xavier Le Bail
f5fe14663d libnetdissect code must include 'netdissect.h', not 'interface.h'
Moreover:
Remove netdissect.h include in interface.h
Move thiszone declaration in netdissect.h
Update a comment
2015-09-11 13:22:56 +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
e847135d66 Functions in libnetdissect must use ndo_error() function 2015-09-05 22:52:11 +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
Bill Parker
e6857f421d Add checks for strdup() failure. 2015-07-13 12:55:29 -07:00
Guy Harris
1c8a77f92b We're not doing setjmp/longjmp, so no need for static variables.
We stopped doing setjmp/longjmp a while ago (it could cause issues on
multiple platforms), so we don't need to make pointer variables static
in the lookup routines.
2015-07-13 12:50:01 -07:00
Guy Harris
dccbbf9a09 Don't cast away warnings for ether_ntohost().
We have a choice between "your OS's header files suck" warnings on HP-UX
and -Wcast-qual warnings on all platforms.  I vote for the former, as
the latter let us find cases where we're casting constness away, and we
really don't want to cast constness away if we can possibly avoid it.
2015-04-26 18:42:23 -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
Guy Harris
4405f13804 Get rid of support for non-NDOified printers.
Remove the TTEST{2}/TCHECK{2} macros.  Rename all "ndo_printer" routines,
structures, and structure members to just "printer", and get rid of the
old routines/structures/structure members with those names.
2015-03-10 13:25:52 -07:00
Denis Ovsienko
1d66439981 refine 802.1Q VLAN TCI decoding
Factor the common code out to a new function and rename the CFI bit to
DEI to match the terminology in Clause 9.6 of IEEE 802.1Q-2011.
2015-01-29 20:38:54 +00:00
Guy Harris
e5b3ec43d3 Clean up bounds checking.
Fix link-layer header length for Cisco-style encapsulation while we're
at it.
2014-12-19 12:13:15 -08:00
Gisle Vanem
31b448f219 Use proper declaration
'eproto_db' is in libpcap. Thus use a proper 'extern __declspec(dllimport)' declaration.
2014-05-02 06:36:14 -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
32938f947f Define NETDISSECT_REWORKED and fix the issues it provokes.
I.e., use the flags from the netdissect_options structure.
2014-04-04 00:46:33 -07:00
Guy Harris
1cde6435df Netdissectify the to-name resolution routines.
Have them take a netdissect_options * argument, and get the "no name
resolution" flag from it.

Move the declaration of dnaddr_string to addrtoname.h, along with the
other XXX-to-string routines.
2014-04-04 00:43:46 -07:00
Denis Ovsienko
fe3253b9b8 remove tcpdump's own CVS keywords
Remove lots of $Header's and a few $Id's that all belong to the former
CVS repository of tcpdump itself. These keywords have been frozen since
the migration to git in late 2008.
2014-01-03 00:59:08 +04:00
Dmitrij Tejblum
5aa3566172 Fix a strict-aliasing GCC warning in getname6(), as the GCC manual suggests. 2013-06-16 15:37:44 +04:00
Bill Parker
f6d19bd32a Sanity Checking added to addrtoname
Added return value checking for tp->e_bs against NULL to see if memory
was actually allocated :)

Conflicts:
	addrtoname.c
2012-09-04 20:45:02 -04:00
Bill Parker
16e5625664 In reviewing addrtoname.c, I found a minor issue with a call to
malloc() failing to check it's return value in file 'addrtoname.c' in
function 'LookupBytestring'.  Here is the resulting patch below :)
2012-09-03 17:23:14 -04:00
Guy Harris
2886b89df6 Back out DLT_PFSYNC support.
Unfortunately, the DLT_PFSYNC support depends on header files included
from the pfctl command's source tree, and trying to arrange to find that
would be too much trouble.
2012-02-29 21:14:50 -08:00
Guy Harris
0d2d222ffb Add DLT_PFSYNC support.
From FreeBSD PR bin/124825: tcpdump(8) does not support pfsync(4) data,
which in turn was ported over from OpenBSD.  We already have CARP
support, so we did not port that part over.
2012-02-29 01:51:27 -08:00
Michael Richardson
3c4027f599 Merge commit 'lumag/master' 2010-05-13 13:52:46 -04:00
Guy Harris
48ea21554b Don't blow up if a zero-length link-layer address is passed to linkaddr_string().
Clean up style a bit while we're at it.
2010-03-25 11:21:49 -07:00
Dmitry Eremin-Solenikov
4e25f49680 addrtoname.[ch]: add a printer for Little-Endian 64-bit address
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
2010-03-09 18:12:39 +03:00
Kovarththanan Rajaratnam
2086d80fa0 af.h/c: make several structs const 2010-02-20 07:45:39 +01:00
Kovarththanan Rajaratnam
6457f82aaa addrtoname.c: make several structs static 2010-02-20 07:45:21 +01:00
Kovarththanan Rajaratnam
ec7a5640cf addrtoname.c: constify several structs 2010-02-20 07:32:39 +01:00
hannes
c15c709252 expose the BUFSIZE def to the outside world 2007-08-08 14:06:34 +00:00
guy
a7c96d7bcb "ether.h" defines more than we need, and, on some platforms, redefines
ether_header (which is one of the things we don't need).  Just define
ETHER_ADDR_LEN to 6 if it's not defined - it can't be anything but 6.
2006-05-12 02:14:55 +00:00
hannes
0918822457 from Gisle Vanem:
- use local Ethernet defs on WIN32
2006-02-27 07:17:34 +00:00
hannes
aebfcfe1f6 rework the ARP printer & add support for Frame-Relay ARP 2006-02-11 22:11:40 +00:00