commit 219f3f8e1649a94a25c7ef4d4713b9c26010db9f
parent 415647025488b44ba155c7c5facc8e77595e453c
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date: Thu, 17 Sep 2020 11:40:13 +1000
Make process match the form of pcap_handler
Diffstat:
M | ngrep.c | | | 26 | +++++++++++++------------- |
M | ngrep.h | | | 22 | +++++++++++----------- |
2 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/ngrep.c b/ngrep.c
@@ -350,7 +350,7 @@ main(int argc, char **argv)
}
update_windowsize(0);
- while (pcap_loop(pd, -1, (pcap_handler)process, 0))
+ while (pcap_loop(pd, -1, process, 0))
;
clean_exit(0);
@@ -607,9 +607,9 @@ setup_pattern_match(void)
}
static inline size_t
-vlan_frame_count(uint8_t *p, uint32_t caplen)
+vlan_frame_count(const uint8_t *p, uint32_t caplen)
{
- uint8_t *et = p + 12;
+ const uint8_t *et = p + 12;
uint16_t ether_type = EXTRACT_16BITS(et);
size_t count = 0;
@@ -625,7 +625,7 @@ vlan_frame_count(uint8_t *p, uint32_t caplen)
}
void
-process(UNUSED uint8_t *d, struct pcap_pkthdr *h, uint8_t *p)
+process(UNUSED uint8_t *d, const struct pcap_pkthdr *h, const uint8_t *p)
{
uint8_t *data;
struct ip *ip4_pkt;
@@ -797,10 +797,10 @@ process(UNUSED uint8_t *d, struct pcap_pkthdr *h, uint8_t *p)
}
void
-dump_packet(struct pcap_pkthdr *h, uint8_t *p, uint8_t proto, uint8_t *data,
- uint32_t len, const char *ip_src, const char *ip_dst,
- uint16_t sport, uint16_t dport, uint8_t flags, uint16_t hdr_offset,
- bool frag, uint16_t frag_offset, uint32_t frag_id)
+dump_packet(const struct pcap_pkthdr *h, const uint8_t *p, uint8_t proto,
+ uint8_t *data, uint32_t len, const char *ip_src, const char *ip_dst,
+ uint16_t sport, uint16_t dport, uint8_t flags, uint16_t hdr_offset,
+ bool frag, uint16_t frag_offset, uint32_t frag_id)
{
size_t match_size, match_index;
char ident = '?';
@@ -1126,7 +1126,7 @@ get_filter_from_argv(char **argv)
}
void
-print_time_absolute(struct pcap_pkthdr *h)
+print_time_absolute(const struct pcap_pkthdr *h)
{
struct tm *t = localtime((const time_t *)&h->ts.tv_sec);
@@ -1136,7 +1136,7 @@ print_time_absolute(struct pcap_pkthdr *h)
}
void
-print_time_diff(struct pcap_pkthdr *h)
+print_time_diff(const struct pcap_pkthdr *h)
{
uint32_t secs, usecs;
@@ -1155,7 +1155,7 @@ print_time_diff(struct pcap_pkthdr *h)
}
void
-print_time_offset(struct pcap_pkthdr *h)
+print_time_offset(const struct pcap_pkthdr *h)
{
uint32_t secs, usecs;
@@ -1177,7 +1177,7 @@ print_time_offset(struct pcap_pkthdr *h)
}
void
-dump_delay_proc_init(struct pcap_pkthdr *h)
+dump_delay_proc_init(const struct pcap_pkthdr *h)
{
dump_delay = &dump_delay_proc;
@@ -1188,7 +1188,7 @@ dump_delay_proc_init(struct pcap_pkthdr *h)
}
void
-dump_delay_proc(struct pcap_pkthdr *h)
+dump_delay_proc(const struct pcap_pkthdr *h)
{
uint32_t secs, usecs;
diff --git a/ngrep.h b/ngrep.h
@@ -65,8 +65,8 @@
typedef void (*dump_func)(uint8_t *, uint32_t, size_t, size_t);
typedef int (*char_cmp_func)(int);
typedef bool (*match_func)(uint8_t *, uint32_t, size_t *, size_t *);
-typedef void (*delay_func)(struct pcap_pkthdr *);
-typedef void (*ts_func)(struct pcap_pkthdr *);
+typedef void (*delay_func)(const struct pcap_pkthdr *);
+typedef void (*ts_func)(const struct pcap_pkthdr *);
int setup_pcap_source(void);
int setup_bpf_filter(char **);
@@ -75,30 +75,30 @@ int setup_hex_match(void);
int setup_pattern_match(void);
int setup_matcher(void);
-void process(uint8_t *, struct pcap_pkthdr *, uint8_t *);
+void process(uint8_t *, const struct pcap_pkthdr *, const uint8_t *);
__dead void usage(void);
void update_windowsize(int32_t);
__dead void clean_exit(int);
-void dump_packet(struct pcap_pkthdr *, uint8_t *, uint8_t, uint8_t *, uint32_t,
- const char *, const char *, uint16_t, uint16_t, uint8_t,
- uint16_t, bool, uint16_t, uint32_t);
+void dump_packet(const struct pcap_pkthdr *, const uint8_t *, uint8_t,
+ uint8_t *, uint32_t, const char *, const char *, uint16_t,
+ uint16_t, uint8_t, uint16_t, bool, uint16_t, uint32_t);
int byline_cmp(int);
void dump_unformatted(uint8_t *, uint32_t, size_t, size_t);
void dump_formatted(uint8_t *, uint32_t, size_t, size_t);
-void dump_delay_proc_init(struct pcap_pkthdr *);
-void dump_delay_proc(struct pcap_pkthdr *);
+void dump_delay_proc_init(const struct pcap_pkthdr *);
+void dump_delay_proc(const struct pcap_pkthdr *);
bool re_match_func(uint8_t *, uint32_t, size_t *, size_t *);
bool bin_match_func(uint8_t *, uint32_t, size_t *, size_t *);
bool blank_match_func(uint8_t *, uint32_t, size_t *, size_t *);
-void print_time_absolute(struct pcap_pkthdr *);
-void print_time_diff(struct pcap_pkthdr *);
-void print_time_offset(struct pcap_pkthdr *);
+void print_time_absolute(const struct pcap_pkthdr *);
+void print_time_diff(const struct pcap_pkthdr *);
+void print_time_offset(const struct pcap_pkthdr *);
char *get_filter_from_file(void);
char *get_filter_from_argv(char **);