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.
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.
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.
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.
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.
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.
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).
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.
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
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.
Eliminate a number of fputs(), putchar() and fflush() uses. Justify
preprocessor directives. Don't typecast ND_PRINT() to void and fix some
indentation.
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 ".".
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.
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.
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().
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.
"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.
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.
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".
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.