source: tools/tracereport/port_report.c @ c3e6e47

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since c3e6e47 was c3e6e47, checked in by Perry Lorier <perry@…>, 16 years ago

Update to support libtrace3, also fix (minor) warnings where possible!

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[d3ff1fb]1#include <netdb.h>
2#include <inttypes.h>
[e3b0188]3#include <lt_inttypes.h>
[d3ff1fb]4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include "libtrace.h"
8#include "tracereport.h"
[49ce177]9#include "contain.h"
[d3ff1fb]10
[49ce177]11CMP(cmp_int,int,a-b)
12MAP(int,MAP(int,stat_t)) protocol_tree = MAP_INIT(cmp_int);
[d3ff1fb]13
14
15void port_per_packet(struct libtrace_packet_t *packet)
16{
17        struct libtrace_ip *ip = trace_get_ip(packet);
[c3e6e47]18        int port;
[d3ff1fb]19        if (!ip)
20                return;
21
[c3e6e47]22        port = trace_get_server_port(ip->ip_p,
[d3ff1fb]23                        trace_get_source_port(packet),
24                        trace_get_destination_port(packet))==USE_SOURCE
25                ? trace_get_source_port(packet)
26                : trace_get_destination_port(packet);
27
28
[49ce177]29        if (!MAP_FIND(protocol_tree,ip->ip_p)) {
30                MAP_INSERT(protocol_tree,ip->ip_p,MAP_INIT(cmp_int));
[d3ff1fb]31        }
[49ce177]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});
[d3ff1fb]35        }
[49ce177]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);
[d3ff1fb]39}
40
[49ce177]41static MAP_VISITOR(port_visitor,int,stat_t)
[d3ff1fb]42{
[49ce177]43        struct servent *ent = getservbyport(htons(node->key),(char *)userdata);
[d3ff1fb]44        if(ent)
45                printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n",
46                                ent->s_name,
[49ce177]47                                node->value.bytes,
48                                node->value.count
[d3ff1fb]49                      );
50        else
51                printf("%20i:\t%12" PRIu64 "\t%12" PRIu64 "\n",
[49ce177]52                                node->key,
53                                node->value.bytes,
54                                node->value.count
[d3ff1fb]55                      );
56}
57
[49ce177]58static MAP_VISITOR(protocol_visitor,int,MAP(int,stat_t))
[d3ff1fb]59{
[49ce177]60        struct protoent *ent = getprotobynumber(node->key);
61        printf("Protocol: %i %s%s%s\n",node->key,
[d3ff1fb]62                        ent?"(":"",ent?ent->p_name:"",ent?")":"");
[49ce177]63        MAP_VISIT(node->value,NULL,port_visitor,NULL,(void*)(ent?ent->p_name:""));
[d3ff1fb]64}
65
66void port_report(void)
67{
68        printf("# Port breakdown:\n");
69        printf("%-20s \t%12s\t%12s\n","Port","Bytes","Packets");
70        setservent(1);
71        setprotoent(1);
[49ce177]72        MAP_VISIT(protocol_tree,NULL,protocol_visitor,NULL,NULL);
[d3ff1fb]73        endprotoent();
74        endservent();
75}
Note: See TracBrowser for help on using the repository browser.