Commit Graph

35 Commits

Author SHA1 Message Date
Guy Harris
b314392dfe Include pcap-missing.h, to get the declaration of pcap_datalink_val_to_name().
If we're building with an old version of libpcap that doesn't include
pcap_datalink_val_to_name(), we incorporate our own version, but we need
to have it declared before we use it.
2018-07-29 15:08:16 -07:00
Guy Harris
51c1da63e4 DLT_LINUX_SLL2 support. 2018-07-12 11:49:38 -07:00
Guy Harris
66384fa15b We no longer need pcap/nflog.h nor pcap/bluetooth.h. 2018-05-24 14:13:22 -07:00
Francois-Xavier Le Bail
56e6581c34 Remove useless comments 2018-03-19 15:16:32 +01:00
Francois-Xavier Le Bail
a53605c61b Add a malloc/free process with garbage collector
Use it in the PPP printer.
2018-03-14 13:59:26 +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
f253e11009 Add a sanity check on packet header length
The packet length must be <= MAXIMUM_SNAPLEN.

Currently, there is no D-Bus printer, thus no need for a bigger length.

Now a pachet is valid if:
capture length != 0,
packet length != 0,
capture length <= MAXIMUM_SNAPLEN,
packet length <= MAXIMUM_SNAPLEN,
packet length >= capture length.

Moreover:
Fix the packet header lengths of some fuzzed pcap files:
If the lengths are > MAXIMUM_SNAPLEN, set them to MAXIMUM_SNAPLEN.
Thus they will be always usable with this new sanity check.
2018-02-07 18:48:49 +01:00
Francois-Xavier Le Bail
8d814082b7 Add a sanity check on packet header capture length
The capture length must be <= MAXIMUM_SNAPLEN.

Now a pachet is valid if:
packet length != 0,
capture length != 0,
capture length <= MAXIMUM_SNAPLEN,
packet length >= capture length.

Moreover:
Fix spaces, indentation.
2018-02-01 18:58:02 +01:00
Francois-Xavier Le Bail
bdeb75099d Add a comment about packet and capture lengths 2018-01-25 15:29:02 +01:00
Francois-Xavier Le Bail
a8c1b2a339 No more need for ndo_invalid_header in struct netdissect_options
Because we now stop decoding packet when header length(s) is/are invalid,
there is no more need to keep the invalid header flag out of
pretty_print_packet function.
2018-01-25 15:12:24 +01:00
Francois-Xavier Le Bail
c1ce37fff3 Don't decode the packet when header length(s) is/are invalid 2018-01-25 11:23:24 +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
9e6ba479d8 Add sanity checks on packet header (packet length / capture length)
For a valid packet:
packet length != 0,
capture length != 0,
packet length >= capture length.

Update the output of some tests accordingly.
2018-01-16 08:32:52 +01: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
Francois-Xavier Le Bail
e2982e7f6f Update ND_PRINT() as a variadic macro 2018-01-07 13:36:41 +01:00
Francois-Xavier Le Bail
51d034f45b Rename some link-layer dissector entry functions
Most of them are already named *_if_print.
Update the others to have the same prefix.

This change allow easier identification.
2017-11-16 07:22:41 +01: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
Guy Harris
141c1c6f49 Suppress UBSan warnings from EXTRACT_.
Yes, the behavior of an access with an improperly-aligned pointer is
undefined according to the C standard, but if we're doing that in an
EXTRACT_ function/macro, we're doing it because we know it's safe and
because it's faster than picking the bytes out one by one and assembling
them, so suppress those warnings.

Pull over libpcap's funcattrs.h and use it to do a bunch of checks for
various function attributes; that defines __has_attribute(), so we can
use it to check for the "suppress sanitizer warnings" attribute.

While we're at it, use other things it defines to specify "this function
never returns", "this function is printf-like", and "this function
argument is a printf-style format argument", rather than using various
configure-script checks.  That should let us declare some function
attributes with Microsoft Visual Studio's compilers.
2017-08-18 20:11:43 -07:00
Guy Harris
6311dc0b6e Printers MUST (not MAY or even SHOULD) check bounds. 2017-02-17 13:51:51 -08:00
Francois-Xavier Le Bail
77e7df3569 Fix NDOization
putchar() -> ND_PRINT(());
2016-10-21 21:27:53 +02:00
Francois-Xavier Le Bail
392cc92bcf Remove _U_ when parameter is used 2016-08-18 09:41:01 +02:00
Guy Harris
91e08f888d Move some code around.
Move stuff to initialize and clean up libraries that are used by
netdissect code into nd_init() and nd_cleanup() routines in
libnetdissect; this includes Winsock (which is used on Windows by, for
example, the code to get names for IP addresses) and libsmi.

Call nd_init() when tcpdump starts up, and call nd_cleanup() when it
exits.

Move util.c routines to tcpdump.c, and make them static.

Use ndo->ndo_error to report a failure to open a file in print-esp.c.
2016-08-04 13:19:57 -07:00
Francois-Xavier Le Bail
a1dadfb1bc Fix the error handling in 'ndo_printf' function
Moreover:
Replace strerror() calls with pcap_strerror() calls, in case some platform
lacks strerror().
2015-10-12 22:30:31 +02:00
Guy Harris
77453f5355 Eliminate some remaining uses of u_int32_t. 2015-09-18 15:11:43 -07:00
Francois-Xavier Le Bail
f0ff49cc4d Move if_printer to structure netdissect_options
The structure 'netdissect_options' can hold if_printer.
Thus the structure 'print_info' is useless now.

Moreover:
Delete useless blank lines
Fix indent
2015-09-14 15:54:54 +02: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
Guy Harris
9e90deb655 "tcpdump" should not be used in any libnetdissect code.
Libnetdissect could be used by programs not named "tcpdump".  Rename
"tcpdump_printf()" to "ndo_printf()".
2015-09-08 00:53:38 -07:00
Francois-Xavier Le Bail
0845bc813c Add program_name field in the netdissect_options structure
A program that use the library should set it. Done for tcpdump.
ndo_error() and ndo_warning() print now 'ndo->program_name'.

Moreover:
Fix indent
2015-09-07 19:13:42 +02:00
Francois-Xavier Le Bail
e847135d66 Functions in libnetdissect must use ndo_error() function 2015-09-05 22:52:11 +02:00
Guy Harris
0b1de8f73d Merge pull request #455 from brooksdavis/gndo-cleanup
Remove global netdissect_object and remove non-dissection related fields
2015-05-20 16:56:06 -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
Brooks Davis
dcfd7c43ad Pass an ndo to the print API rather than using gndo.
Since gndo is only referenced in main() move it there.
2015-04-27 00:10:23 +00:00
Brooks Davis
115a063589 Disentangle packet dissection functionally in tcpdump from the internal
libnetdissect.  This greatly narrows the public interface and allows
libnetdissect to be more easily sandboxed.
2015-04-15 18:52:33 +00:00