From: Francois-Xavier Le Bail Date: Tue, 6 May 2014 10:07:55 +0000 (+0200) Subject: Print an optional packet number in the beginning of line X-Git-Tag: tcpdump-4.6.0~32^2~1 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/ab3d424294b1daebe35c1b1b946da8f5dea1a916 Print an optional packet number in the beginning of line The new option is '--number'. --- diff --git a/netdissect.h b/netdissect.h index 250d5312..e94ca976 100644 --- a/netdissect.h +++ b/netdissect.h @@ -124,6 +124,7 @@ struct netdissect_options { int ndo_Wflag; /* recycle output files after this number of files */ int ndo_WflagChars; int ndo_Hflag; /* dissect 802.11s draft mesh standard */ + int ndo_packet_number; /* print a packet number in the beginning of line */ int ndo_suppress_default_print; /* don't use default_print() for unknown packet types */ const char *ndo_dltname; diff --git a/tcpdump.c b/tcpdump.c index fc86d32b..b08e00f1 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -675,6 +675,7 @@ static struct option longopts[] = { { "debug-filter-parser", no_argument, NULL, 'Y' }, #endif { "relinquish-privileges", required_argument, NULL, 'Z' }, + { "number", no_argument, NULL, 'z' + 1}, { NULL, 0, NULL, 0 } }; @@ -1256,6 +1257,10 @@ main(int argc, char **argv) username = strdup(optarg); break; + case 'z' + 1: + gndo->ndo_packet_number = 1; + break; + default: usage(); /* NOTREACHED */ @@ -2078,6 +2083,10 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) print_info = (struct print_info *)user; ndo = print_info->ndo; + + if(ndo->ndo_packet_number) + ND_PRINT((ndo, "%5u ", packets_captured)); + ts_print(ndo, &h->ts); /* @@ -2266,7 +2275,7 @@ usage(void) (void)fprintf(stderr, "\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n"); (void)fprintf(stderr, -"\t\t[ -i interface ]" j_FLAG_USAGE " [ -M secret ]\n"); +"\t\t[ -i interface ]" j_FLAG_USAGE " [ -M secret ] [ --number ]\n"); #ifdef HAVE_PCAP_SETDIRECTION (void)fprintf(stderr, "\t\t[ -Q in|out|inout ]\n");