ongrep

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

commit 33e70763589ac7a9c14fe1c7cf184897924f67a0
parent a39256b7c2d3ec836a9f8b60108123325a80a213
Author: David Haguenauer <ml@kurokatta.org>
Date:   Wed,  8 Jul 2015 22:29:18 +0200

Expand integer range for various options to 32-bits -- closes #3

List of affected options:
  -A num of packets to dump after match
  -n num of packets to inspect
  -s set bpf caplen
  -S set limitlen on matched packets

Diffstat:
Mngrep.c | 18+++++++++++-------
Mngrep.h | 3+++
2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/ngrep.c b/ngrep.c @@ -104,8 +104,9 @@ * Configuration Options */ -uint16_t snaplen = 65535, limitlen = 65535, promisc = 1, to = 100; -uint16_t match_after = 0, keep_matching = 0, matches = 0, max_matches = 0; +uint32_t snaplen = 65535, limitlen = 65535, promisc = 1, to = 100; +uint32_t match_after = 0, keep_matching = 0, matches = 0, max_matches = 0; + #if USE_TCPKILL uint16_t tcpkill_active = 0; #endif @@ -232,9 +233,10 @@ int main(int argc, char **argv) { case 'P': nonprint_char = *optarg; break; - case 'S': - limitlen = atoi(optarg); + case 'S': { + limitlen = _atoui32(optarg); break; + } case 'O': dump_file = optarg; break; @@ -242,7 +244,9 @@ int main(int argc, char **argv) { read_file = optarg; break; case 'A': - match_after = atoi(optarg) + 1; + match_after = _atoui32(optarg); + if (match_after < UINT32_MAX) + match_after++; break; #if defined(_WIN32) case 'L': @@ -263,10 +267,10 @@ int main(int argc, char **argv) { ws_col_forced = atoi(optarg); break; case 'n': - max_matches = atoi(optarg); + max_matches = _atoui32(optarg); break; case 's': { - uint16_t value = atoi(optarg); + uint16_t value = _atoui32(optarg); if (value > 0) snaplen = value; } break; diff --git a/ngrep.h b/ngrep.h @@ -35,6 +35,9 @@ ((uint16_t)((uint16_t)*((const uint8_t *)(p) + 0) << 8 | \ (uint16_t)*((const uint8_t *)(p) + 1))) +#define _atoui32(p) \ + ((uint32_t)strtoul((p), (char **)NULL, 10)) + /* * Default patterns for BPF and regular expression filters. *