source: tools/tracereport/port_report.c @ e3b0188

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since e3b0188 was e3b0188, checked in by Daniel Lawson <dlawson@…>, 16 years ago

a lot of changes for cross-compilation support

  • header ordering
  • os-specific headers
  • an lt_inttypes.h which defines PRIu64 etc for platforms that don't have them
  • removed daglegacy.h, merged with dagformat.h
  • 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);
18        if (!ip)
19                return;
20
21        int port = trace_get_server_port(ip->ip_p,
22                        trace_get_source_port(packet),
23                        trace_get_destination_port(packet))==USE_SOURCE
24                ? trace_get_source_port(packet)
25                : trace_get_destination_port(packet);
26
27
[49ce177]28        if (!MAP_FIND(protocol_tree,ip->ip_p)) {
29                MAP_INSERT(protocol_tree,ip->ip_p,MAP_INIT(cmp_int));
[d3ff1fb]30        }
[49ce177]31
32        if (!MAP_FIND(MAP_FIND(protocol_tree,ip->ip_p)->value,port)) {
33                MAP_INSERT(MAP_FIND(protocol_tree,ip->ip_p)->value,port,{0});
[d3ff1fb]34        }
[49ce177]35
36        ++MAP_FIND(MAP_FIND(protocol_tree,ip->ip_p)->value,port)->value.count;
37        MAP_FIND(MAP_FIND(protocol_tree,ip->ip_p)->value,port)->value.bytes+=trace_get_wire_length(packet);
[d3ff1fb]38}
39
[49ce177]40static MAP_VISITOR(port_visitor,int,stat_t)
[d3ff1fb]41{
[49ce177]42        struct servent *ent = getservbyport(htons(node->key),(char *)userdata);
[d3ff1fb]43        if(ent)
44                printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n",
45                                ent->s_name,
[49ce177]46                                node->value.bytes,
47                                node->value.count
[d3ff1fb]48                      );
49        else
50                printf("%20i:\t%12" PRIu64 "\t%12" PRIu64 "\n",
[49ce177]51                                node->key,
52                                node->value.bytes,
53                                node->value.count
[d3ff1fb]54                      );
55}
56
[49ce177]57static MAP_VISITOR(protocol_visitor,int,MAP(int,stat_t))
[d3ff1fb]58{
[49ce177]59        struct protoent *ent = getprotobynumber(node->key);
60        printf("Protocol: %i %s%s%s\n",node->key,
[d3ff1fb]61                        ent?"(":"",ent?ent->p_name:"",ent?")":"");
[49ce177]62        MAP_VISIT(node->value,NULL,port_visitor,NULL,(void*)(ent?ent->p_name:""));
[d3ff1fb]63}
64
65void port_report(void)
66{
67        printf("# Port breakdown:\n");
68        printf("%-20s \t%12s\t%12s\n","Port","Bytes","Packets");
69        setservent(1);
70        setprotoent(1);
[49ce177]71        MAP_VISIT(protocol_tree,NULL,protocol_visitor,NULL,NULL);
[d3ff1fb]72        endprotoent();
73        endservent();
74}
Note: See TracBrowser for help on using the repository browser.