-2147483648 provokes warnings, for various reasons involving the
definition of a constant in C, the rules of picking the type of a
constant, and the rules for determining the type of an expression
involving an integral value and the - operator. (Note that
-2147483648isn't a decimal-constant in C90 or C99, as a decimal-constant
can't contain a -. Therefore, it's a constant expression, consisting of
the - operator applied to the constant 2147483648.)
So we use INT32_MIN, which should at least make an effort to avoid those
warnings.
If it's not < 0, it's not -2147483648; check for negative values first.
Don't calculate the value for -2147483648 by hand, print a - and then
have unsigned_relts_print() calculate the value for 2147483648.
Have signed_relts_print() just call unsigned_relts_print() to do the
formatting, once it's ensured that the value is positive and printed a
leading minus sign if necessary.
Have separate routines for signed and unsigned relative time stamps.
Have the routine for signed time stamps handle the case of -2^31, where
you can't negate it and have the result fit in a 32-bit signed integer.
There are currently no users of the signed relative time stamp routine,
but it's there in case anybody needs it (and is passing 32-bit
quantitites, so that there's a risk that a packet might contain -2^31 as
the time stamp).
Fixes an array overflow found with American Fuzzy Lop by Hanno Böck.
It can't be told to stop at the end of the packet data. Add a
fn_printztn() that prints null-terminated strings, with a length check,
and which returns the number of bytes processed, or 0 if we ran out of
data. That means it does the scanning we need, but safely.
Use it in the TFTP and BOOTP printers.
Fixes a heap overflow found with American Fuzzy Lop by Hanno Böck.
As the string in question is passed as a constant from a printer, it
*shouldn't* contain any non-ASCII characters, but squelching the warning
is harmless and, on modern processors, a non-sign-extending byte load
shouldn't be any worse than a sign-extending byte load.
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.
When I needed to print a string and didn't remember which of the three
functions fn_print(), fn_printn() and fn_printzp() was the right one
for the data, every time it would end up in reading through all of them
and forgetting the difference shortly after the commit.
Just having it explained in the comments should work better.
- Fix display of some nanoseconds timestamps
For example, bad print 00:-16:-2.000851566 is now 00:00:00.037851566
- Fix display of timestamp of a packet when it is lower than previous one
For example, bad print 00:00:-1.000999790 is now -00:00:00.000000210
Switch RRCP and BGP functions from tok2strbuf() to tok2str() to avoid
unnecessary local buffer management. The latter function does it in a
way to allow up to 4 calls to itself from printf(). After that
tok2strbuf() remains used by tok2str() only and can be refined later.
Remove a duplicate macro and place the remaining definition into the
right file.
Delete the 'static char buf' array in ts_format().
buf is now a parameter of ts_format().
Moreover:
Decrease a too long string.
Fix a space in a comment.
Do the case-insensitive comparisons in a locale-independent fashion that
only maps ASCII letters, in the standard English-language fashion; that
way, we don't get bitten by, for example, Turkish having separate "i
with dot" and "i without dot" letters, with lower-case "i with dot" being
mapped to upper-case "I with dot" rather than being mapped to "I".
This prevents the compiler issue mentioned in GitHub issue #451, and
also cleans up some other signed vs. unsigned stuff.
While we're at it, clean up bittok2str_internal() (just pass it the
separator string, not a Boolean value that's tested to choose the
separator string), and print unknown arguments to the bittok2str
routines in hex, not decimal.