Changeset d4336d5 for tools/tracereport/port_report.c
- Timestamp:
- 02/21/07 14:39:26 (15 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- 09be643
- Parents:
- c14602f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/tracereport/port_report.c
ra7282fb rd4336d5 8 8 #include "tracereport.h" 9 9 #include "contain.h" 10 #include "report.h"11 10 12 stat_t ports[ 256][65536]={{{0,0}}};11 stat_t ports[4][256][65536]={{{{0,0}}}}; 13 12 char protn[256]={0}; 13 static bool suppress[4] = {true,true,true,true}; 14 14 15 15 void port_per_packet(struct libtrace_packet_t *packet) … … 17 17 uint8_t proto; 18 18 int port; 19 19 int dir = trace_get_direction(packet); 20 if(dir < 0 || dir > 1) 21 dir = 2; 20 22 if(trace_get_transport(packet,&proto,NULL)==NULL) 21 23 return; … … 27 29 : trace_get_destination_port(packet); 28 30 29 ports[ proto][port].bytes+=trace_get_wire_length(packet);30 ports[ proto][port].count++;31 ports[dir][proto][port].bytes+=trace_get_wire_length(packet); 32 ports[dir][proto][port].count++; 31 33 protn[proto]=1; 34 suppress[dir] = false; 32 35 } 33 36 34 static void port_port(int i,char *prot, int j) 37 void port_suppress() 38 { 39 int i; 40 printf("%-20s","Direction:"); 41 //printf("%20s", " "); 42 for(i=0;i<4;i++){ 43 if(!suppress[i]){ 44 switch(i){ 45 case 0: 46 printf("\t%24s", "Outbound "); 47 break; 48 case 1: 49 printf("\t%24s", "Inbound "); 50 break; 51 case 2: 52 printf("\t%24s", "Undefined "); 53 break; 54 default: 55 break; 56 } 57 } 58 } 59 printf("\n"); 60 printf("%-20s","Port"); 61 for(i=0;i<4;i++){ 62 if(!suppress[i]){ 63 printf("\t%12s\t%12s", "bytes","packets"); 64 } 65 } 66 printf("\n"); 67 } 68 69 void port_port(int i,char *prot, int j) 35 70 { 36 71 struct servent *ent = getservbyport(htons(j),prot); 37 if(ent) 38 printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n", 39 ent->s_name, 40 ports[i][j].bytes, 41 ports[i][j].count 72 int k; 73 74 if(ent){ 75 printf("%20s:",ent->s_name); 76 for(k=0;k<4;k++){ 77 if (ports[k][i][j].count==0){ 78 if(!suppress[k]) 79 printf("\t%24s"," "); 80 continue; 81 } 82 printf("\t%12" PRIu64 "\t%12" PRIu64, 83 ports[k][i][j].bytes, 84 ports[k][i][j].count 42 85 ); 43 else 44 printf("%20i:\t%12" PRIu64 "\t%12" PRIu64 "\n", 45 j, 46 ports[i][j].bytes, 47 ports[i][j].count 86 } 87 } 88 else{ 89 printf("%20i:",j); 90 for(k=0;k<4;k++){ 91 if (ports[k][i][j].count==0){ 92 if(!suppress[k]) 93 printf("\t%24s"," "); 94 continue; 95 } 96 printf("\t%12" PRIu64 "\t%12" PRIu64, 97 ports[k][i][j].bytes, 98 ports[k][i][j].count 48 99 ); 100 } 101 } 102 printf("\n"); 49 103 } 50 104 51 staticvoid port_protocol(int i)105 void port_protocol(int i) 52 106 { 53 int j ;107 int j,k; 54 108 struct protoent *ent = getprotobynumber(i); 55 109 printf("Protocol: %i %s%s%s\n",i, 56 110 ent?"(":"",ent?ent->p_name:"",ent?")":""); 57 111 for(j=0;j<65536;++j) { 58 if (ports[i][j].count) { 59 port_port(i,ent?ent->p_name:"",j); 112 for(k=0;k<4;k++){ 113 if (ports[k][i][j].count) { 114 port_port(i,ent?ent->p_name:"",j); 115 break; 116 } 60 117 } 61 118 } … … 66 123 int i; 67 124 printf("# Port breakdown:\n"); 68 p rintf("%-20s \t%12s\t%12s\n","Port","Bytes","Packets");125 port_suppress(); 69 126 setservent(1); 70 127 setprotoent(1); … … 76 133 endprotoent(); 77 134 endservent(); 135 136 int total, j,k; 137 for(i=0;i<4;i++){ 138 total = 0; 139 for(j=0;j<256;j++) 140 for(k=0;k<65536;k++) 141 total += ports[i][j][k].count; 142 //printf("%s: %i\n", "Total", total); 143 } 78 144 }
Note: See TracChangeset
for help on using the changeset viewer.