Changeset 11c4044
- Timestamp:
- 05/23/06 13:23:49 (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:
- 5b4404a
- Parents:
- a472b50
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/tracereport/port_report.c
rc3e6e47 r11c4044 9 9 #include "contain.h" 10 10 11 CMP(cmp_int,int,a-b) 12 MAP(int,MAP(int,stat_t)) protocol_tree = MAP_INIT(cmp_int); 13 11 stat_t ports[256][65536]={{{0,0}}}; 12 char protn[256]={0}; 14 13 15 14 void port_per_packet(struct libtrace_packet_t *packet) 16 15 { 17 struct libtrace_ip *ip = trace_get_ip(packet);16 uint8_t proto; 18 17 int port; 19 if (!ip) 18 19 if(trace_get_transport(packet,&proto,NULL)==NULL) 20 20 return; 21 21 22 port = trace_get_server_port( ip->ip_p,22 port = trace_get_server_port(proto, 23 23 trace_get_source_port(packet), 24 24 trace_get_destination_port(packet))==USE_SOURCE … … 26 26 : trace_get_destination_port(packet); 27 27 28 29 if (!MAP_FIND(protocol_tree,ip->ip_p)) { 30 MAP_INSERT(protocol_tree,ip->ip_p,MAP_INIT(cmp_int)); 31 } 32 33 if (!MAP_FIND(MAP_FIND(protocol_tree,ip->ip_p)->value,port)) { 34 MAP_INSERT(MAP_FIND(protocol_tree,ip->ip_p)->value,port,{0}); 35 } 36 37 ++MAP_FIND(MAP_FIND(protocol_tree,ip->ip_p)->value,port)->value.count; 38 MAP_FIND(MAP_FIND(protocol_tree,ip->ip_p)->value,port)->value.bytes+=trace_get_wire_length(packet); 28 ports[proto][port].bytes+=trace_get_wire_length(packet); 29 ports[proto][port].count++; 30 protn[proto]=1; 39 31 } 40 32 41 static MAP_VISITOR(port_visitor,int,stat_t)33 void port_port(int i,char *prot, int j) 42 34 { 43 struct servent *ent = getservbyport(htons( node->key),(char *)userdata);35 struct servent *ent = getservbyport(htons(j),prot); 44 36 if(ent) 45 37 printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n", 46 38 ent->s_name, 47 node->value.bytes,48 node->value.count39 ports[i][j].bytes, 40 ports[i][j].count 49 41 ); 50 42 else 51 43 printf("%20i:\t%12" PRIu64 "\t%12" PRIu64 "\n", 52 node->key,53 node->value.bytes,54 node->value.count44 j, 45 ports[i][j].bytes, 46 ports[i][j].count 55 47 ); 56 48 } 57 49 58 static MAP_VISITOR(protocol_visitor,int,MAP(int,stat_t))50 void port_protocol(int i) 59 51 { 60 struct protoent *ent = getprotobynumber(node->key); 61 printf("Protocol: %i %s%s%s\n",node->key, 52 int j; 53 struct protoent *ent = getprotobynumber(i); 54 printf("Protocol: %i %s%s%s\n",i, 62 55 ent?"(":"",ent?ent->p_name:"",ent?")":""); 63 MAP_VISIT(node->value,NULL,port_visitor,NULL,(void*)(ent?ent->p_name:"")); 56 for(j=0;j<65536;++j) { 57 if (ports[i][j].count) { 58 port_port(i,ent?ent->p_name:"",j); 59 } 60 } 64 61 } 65 62 66 63 void port_report(void) 67 64 { 65 int i; 68 66 printf("# Port breakdown:\n"); 69 67 printf("%-20s \t%12s\t%12s\n","Port","Bytes","Packets"); 70 68 setservent(1); 71 69 setprotoent(1); 72 MAP_VISIT(protocol_tree,NULL,protocol_visitor,NULL,NULL); 70 for(i=0;i<256;++i) { 71 if (protn[i]) { 72 port_protocol(i); 73 } 74 } 73 75 endprotoent(); 74 76 endservent();
Note: See TracChangeset
for help on using the changeset viewer.