Commit Graph

50 Commits

Author SHA1 Message Date
Denis Ovsienko
032d569e68 Spell "indent" where it belongs. 2021-03-28 13:44:35 +01:00
Francois-Xavier Le Bail
5ee4e508de ASCII/hex: Use nd_trunc_longjmp() in truncation cases
In functions ascii_print(), hex_and_ascii_print_with_offset() and
hex_print_with_offset().
Therefore indirectly for the functions hex_and_ascii_print(), hex_print()
and ndo_default_print().

Even if hex_and_ascii_print(), hex_print() and ascii_print() are used in
print.c after the setjmp() block with the calls:

1) hex_and_ascii_print(ndo, "\n\t", sp, h->caplen);
2) hex_and_ascii_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
3) hex_print(ndo, "\n\t", sp, h->caplen);
4) hex_print(ndo, "\n\t", sp + hdrlen, h->caplen - hdrlen);
5) ascii_print(ndo, sp, h->caplen);
6) ascii_print(ndo, sp + hdrlen, h->caplen - hdrlen);

sp and h->caplen are unmodified, ndo->ndo_snapend was restored.

1), 3) and 5) the length to print is caplen => no truncation can occur.
2), 4) and 6) the length to print is (caplen - hdrlen) after a shift of
hdrlen => no truncation can occur.

Moreover:
Update the output of three tests accordingly.
Remove an useless comment.
Fix indentation.
2021-03-27 20:54:29 +01:00
Denis Ovsienko
a8bba6ff8e Lose a forward declaration in print-ascii.c. [skip ci] 2020-09-13 22:53:50 +01:00
Guy Harris
9a6a650241 Don't use <ctype.h> macros.
Some of them are locale-dependent, and all of them run the risk of
failing if you hand them a char with the 8th bit set.

Move our replacements to a new netdissect-ctype.h file, and, for the
ones that check for particular character types, add _ASCII to the name,
to indicate that only ASCII characters pass the check.  Do the same for
the ones that map between cases, to indicate that they only map ASCII
letters.

For isspace(), explicitly check for the characters we care about, to
make it clearer what we're doing.
2019-09-01 16:11:32 -07: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
07a7f33ba3 Fix some narrowing warnings on LP64/LLP64 platforms.
Add a ND_BYTES_AVAILABLE_AFTER() macro to find the number of bytes
available in the captured data, starting at the byte pointed to by the
argument.  It returns a u_int rather than a ptrdiff_t, so it'll be
32 bits on LP64 and LLP64 platforms as well as on ILP32 platforms.  Use
that macro.

Make size-of-buffer arguments size_t.

Cast some size_t and ptrdiff_t values to u_int or int.
2019-04-18 10:13:49 -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
Guy Harris
19fff15898 Type and size cleanups.
Make the count of 2-octet values to dump an unsigned value.

Make the variables into which we fetch those octets unsigned as well.

Cast the result of the "is the character printable ASCII?  If so, it's
the character, otherwise it's '.'" to char, to squelch narrowing
warnings.
2018-12-10 21:23:21 -08:00
Francois-Xavier Le Bail
5fe61e70f1 Simplify some expressions
In the equality case, the difference is also zero.
2018-06-01 22:25:17 +02:00
Francois-Xavier Le Bail
53d1f7a25a Update hex_and_ascii_print_with_offset() to static 2018-05-10 16:48:48 +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
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
fe4ef2d22b Use the EXTRACT_U_1() macro in some utility functions 2018-01-28 14:18:51 +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
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
58010245a5 Use more the EXTRACT_U_1() macro (48/n) 2017-12-09 09:26:39 +01:00
Francois-Xavier Le Bail
03a2d9c4c1 Use more the EXTRACT_U_1() macro (47/n)
In: if (... *(p) ...) ...
2017-12-05 10:45:44 +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
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
4ac72261ee Don't run past the snapshot length when doing hex/ASCII dumps. 2014-10-23 00:06:32 -07:00
Gisle Vanem
c527e26afb coordinate ascii_print() prototypes for MSVC
ascii_print() has conflicts between prototype and implementation. MSVC
doesn't allow adding a register modifier just like that.
2014-04-03 19:58:51 +04:00
Denis Ovsienko
f274a23dc1 improve previous NDO conversions 2014-04-03 17:41:02 +04:00
Denis Ovsienko
d6af516cbc finalize some previous NDO conversions
Eliminate a number of fputs(), putchar() and fflush() uses. Justify
preprocessor directives. Don't typecast ND_PRINT() to void and fix some
indentation.
2014-03-26 15:49:27 +04:00
Denis Ovsienko
eb8916857c NDOize print-ascii.c further
Introduce netdissect_options into hex_and_ascii_print_with_offset(),
hex_and_ascii_print() and related functions.
2014-03-13 11:06:15 +04:00
Guy Harris
bcda4c1950 With -A and -AA, don't send CRs to the standard output.
They don't belong on the ends of lines on UN*X, and the standard I/O
library will give us one at the end of the line on Windows so they're
not needed there.  In the middle of a line, just print a ".".
2014-02-03 00:01:56 -08:00
Guy Harris
3454732513 Do our own isascii(), isprint(), isgraph(), and toascii().
We do *not* want the behavior of isprint() and isgraph() to be
locale-dependent - we want both of them to return "true" only for ASCII
characters.

We have to do our own isascii() and toascii() on non-UN*X systems
anyway, so let's just do all of them ourselves.
2014-02-02 15:17:06 -08: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
Denis Ovsienko
0b7b6192c6 fix a few compiler warnings about prototypes
print-ascii.c needs prototypes of ascii_print(),
hex_and_ascii_print_with_offset() and hex_and_ascii_print().

