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'
This commit is contained in:
Denis Ovsienko 2021-03-17 04:02:23 +00:00
parent 8657e34a60
commit 7e29aa3605
3 changed files with 24 additions and 3 deletions

View File

@ -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,

View File

@ -28,6 +28,7 @@
#include <stdio.h>
#include "netdissect.h"
#include "interface.h"
void
bpf_dump(const struct bpf_program *p, int option)

11
print.c
View File

@ -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