commit 116283f86777d20cf3318f7e388a9f32562fbc48
parent 5910e0045d028419468a04fc7737ff288fb85a77
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date: Wed, 24 Jun 2020 16:58:26 +1000
Silence prototype warnings
Added some typedefs for the four function types in use: packet dumpers,
data matchers, delay simulators and timestamp printers. Also started
marking unused function parameters.
More work is needed for process(), as making it a pcap_handler generates
a whole slew of warnings about parameter const-ness and such.
Diffstat:
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/ngrep.c b/ngrep.c
@@ -68,10 +68,10 @@ pcre_extra *pattern_extra = NULL;
char *match_data = NULL, *bin_data = NULL;
int hex_exp_pfx = 0;
uint16_t match_len = 0;
-int8_t (*match_func)() = &blank_match_func;
+match_func matcher = blank_match_func;
int8_t dump_single = 0;
-void (*dump_func)(unsigned char *, uint32_t, uint16_t, uint16_t) = &dump_formatted;
+dump_func dumper = &dump_formatted;
/* BPF/Network */
char *filter = NULL, *filter_file = NULL;
@@ -87,7 +87,8 @@ struct in_addr net, mask;
/* Timestamp/delay functionality */
struct timeval prev_ts = {0, 0}, prev_delay_ts = {0,0};
-void (*print_time)() = NULL, (*dump_delay)() = dump_delay_proc_init;
+delay_func dump_delay = dump_delay_proc_init;
+ts_func print_time = NULL;
/*
* Window-size functionality
@@ -223,13 +224,13 @@ main(int argc, char **argv)
break;
case 'W':
if (!strcasecmp(optarg, "normal"))
- dump_func = &dump_formatted;
+ dumper = &dump_formatted;
else if (!strcasecmp(optarg, "byline"))
- dump_func = &dump_byline;
+ dumper = &dump_byline;
else if (!strcasecmp(optarg, "none"))
- dump_func = &dump_unwrapped;
+ dumper = &dump_unwrapped;
else if (!strcasecmp(optarg, "single")) {
- dump_func = &dump_unwrapped;
+ dumper = &dump_unwrapped;
dump_single = 1;
} else {
warnx("invalid wrap method: %s", optarg);
@@ -252,7 +253,7 @@ main(int argc, char **argv)
if (unveil(NULL, NULL) == -1)
err(2, "unveil");
- if (show_hex && dump_func != &dump_formatted) {
+ if (show_hex && dumper != &dump_formatted) {
warnx("-x is incompatible with -W");
usage();
}
@@ -519,7 +520,7 @@ setup_hex_match(void)
bin_data = bytes;
match_len = len / 2;
- match_func = &bin_match_func;
+ matcher = bin_match_func;
return 0;
err:
@@ -555,7 +556,7 @@ setup_pattern_match(void)
return -1;
}
pattern_extra = pcre_study(pattern, 0, &re_err);
- match_func = &re_match_func;
+ matcher = re_match_func;
return 0;
}
@@ -579,7 +580,7 @@ vlan_frame_count(u_char * p, uint16_t limit)
}
void
-process(u_char *d, struct pcap_pkthdr *h, u_char *p)
+process(UNUSED u_char *d, struct pcap_pkthdr *h, u_char *p)
{
uint8_t vlan_offset = include_vlan ?
vlan_frame_count(p, h->caplen) * VLANHDR_SIZE : 0;
@@ -761,7 +762,7 @@ dump_packet(struct pcap_pkthdr *h, u_char *p, uint8_t proto,
len = limitlen;
if (len > 0 &&
- match_func(data, len, &match_index, &match_size) == invert_match &&
+ matcher(data, len, &match_index, &match_size) == invert_match &&
!keep_matching)
return;
@@ -836,7 +837,7 @@ dump_packet(struct pcap_pkthdr *h, u_char *p, uint8_t proto,
printf(" #%u\n", seen_frames);
if (quiet < 3 && len > 0)
- dump_func(data, len, match_index, match_size);
+ dumper(data, len, match_index, match_size);
if (pd_dump)
pcap_dump((u_char *) pd_dump, h, p);
@@ -900,8 +901,8 @@ bin_match_func(unsigned char *data, uint32_t len, uint16_t *mindex,
}
int8_t
-blank_match_func(unsigned char *data, uint32_t len, uint16_t *mindex,
- uint16_t *msize)
+blank_match_func(UNUSED unsigned char *data, UNUSED uint32_t len,
+ uint16_t *mindex, uint16_t *msize)
{
matches++;
diff --git a/ngrep.h b/ngrep.h
@@ -27,6 +27,8 @@
((uint16_t)((uint16_t)*((const uint8_t *)(p) + 0) << 8 | \
(uint16_t)*((const uint8_t *)(p) + 1)))
+#define UNUSED __attribute__((__unused__))
+
/*
* Default patterns for BPF and regular expression filters.
*
@@ -61,6 +63,12 @@ typedef enum {
TCP = 'T', UDP = 'U', ICMP = 'I', ICMPv6 = 'I', IGMP = 'G', UNKNOWN = '?'
} netident_t;
+typedef void (*dump_func)(unsigned char *, uint32_t, uint16_t, uint16_t);
+typedef int8_t (*match_func)(unsigned char *, uint32_t, uint16_t *,
+ uint16_t *);
+typedef void (*delay_func)(struct pcap_pkthdr *);
+typedef void (*ts_func)(struct pcap_pkthdr *);
+
int setup_pcap_source(void);
int setup_bpf_filter(char **);
int hextoc(char d, char *c);