Changeset 1147


Ignore:
Timestamp:
02/22/07 11:31:14 (6 years ago)
Author:
spa1
Message:

Completely re-worked the output of the tcp options report - it now writes to a file in a nice format for Python (or similar) to parse while still being human-readable, especially in 80 character terminal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/tracereport/tcpopt_report.c

    r1146 r1147  
    66#include "tracereport.h" 
    77 
    8 static stat_t tcpopt_stat[4][256] = {{{0,0}}}; 
    9 /* Suppressing things seems a little pointless to me */ 
    10 static bool suppress[4] = {true,true,true,true}; 
     8static stat_t tcpopt_stat[3][256] = {{{0,0}}}; 
    119 
    1210void tcpopt_per_packet(struct libtrace_packet_t *packet) 
     
    4038        } 
    4139         
    42         suppress[dir] = false; 
    4340} 
    4441 
    45 void tcpopt_suppress() 
    46 { 
    47         int i; 
    48         printf("%-20s","Direction:"); 
    49         for(i=0;i<4;i++){ 
    50                 if(!suppress[i]){ 
    51                         switch(i){ 
    52                                 case 0: 
    53                                         printf("\t%24s", "Outbound   "); 
    54                                         break; 
    55                                 case 1: 
    56                                         printf("\t%24s", "Inbound   "); 
    57                                         break; 
    58                                 case 2: 
    59                                         printf("\t%24s", "Undefined   "); 
    60                                         break; 
    61                                 default: 
    62                                         break; 
    63                         } 
    64                 } 
    65         } 
    66         printf("\n"); 
    67         printf("%-20s","TCP OPTIONS"); 
    68         for(i=0;i<4;i++){ 
    69                 if(!suppress[i]){ 
    70                         printf("\t%12s\t%12s", "bytes","packets"); 
    71                 } 
    72         } 
    73         printf("\n"); 
    74 } 
    7542 
    7643void tcpopt_report(void) 
    7744{ 
     45         
    7846        int i,j; 
    79         printf("# TCP OPTION breakdown:\n"); 
    80         tcpopt_suppress(); 
     47         
     48        FILE *out = fopen("tcpopt.out", "w"); 
     49        if (!out) { 
     50                perror("fopen"); 
     51                return; 
     52        } 
     53 
     54        /* Put some headings up for human-readability */ 
     55        fprintf(out, "%-12s\t%8s\t%12s\t%12s\n", 
     56                        "OPTION", 
     57                        "DIRECTION", 
     58                        "BYTES", 
     59                        "PACKETS"); 
    8160         
    8261        for(i=0;i<256;++i) { 
     
    8766                switch(i) { 
    8867                        case 1: 
    89                                 printf("%20s", "NOP: "); 
     68                                fprintf(out, "%12s", "NOP |"); 
    9069                                break; 
    9170                        case 2: 
    92                                 printf("%20s", "MSS: "); 
     71                                fprintf(out, "%12s", "MSS |"); 
    9372                                break; 
    9473                        case 3: 
    95                                 printf("%20s", "Winscale: "); 
     74                                fprintf(out, "%12s", "Winscale |"); 
    9675                                break; 
    9776                        case 4: 
    98                                 printf("%20s", "SACK Permitted: "); 
     77                                fprintf(out, "%12s", "SACK Perm |"); 
    9978                                break; 
    10079                        case 5: 
    101                                 printf("%20s", "SACK Information: "); 
     80                                fprintf(out, "%12s", "SACK Info |"); 
    10281                                break; 
    10382                        case 8: 
    104                                 printf("%20s", "Timestamp: "); 
     83                                fprintf(out, "%12s", "Timestamp |"); 
    10584                                break; 
    10685                        case 19: 
    107                                 printf("%20s", "MD5: "); 
     86                                fprintf(out, "%12s", "MD5 |"); 
    10887                        default: 
    109                                 printf("%20i:",i); 
     88                                fprintf(out, "%12i |",i); 
    11089                } 
    11190                 
    112                 for(j=0;j<4;j++){ 
    113                         if (tcpopt_stat[j][i].count==0){ 
    114                                 if(!suppress[j]) 
    115                                         printf("\t%24s"," "); 
    116                                 continue; 
     91                for(j=0;j<3;j++){ 
     92                        if (j != 0) { 
     93                                fprintf(out, "%12s", " |"); 
    11794                        } 
    118                         printf("\t%12" PRIu64 "\t%12" PRIu64, 
     95                 
     96                        switch (j) { 
     97                                case 0: 
     98                                        fprintf(out, "\t%8s", "Outbound"); 
     99                                        break; 
     100                                case 1: 
     101                                        fprintf(out, "\t%8s", "Inbound"); 
     102                                        break; 
     103                                case 2: 
     104                                        fprintf(out, "\t%8s", "Unknown"); 
     105                                        break; 
     106                        } 
     107                         
     108                        fprintf(out, "\t%12llu %12llu\n", 
    119109                                tcpopt_stat[j][i].bytes, 
    120110                                tcpopt_stat[j][i].count); 
    121111                } 
    122                 printf("\n"); 
    123112        } 
     113        fclose(out); 
    124114} 
Note: See TracChangeset for help on using the changeset viewer.