Skip to content

Commit

Permalink
Expand integer range for various options to 32-bits -- closes #3
Browse files Browse the repository at this point in the history
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
  • Loading branch information
haguenau authored and jpiccari committed Sep 14, 2015
1 parent a39256b commit 33e7076
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ngrep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -232,17 +233,20 @@ 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;
case 'I':
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':
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions ngrep.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 33e7076

Please sign in to comment.