Commit Graph

43 Commits

Author SHA1 Message Date
Guy Harris
18ea57e19b netdissect-stdinc: get rid of an extra definition of strdup.
We first unconditionally define it, and then later only define it if
it's already defined.  Microsoft defines it for us, but has deprecated
that definition because it pollutes the ISO C namespace with a POSIXism;
try just doing the conditional definition.
2024-09-09 19:41:22 -07:00
Denis Ovsienko
10b807441e Detect OS IPv6 support using AF_INET6 only.
tcpdump source code has not been using struct in6_addr since commit
0c9cfdc in 2019, so lose the conditional structure declaration, which is
a no-op.

Since commit de7c619 in 2015 netdissect-stdinc.h on Windows defines
HAVE_OS_IPV6_SUPPORT if AF_INET6 if defined, which makes it equivalent
to AF_INET6.  On Unix-like systems taking struct in6_addr out of scope
would make HAVE_OS_IPV6_SUPPORT equivalent to AF_INET6, thus after
removing struct in6_addr remove HAVE_OS_IPV6_SUPPORT together with
Autoconf and CMake checks that define it.  Leave an unrelated CMake
workaround in place for later debugging.

On Windows do not define AF_INET6 if it is not defined, which makes
AF_INET6 a universal indicator of the OS IPv6 support on all supported
OSes.  The few remaining use cases that genuinely need AF_INET6 use it
to make OS API calls, so if the macro is not defined, it most likely
means such an API call in the best case would return just a well-formed
error status.  With this in mind, in win32_gethostbyaddr() and
ip6addr_string() guard all IPv6-specific code with #ifdef AF_INET6.  In
tcpdump.c add a comment to note why a guard is not required for
Casper-specific conditional code that uses AF_INET6.

This way when the OS does not support IPv6, IPv6 addresses will not
resolve to names, which is expected.  Other than that, tcpdump should be
able to process IPv6 addresses the usual way regardless if the OS would
be able to process the packets with these addresses.
2023-02-22 20:05:58 +00:00
Francois-Xavier Le Bail
794a259a33 Put a space between type and '*' in pointer declarators (style) 2021-12-30 20:23:13 +01:00
Guy Harris
39f09d68ce Suppress "casting away const" warnings in missing/getopt_long.c.
It's explicitly cheating in some places; just cast away the warnings.

Add a Clang version testing macro to compiler-tests.h.

Move the diagnostic control #defines from netdissect-stdinc.h to
diag-control.h, libpcap-style, so that they can be used by code that
doesn't use (or need) netdissect-stdinc.h.  This also means that we can
limit the inclusion of diag-control.h, and the definition of those

Do them more libpcap-style, with separate DIAG_OFF/DIAG_ON pairs for
particular issues, rather than having DIAG_OFF() and DIAG_ON() macros
that take -W option names as arguments; that way, if we need to define
them for compilers that don't have the GCC/Clang syntax for those
pragmas, e.g. MSVC, we can do so.
2021-07-24 01:51:02 -07:00
Guy Harris
eebc98d735 Add ftmacros.h, defining various feature test macros, and use it.
This attempts to ensure that we get all the APIs for the platform
declared, including the ones that, shock horror, "pollute the
namespace".

This fixes some compile failures with Sun C on Solaris 11.
2021-01-01 22:47:27 -08:00
Guy Harris
faf8fb70af Handle very large -f files by rejecting them.
_read(), on Windows, has a 32-bit size argument and a 32-bit return
value, so reject -f files that have more than 2^31-1 characters.

Add some #defines so that, on Windows, we use _fstati64 to get the size
of that file, to handle large files.

Don't assume that our definition for ssize_t is the same size as size_t;
by the time we want to print the return value of the read, we know it'll
fit into an int, so just cast it to int and print it with %d.
2020-09-30 11:37:30 -07:00
Guy Harris
a96b0d2174 We no longer use isascii(), so we don't need to define it with MSVC. 2019-09-01 16:15:31 -07: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
c2d6a5db5b Clean up comments.
[skip ci]
2019-08-11 13:50:13 -07:00
Guy Harris
9860220fde <inttypes.h> should suffice to define PRI[doux]64. 2019-08-11 11:35:55 -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
846e943f2b Require VS 2015 or later for Windows builds using Visual Studio.
Forcibly fail the build if we don't have it, and just include
<inttypes.h> if we do.
2019-08-08 20:03:00 -07:00
Francois-Xavier Le Bail
27eabd022a Revert "Add PRIsize, to use as the print format for size_t"
This reverts commit 40f1cf8aa7.

