tcpdump mailing list archives

Re: if anyone wanted to practice fixing compiler warnings in tcpdump...


From: Guy Harris <gharris () sonic net>
Date: Sun, 29 Jul 2018 18:08:51 -0700

On Jul 29, 2018, at 5:48 AM, Denis Ovsienko <denis () ovsienko info> wrote:

Building (configure+gcc) tcpdump master branch with libpcap 0.6.1 yields the following compiler warnings, some of 
which are as easy as decorating a variable declaration with #ifdef:

./tcpdump.c: In function ‘open_interface’:
./tcpdump.c:1382:22: warning: passing argument 1 of ‘pcap_open_live’ discards ‘const’ qualifier from pointer target 
type [-Wdiscarded-qualifiers]
 pc = pcap_open_live(device, ndo->ndo_snaplen, !pflag, 1000, ebuf);
                     ^~~~~~
In file included from ./tcpdump.c:97:0:
../libpcap/pcap.h:136:9: note: expected ‘char *’ but argument is of type ‘const char *’
pcap_t *pcap_open_live(char *, int, int, int, char *);
        ^~~~~~~~~~~~~~

Libpcap *should* have had it as const since the beginning, but const was new back when libpcap was introduced; we later 
added const to a bunch of argument declarations.

In this particular case, we could make the argument to open_interface() a "char *" rather than a "const char *" - it's 
just a routine internal to tcpdump, so it's not as if we're claiming "hey, we might modify this" to code using it.

./tcpdump.c: At top level:
./tcpdump.c:221:22: warning: ‘show_tstamp_types_and_exit’ declared ‘static’ but never defined [-Wunused-function]
static NORETURN void show_tstamp_types_and_exit(pcap_t *, const char *device);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
./tcpdump.c:195:12: warning: ‘Uflag’ defined but not used [-Wunused-variable]
static int Uflag;   /* "unbuffered" output of dump files */
           ^~~~~
./tcpdump.c:190:12: warning: ‘jflag’ defined but not used [-Wunused-variable]
static int jflag = -1;   /* packet time stamp source */
           ^~~~~
./tcpdump.c:155:12: warning: ‘Bflag’ defined but not used [-Wunused-variable]
static int Bflag;   /* buffer size */
           ^~~~~

Just #ifdefs around the definitions of the flags and declaration of the routine fixes that.  Done in 
ca47c45b8eab2e205165e175411a5e71e18101fc.

./print.c: In function ‘get_if_printer’:
./print.c:304:13: warning: implicit declaration of function ‘pcap_datalink_val_to_name’; did you mean 
‘pcap_datalink’? [-Wimplicit-function-declaration]
  dltname = pcap_datalink_val_to_name(type);
            ^~~~~~~~~~~~~~~~~~~~~~~~~
            pcap_datalink
./print.c:304:11: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
  dltname = pcap_datalink_val_to_name(type);
          ^

We need to include "pcap-missing.h" in "print.c" to declare it.  Done in b314392dfe5345edfdd8de07c78a4ea2ae636fd9.

./print-juniper.c: In function ‘juniper_parse_header’:
./print-juniper.c:1203:14: warning: unused variable ‘control_word’ [-Wunused-variable]
    uint32_t control_word;
             ^~~~~~~~~~~~
At top level:
./print-juniper.c:1197:1: warning: ‘juniper_parse_header’ defined but not used [-Wunused-function]
juniper_parse_header(netdissect_options *ndo,
^~~~~~~~~~~~~~~~~~~~
./print-juniper.c:1079:1: warning: ‘juniper_ppp_heuristic_guess’ defined but not used [-Wunused-function]
juniper_ppp_heuristic_guess(netdissect_options *ndo,
^~~~~~~~~~~~~~~~~~~~~~~~~~~
./print-juniper.c:441:25: warning: ‘juniper_protocol_values’ defined but not used [-Wunused-const-variable=]
static const struct tok juniper_protocol_values[] = {
                        ^~~~~~~~~~~~~~~~~~~~~~~
./print-juniper.c:67:25: warning: ‘juniper_ipsec_type_values’ defined but not used [-Wunused-const-variable=]
static const struct tok juniper_ipsec_type_values[] = {
                        ^~~~~~~~~~~~~~~~~~~~~~~~~

Those required #ifdefs/#ifs.  Done in 09d0c4368cf4e3bb247baf9415cf98416402ea14.
_______________________________________________
tcpdump-workers mailing list
tcpdump-workers () lists tcpdump org
https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers

Current thread: