diff options
author | Denis Ovsienko <denis@ovsienko.info> | 2021-03-17 04:02:23 +0000 |
---|---|---|
committer | Denis Ovsienko <denis@ovsienko.info> | 2021-03-17 11:55:17 +0000 |
commit | 7e29aa36055cb09e68325e3e26aeb82ef8584a89 (patch) | |
tree | da7bcc11a469fdaa54294ac15e38e9622095ca10 | |
parent | 8657e34a600f3b5fe0e0368ad06a0c7b1a18307b (diff) | |
download | tcpdump-7e29aa36055cb09e68325e3e26aeb82ef8584a89.tar.gz |
Squelch compiler warnings on OpenBSD.
With these changes tcpdump passes "CFLAGS=-Werror make" on OpenBSD 6.8
AMD64, so build.sh has one less reason to fail.
gcc (GCC) 4.2.1 20070719
(also from OpenBSD clang version 10.0.1 with different wording)
./addrtoname.c: In function 'etheraddr_string':
./addrtoname.c:605: warning: passing argument 2 of 'ether_ntohost'
discards qualifiers from pointer target type
./addrtoname.c: In function 'init_etherarray':
./addrtoname.c:980: warning: passing argument 2 of 'ether_ntohost'
discards qualifiers from pointer target type
./print.c: In function 'pretty_print_packet':
./print.c:389: warning: passing argument 2 of 'ts_print' from
incompatible pointer type
./bpf_dump.c:34: warning: no previous prototype for 'bpf_dump'
-rw-r--r-- | addrtoname.c | 15 | ||||
-rw-r--r-- | bpf_dump.c | 1 | ||||
-rw-r--r-- | print.c | 11 |
3 files changed, 24 insertions, 3 deletions
diff --git a/addrtoname.c b/addrtoname.c index 33b93784..58ced4f9 100644 --- a/addrtoname.c +++ b/addrtoname.c @@ -77,6 +77,7 @@ #define NEED_NETINET_IF_ETHER_H #else /* HAVE_STRUCT_ETHER_ADDR */ struct ether_addr { + /* Beware FreeBSD calls this "octet". */ unsigned char ether_addr_octet[MAC_ADDR_LEN]; }; #endif /* HAVE_STRUCT_ETHER_ADDR */ @@ -601,8 +602,15 @@ etheraddr_string(netdissect_options *ndo, const uint8_t *ep) #ifdef USE_ETHER_NTOHOST if (!ndo->ndo_nflag) { char buf2[BUFSIZE]; + /* + * This is a non-const copy of ep for ether_ntohost(), which + * has its second argument non-const in OpenBSD. Also saves a + * type cast. + */ + struct ether_addr ea; - if (ether_ntohost(buf2, (const struct ether_addr *)ep) == 0) { + memcpy (&ea, ep, MAC_ADDR_LEN); + if (ether_ntohost(buf2, &ea) == 0) { tp->e_name = strdup(buf2); if (tp->e_name == NULL) (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, @@ -977,7 +985,10 @@ init_etherarray(netdissect_options *ndo) /* * Use YP/NIS version of name if available. */ - if (ether_ntohost(name, (const struct ether_addr *)el->addr) == 0) { + /* Same workaround as in etheraddr_string(). */ + struct ether_addr ea; + memcpy (&ea, el->addr, MAC_ADDR_LEN); + if (ether_ntohost(name, &ea) == 0) { tp->e_name = strdup(name); if (tp->e_name == NULL) (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, @@ -28,6 +28,7 @@ #include <stdio.h> #include "netdissect.h" +#include "interface.h" void bpf_dump(const struct bpf_program *p, int option) @@ -386,7 +386,16 @@ pretty_print_packet(netdissect_options *ndo, const struct pcap_pkthdr *h, * bigger lengths. */ - ts_print(ndo, &h->ts); + /* + * The header /usr/include/pcap/pcap.h in OpenBSD declares h->ts as + * struct bpf_timeval, not struct timeval. The former comes from + * /usr/include/net/bpf.h and uses 32-bit unsigned types instead of + * the types used in struct timeval. + */ + struct timeval tvbuf; + tvbuf.tv_sec = h->ts.tv_sec; + tvbuf.tv_usec = h->ts.tv_usec; + ts_print(ndo, &tvbuf); /* * Printers must check that they're not walking off the end of |