ongrep

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

commit 3c0d050784006bb98448d218a4fbabefc2b789a7
parent 8ae820c6a6eb17c249ca68bbcade54227c0802cc
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Wed, 16 Sep 2020 14:37:00 +1000

process: bool fragmented flag

Diffstat:
Mngrep.c | 18++++++++----------
Mngrep.h | 4++--
2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/ngrep.c b/ngrep.c @@ -629,7 +629,7 @@ process(UNUSED u_char *d, struct pcap_pkthdr *h, u_char *p) uint32_t ip_hl = 0; uint32_t ip_off = 0; - uint8_t fragmented = 0; + bool fragmented = false; uint16_t frag_offset = 0; uint32_t frag_id = 0; @@ -660,8 +660,9 @@ process(UNUSED u_char *d, struct pcap_pkthdr *h, u_char *p) ip_proto = ip4_pkt->ip_p; ip_off = ntohs(ip4_pkt->ip_off); - fragmented = ip_off & (IP_MF | IP_OFFMASK); - frag_offset = (fragmented) ? (ip_off & IP_OFFMASK) * 8 : 0; + fragmented = (ip_off & (IP_MF | IP_OFFMASK)) != 0; + if (fragmented) + frag_offset = (ip_off & IP_OFFMASK) * 8; frag_id = ntohs(ip4_pkt->ip_id); inet_ntop(AF_INET, &ip4_pkt->ip_src, ip_src, sizeof(ip_src)); @@ -672,17 +673,14 @@ process(UNUSED u_char *d, struct pcap_pkthdr *h, u_char *p) ip_proto = ip6_pkt->ip6_nxt; if (ip_proto == IPPROTO_FRAGMENT) { - struct ip6_frag *ip6_fraghdr; - - ip6_fraghdr = + struct ip6_frag *ip6_fraghdr = (struct ip6_frag *)((unsigned char *)ip6_pkt + ip_hl); ip_hl += sizeof(struct ip6_frag); ip_proto = ip6_fraghdr->ip6f_nxt; - fragmented = 1; - frag_offset = - ntohs(ip6_fraghdr->ip6f_offlg & IP6F_OFF_MASK); + fragmented = true; + frag_offset = ntohs(ip6_fraghdr->ip6f_offlg & IP6F_OFF_MASK); frag_id = ntohl(ip6_fraghdr->ip6f_ident); } inet_ntop(AF_INET6, &ip6_pkt->ip6_src, ip_src, sizeof(ip_src)); @@ -795,7 +793,7 @@ void dump_packet(struct pcap_pkthdr *h, u_char *p, uint8_t proto, unsigned char *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, uint8_t frag, uint16_t frag_offset, + uint16_t hdr_offset, bool frag, uint16_t frag_offset, uint32_t frag_id) { size_t match_size, match_index; diff --git a/ngrep.h b/ngrep.h @@ -76,8 +76,8 @@ void update_windowsize(int32_t); __dead void clean_exit(int); void dump_packet(struct pcap_pkthdr *, u_char *, uint8_t, unsigned char *, uint32_t, - const char *, const char *, uint16_t, uint16_t, uint8_t, - uint16_t, uint8_t, uint16_t, uint32_t); + const char *, const char *, uint16_t, uint16_t, uint8_t, + uint16_t, bool, uint16_t, uint32_t); void dump_unwrapped(unsigned char *, uint32_t, size_t, size_t); void dump_formatted(unsigned char *, uint32_t, size_t, size_t);