We will use %zu as the print format for size_t because C99 support it and
also Visual Studio VS 2015 and after.
2019-08-08 11:17:29 +02:00
Francois-Xavier Le Bail
40f1cf8aa7 Add PRIsize, to use as the print format for size_t
size_t may be bigger than unsigned long, so don't just cast to unsigned
long and print with %lu".  (In practice, the value is unlikely to be
bigger, but this is cleaner.)

We could use %zu on UN*X, as we require C99 support and C99 requires
support for z as a size modifier, but MSVC doesn't support z as a size
modifier until Visual Studio 2017.

Updated from:
libpcap/commit/e217f88289b9601e3a9a8d13477f867bcb83b5e2
2019-08-03 16:24:04 +02:00
Guy Harris
b759e3117c Define ssize_t on Windows. 2019-07-21 11:38:51 -07:00
Guy Harris
1c803f7812 Squelch annoying bogus Clang warnings. 2018-11-09 12:54:00 -08:00
Guy Harris
1c30d69b97 Fix nd_snprintf(buf, buflen, "string");
If this is VS prior to 2015 or MinGW, we can't trust snprintf(); we have
to use _snprintf_s(), but that requires us to insert _TRUNCATE as an
argument after the buffer and buffer length and before the format string
and arguments, if any, to the format string.

That means we need to use a vararg macro; however, if we make the format
string a regular argument to the macro, that means that, if there are no
arguments *after* the format string, you end up with an argument list to
_snprintf_s() that ends with "fmt, ", and that's not valid C.

*If* we knew this was GCC or Clang, we could use a GNU C-specific hack,
wherein, if __VA_ARGS__ is preceded by ## and there's a comma before
that, the comma is removed if __VA_ARGS__ is empty, but this might be
Microsoft's C compiler in a version of Visual Studio prior to VS 2015,
which might not support that.

So we have to just have the macro take, as the ... arguments, the format
string and its arguments.

Addresses GitHub issue #713.
2018-10-13 22:51:54 -07:00
Daniel Miller
30618d8d9a Ensure isatty is defined on Win32. 2018-10-02 09:52:40 -05: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
Guy Harris
1e120597d2 Don't define {v}snprintf() as _{v}snprintf(); they're not the same.
They don't behave exactly like ISO C {v}snprintf(), so, on Windows, we
have wrappers around _{v}snprintf() that behave the way {v}snprintf()
are supposed to work.
2018-01-29 13:55:08 -08:00
Guy Harris
6ed7ed4711 Another UN*Xism we need - isascii().
I guess it's not in ISO C because the character set of an ISO C
implementation isn't necessarily ASCII (EBCDIC, in IBM's C for z/OS and
IBM i).
2018-01-29 01:44:30 -08:00
Guy Harris
c1094815c3 Let CMake figure out whether we have snprintf() or not.
Now that we're using check_symbol_exists(), CMake can find it, so we
don't need to check the compiler version - and this avoids a warning
about redefining HAVE_SNPRINTF.
2018-01-29 01:10:25 -08:00
Guy Harris
be658698f9 Include funcattrs.h before you use stuff in it. 2018-01-28 21:09:03 -08:00
Guy Harris
b3703ed9cf Pick up Windows snprintf and strdup replacements from libpcap. 2018-01-28 20:57:15 -08:00
Guy Harris
a909db55eb Declare ND_UNALIGNED in netdissect.h.
It's netdissect-specific, and there are some files that include
netdissect.h, that don't include netdissect-stdinc.h, and that include
files that define structures using ND_UNALIGNED.
2018-01-28 20:16:36 -08:00
Guy Harris
45fc519a2a Don't test for __attribute__ in the configure script.
Instead, use compiler test macros to check whether *particular*
attributes are supported, and set various #defines appropriately, in
header files.

Rename the UNALIGNED structure attribute to ND_UNALIGNED, and ask
whether we still need it.
2018-01-21 17:57:20 -08:00
Francois-Xavier Le Bail
5b45260126 Remove min() and max() macros from netdissect-stdinc.h
They are already defined in netdissect.h.
2018-01-20 16:47:38 +01:00
Guy Harris
3bc62cd35f Use pcapng as the name of the file format.
At one point, I remember a discussion resulting in the official name of
the next-generation replacement for pcap format being changed to
"pcapng", with no hyphen.