print-icmp6.c needs prototypes of in_cksum_shouldbe() and ns_nprint().
2014-01-02 16:27:14 +04:00
Michael Richardson
ac910c086e ndo-ize print-ascii: hex_print_with_offset() 2014-01-01 21:31:18 -05:00
guy
e085b97e4b Have "ascii_print()" do the "-A" output, and nothing but the "-A"
output.  Have "hex_and_ascii_print_with_offset()" and
"hex_and_ascii_print()" to the "-X"-style offset, leaving
"hex_print_with_offset()" and "hex_print()" doing the "-x"-style output.
Don't have any of them check "xflag", "Xflag", or "Aflag" - they print
what they're intended to print, and the caller should check the flags in
question.

Don't have "-A" set "xflag" or "Xflag".

This cleans up some problems with "-A" printing hex informatioin - it's
not supposed to.
2005-07-06 20:53:30 +00:00
guy
03862177ea The first argument to "ascii_print_with_offset()", "ascii_print()",
"hex_print_with_offset()", and "hex_print()" is a string used as a tag;
make it a "const char *", not a "const u_char *".

Copy the declaration of "strsep()" from "interface.h" to "netdissect.h",
and get rid of the include of "interface.h" from "print-esp.c", as it
includes "netdissect.h".

Update the "ND_TTEST2()" macro to do the same overflow checks that
"TTEST2()" now does.
2004-07-21 22:00:10 +00:00
hannes
60263ffef6 pass on ident string to hex_print() 2003-12-29 11:05:09 +00:00
hannes
5c739aff63 elimitate tabs as they mess up the multi-line output 2003-12-29 10:51:34 +00:00
hannes
f910e26813 pass an identation string to the ascii printer 2003-12-29 10:30:40 +00:00
guy
bbc1cfa669 Have the configure script arrange that the Makefile define _U_
appropriately, and that GNUmakefile and the MSVC++ project file define
it apppriately, as we do with libpcap, rather than defining it in
"interface.h".

Undo the rcsid-shuffling and addition of extra #includes, as we no
longer need to arrange that "interface.h" be included before using _U_
in an RCS ID or copyright.
2003-11-16 09:36:07 +00:00
guy
3824a6c041 From Neil Spring:
use "_U_" in the definitions of "rcsid[]", to eliminate
	complaints about those variables being unused;

	move the definitions after the include of "interface.h", or add
	an include of "interface.h", so that "_U_" is defined.

Include "config.h" before including "tcpdump-stdinc.h" in
"missing/datalinks.c".
2003-11-15 00:39:12 +00:00
guy
edb0e92cdc Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:

	addrtoname.c, configure.in: Linux needs netinet/ether.h for
	ether_ntohost

	print-*.c: change char *foo = "bar" to const char *foo = "bar"
	to appease -Wwrite-strings; should affect no run-time behavior.

	print-*.c: make some variables unsigned.

	print-bgp.c: plen ('prefix len') is unsigned, no reason to
	validate by comparing to zero.

	print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
	instead of inet_ntoa.

	print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
	be false, so check for (u_int)-1, which represents failure,
	explicitly.

	print-isakmp.c: complete initialization of attrmap objects.

	print-lwres.c: "if(x); print foo;" seemed much more likely to be
	intended to be "if(x) { print foo; }".

	print-smb.c: complete initialization of some structures.

In addition, add some fixes for the signed vs. unsigned comparison
warnings:

	extract.h: cast the result of the byte-extraction-and-combining,
	as, at least for the 16-bit version, C's integral promotions
	will turn "u_int16_t" into "int" if there are other "int"s
	nearby.

	print-*.c: make some more variables unsigned, or add casts to an
	unsigned type of signed values known not to be negative, or add
	casts to "int" of unsigned values known to fit in an "int", and
	make other changes needed to handle the aforementioned variables
	now being unsigned.

	print-isakmp.c: clean up the handling of error/status indicators
	in notify messages.

	print-ppp.c: get rid of a check that an unsigned quantity is >=
	0.

	print-radius.c: clean up some of the bounds checking.

	print-smb.c: extract the word count into a "u_int" to avoid the
	aforementioned problems with C's integral promotions.

	print-snmp.c: change a check that an unsigned variable is >= 0
	to a check that it's != 0.

Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 00:00:07 +00:00
risso
3d932490b8 Added support for Win32, based on WinPcap. 2002-08-01 08:52:55 +00:00
itojun
111ff8a61d whitespace cleanup 2002-06-11 17:08:37 +00:00
guy
0283ff899a "-A" flag to print packet data in ASCII, from Jørgen Thomsen
<jth@jth.net>.
2002-04-24 06:55:54 +00:00
itojun
c87b499eac fix ascii dump with -X. due to mistake in snprintf() fixes.
(no need to pull into 3.5)
2000-01-29 16:47:46 +00:00
itojun
dff10c7f70 s/sprintf/snprintf/.
there seem to be couple of unsafe use of strcat and strcpy - we should
bring in strl{cat,cpy}.
2000-01-17 06:24:23 +00:00
fenner
34ff77ff43 Unify rcsid[]'s. 2000-01-09 21:34:14 +00:00
assar
ab9f1243f9 <sys/cdefs.h>: conditionalize 2000-01-07 16:34:59 +00:00
itojun
b35a056ecf comment out __RCSID (netbsd only). 1999-12-23 14:47:46 +00:00
itojun
2813c22cf1 add print-ascii.c and print-telnet.c from netbsd.
- add -X option for ascii printing.
- telnet command sequences (ff xx xx) will be dumped with -vvv -X.
1999-12-22 15:44:09 +00:00