ongrep

A cleaned up fork of ngrep for OpenBSD
git clone git://git.sgregoratto.me/ongrep
Log | Files | Refs | README | LICENSE

commit c93238c8e574351f90aa5351b28329228ce25dae
parent 3e5c48603914ede7e4c60e357e333c473bd3630e
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Wed, 24 Jun 2020 20:22:07 +1000

Drop netident_t and set ident char in dump_packet

Since these are set once per packet, it doesn't make sense to define
them as globals. Instead, set the ident char in the switch itself,
defaulting to '?' for unknown protocols.

Diffstat:
Mngrep.c | 16++++++----------
Mngrep.h | 7-------
2 files changed, 6 insertions(+), 17 deletions(-)

diff --git a/ngrep.c b/ngrep.c @@ -762,7 +762,7 @@ dump_packet(struct pcap_pkthdr *h, u_char *p, uint8_t proto, uint32_t frag_id) { uint16_t match_size, match_index; - char ident; + char ident = '?'; if (!show_empty && len == 0) return; @@ -780,22 +780,18 @@ dump_packet(struct pcap_pkthdr *h, u_char *p, uint8_t proto, switch (proto) { case IPPROTO_TCP: - ident = TCP; + ident = 'T'; break; case IPPROTO_UDP: - ident = UDP; + ident = 'U'; break; case IPPROTO_ICMP: - ident = ICMP; - break; + /* FALLTHROUGH */ case IPPROTO_ICMPV6: - ident = ICMPv6; + ident = 'I'; break; case IPPROTO_IGMP: - ident = IGMP; - break; - default: - ident = UNKNOWN; + ident = 'G'; break; } diff --git a/ngrep.h b/ngrep.h @@ -56,13 +56,6 @@ #define WORD_REGEX "((^%s\\W)|(\\W%s$)|(\\W%s\\W))" -/* - * Single-char packet "ident" flags. - */ -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 *);