Make tcpdump reflect that.

While we're at it, uppdate to use "macOS" as the name of Apple's
UNIX-for-Macs, as appropriate (don't use it for versions that were still
called Mac OS X or OS X).
2018-01-08 18:50:06 -08:00
Ali Abdulkadir
9b939ac5a3 improved check for ipv6 support on windows (autotools) 2017-11-06 01:42:13 +03:00
Francois-Xavier Le Bail
99b16dee90 Fix the macros for controlling warnings
The current clang compilers also set __GNUC__ and __GNUC_MINOR__ thus
we need to test the clang case before the GCC one.

Moreover:
Add DIAG_OFF_CLANG and DIAG_ON_CLANG macros for clang specific
warnings.
Add a comment.
2017-10-21 20:01:02 +02:00
Guy Harris
370cb54503 Fix 64-bit maximum file size argument stuff.
Define strtoint64_t as appropriate in netdissect-stdinc.h.

Check HAVE_PCAP_DUMP_FTELL64, not HAVE_PCAP_FTELL64, to see whether we
have pcap_dump_ftell64().
2017-10-20 12:15:26 -07:00
Guy Harris
d230f8b687 Get rid of obsolescent configure test.
All UN*Xes, these days, let you include both <time.h> and <sys/time.h>.
2017-10-16 13:48:40 -07: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
893b1b1cfb Make the delta between 1970 and 1900 a 64-bit signed integral constant.
It doesn't fit in a 32-bit signed integral constant, so make sure it's
64-bit; the only use is to subtract it from a 64-bit signed integral
value.
2017-09-21 10:05:33 -07:00
Guy Harris
14c81f0a4a Clean up the stuff we do to get <inttypes.h> stuff defined.
If we have a libpcap with <pcap/pcap-inttypes.h>, include it, so that we
don't have to worry about definitions colliding if we later include a
pcap header file that includes pcap/pcap-inttypes.h.

Otherwise, do the same stuff pcap-inttypes.h does.  This means that, on
UN*X, we require that there be an <inttypes.h> that defines everything
we need.

Don't bother doing checks that are no longer necessary as a result of
those changes.
2017-09-14 18:53:34 -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
Denis Ovsienko
6df678ca31 Check for __attribute__ ((fallthrough)) (GCC 7).
The documentation claims that recent GCC is now better by default at
spotting cases of code flow falling through (which is true) and that it
avoids false positives by matching nearby source code comments with
regexps. However, the latter feature doesn't seem to work as reliably
as the manual describes it, so let's have a macro for this purpose.

Tested to work on:
* x86_64, Fedora 26, GCC 7.1.1 (w/__attribute__, w/fallthrough)
* x86_64, Ubuntu 16.04, GCC 5.4.0 (w/__attribute__, w/o fallthrough)
* x86_64, FreeBSD 11.0, CLang 3.8.0 (w/__attribute__, w/o fallthrough)
* SPARC, Solaris 10, SolStudio 12.4 (w/__attribute__, w/o fallthrough)
* SPARC, Solaris 10, SunStudio 11 (w/o __attribute__)
2017-07-22 19:33:49 +01:00
Francois-Xavier Le Bail
c94fccbfce Fix a file mode
A header file does not need an executable mode.
(old mode 100755 ; new mode 100644)
2016-09-26 12:49:41 +02:00
Michael Richardson
a9f4d1c299 added some minor protection against multiple inclusion 2016-07-09 17:22:18 -04:00
Guy Harris
de7c6192e4 Additional Windows cleanups.
Don't import stuff from WinPcap that it really shouldn't be exporting.

Define HAVE_U_INT{N}_T,to suppress definition of intN_t in bittypes.h, as
included by <pcap/pcap.h> on Windows.

Define HAVE_OS_IPV6_SUPPORT if AF_INET6 is defined, so that if we're
building with a VC+SDK combination that defines it and struct in6_addr,
we don't define them ourselves.
2015-09-18 17:24:23 -07:00
Guy Harris
4841fc240d We don't define our own inet_aton() any more, so don't declare it. 2015-09-18 13:19:32 -07: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
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