ongrep

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

commit e609c03de6cf48b2948d3cd05dcd5b363e78d859
parent 0cf0ea5ebed4a09e8fdae549d32c8825e04201c3
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Sun, 14 Jun 2020 22:21:00 +1000

Replace _atoui32 macro with strtonum

Diffstat:
Mngrep.c | 26+++++++++++++++++---------
Mngrep.h | 3---
2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/ngrep.c b/ngrep.c @@ -98,6 +98,7 @@ int main(int argc, char **argv) { int c; + const char *errstr; signal(SIGINT, clean_exit); signal(SIGABRT, clean_exit); @@ -129,7 +130,9 @@ main(int argc, char **argv) nonprint_char = *optarg; break; case 'S': - limitlen = _atoui32(optarg); + limitlen = strtonum(optarg, 1, UINT32_MAX, &errstr); + if (errstr != NULL) + errx(2, "limitlen is %s: %s", errstr, optarg); break; case 'O': dump_file = optarg; @@ -138,7 +141,9 @@ main(int argc, char **argv) read_file = optarg; break; case 'A': - match_after = _atoui32(optarg); + match_after = strtonum(optarg, 1, UINT32_MAX, &errstr); + if (errstr != NULL) + errx(2, "num is %s: %s", errstr, optarg); if (match_after < UINT32_MAX) match_after++; break; @@ -146,16 +151,19 @@ main(int argc, char **argv) usedev = optarg; break; case 'c': - ws_col_forced = atoi(optarg); + ws_col_forced = strtonum(optarg, 1, UINT32_MAX, &errstr); + if (errstr != NULL) + errx(2, "cols is %s: %s", errstr, optarg); break; case 'n': - max_matches = _atoui32(optarg); + max_matches = strtonum(optarg, 1, UINT32_MAX, &errstr); + if (errstr != NULL) + errx(2, "num is %s: %s", errstr, optarg); break; - case 's':{ - uint16_t value = _atoui32(optarg); - if (value > 0) - snaplen = value; - } break; + case 's': + snaplen = strtonum(optarg, 1, UINT32_MAX, &errstr); + if (errstr != NULL) + errx(2, "snaplen is %s: %s", errstr, optarg); case 'C': enable_hilite = 1; break; diff --git a/ngrep.h b/ngrep.h @@ -27,9 +27,6 @@ ((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. *