]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Print an optional packet number in the beginning of line
authorFrancois-Xavier Le Bail <[email protected]>
Tue, 6 May 2014 10:07:55 +0000 (12:07 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Tue, 6 May 2014 10:07:55 +0000 (12:07 +0200)
The new option is '--number'.

netdissect.h
tcpdump.c

index 250d5312f6972c5893c8f11aedbf59ee160540e4..e94ca976740f16cfe68f36293a7d73e5888f27f7 100644 (file)
@@ -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;
 
index fc86d32b4faef6e36a0d85ce09920d172321997d..b08e00f1d90943cb7b1449841592a20fed76b7fd 100644 (file)
--- 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");