Skip to content

Commit

Permalink
add '-m' (max kills) option
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan Beaufour committed Sep 27, 2012
1 parent 88d10f9 commit 60e0e5a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tcpkill.c
Expand Up @@ -25,12 +25,15 @@

int Opt_severity = DEFAULT_SEVERITY;
int pcap_off;
pcap_t *pd;
int Opt_max_kill = 0;
int kill_counter = 0;

static void
usage(void)
{
fprintf(stderr, "Version: " VERSION "\n"
"Usage: tcpkill [-i interface] [-1..9] expression\n");
"Usage: tcpkill [-i interface] [-m max kills] [-1..9] expression\n");
exit(1);
}

Expand Down Expand Up @@ -87,6 +90,11 @@ tcp_kill_cb(u_char *user, const struct pcap_pkthdr *pcap, const u_char *pkt)
(unsigned long) seq,
(unsigned long) seq);
}

++kill_counter;
if (Opt_max_kill && kill_counter >= Opt_max_kill) {
pcap_breakloop(pd);
}
}

int
Expand All @@ -98,15 +106,17 @@ main(int argc, char *argv[])
char *p, *intf, *filter, ebuf[PCAP_ERRBUF_SIZE];
char libnet_ebuf[LIBNET_ERRBUF_SIZE];
libnet_t *l;
pcap_t *pd;

intf = NULL;

while ((c = getopt(argc, argv, "i:123456789h?V")) != -1) {
while ((c = getopt(argc, argv, "i:m:123456789h?V")) != -1) {
switch (c) {
case 'i':
intf = optarg;
break;
case 'm':
Opt_max_kill = atoi(optarg);
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
p = argv[optind - 1];
Expand Down

0 comments on commit 60e0e5a

Please sign in to comment.