network analyzer - first attempt
[svn/Prometheus-QoS/.git] / networks.c
CommitLineData
af37be1d 1/* Modified by: xChaos, 20131028 */
2
3#include "cll1-0.6.2.h"
4#include "ipstruct.h"
5
6#define STRLEN 512
7
8extern struct IP *ips, *networks;
9
10struct IP* find_network_for_ip(char *ipaddr_orig)
11{
12 struct IP *network;
13 char *netaddr, *lastnum, *ipaddr;
14 int ipnum, netnum;
15
16 duplicate(ipaddr_orig, ipaddr);
17 lastnum = strrchr(ipaddr, '.');
18 if(lastnum)
19 {
20 ipnum = atoi(lastnum + 1);
21 *lastnum = 0;
22 }
23
24 for_each(network, networks)
25 {
26 duplicate(network->addr, netaddr);
27 lastnum = strrchr(netaddr, '.');
28 if(lastnum)
29 {
30 netnum = atoi(lastnum + 1);
31 *lastnum = 0;
32// printf("%s/%d + %d\n",network->addr,network->mask,(1<<(32-network->mask)));
33 if( eq(netaddr, ipaddr)
34 and netnum + (1<<(32-network->mask)) > ipnum
35 and netnum <= ipnum)
36 {
37 return network;
38 }
39 }
40 }
41 return NULL;
42}
43
44void analyse_topology(char *traceroute)
45{
46 char *buf, *netaddr, *ptr, *lastnum, *str;
47 int col, gateway, netnum, tracert;
48 struct IP *network=NULL, *ip;
49
50 for_each(ip, networks)
51 {
52 printf("%s/%d %s min=%d max=%d sum=%d\n",ip->addr, ip->mask, ip->name, ip->min, ip->max, ip->desired);
53 }
54
55 /*-----------------------------------------------------------------*/
56 puts("Analysing network topology ...");
57 /*-----------------------------------------------------------------*/
58 for_each(ip, networks)
59 {
60 printf("%s/%d %s\n",ip->addr, ip->mask, ip->name);
61 duplicate(ip->addr, buf);
62 lastnum = strrchr(buf, '.');
63 if(lastnum)
64 {
65 gateway = atoi(lastnum + 1) + 1; /* this is just common rule... */
66 *lastnum = 0;
67 string(str,STRLEN);
68 sprintf(str, traceroute, buf, gateway);
69 shell(str);
70 input(str,STRLEN)
71 {
72 if( not strstr(str, "traceroute")
73 and not strstr(str, "* * *"))
74 {
75 printf("%s",str);
76 duplicate(str, buf);
77 valid_columns(ptr, buf, ' ', col)
78 if(*ptr=='*')
79 {
80 col--;
81 }
82 else if(col==2)
83 {
84 printf("via [%s]\n", ptr);
85 network = find_network_for_ip(ptr);
86 if(network)
87 {
88 network->min += ip->min;
89 network->desired += ip->max;
90 if(ip->max > network->max)
91 {
92 network->max = ip->max;
93 }
94 }
95 }
96 }
97 }
98 }
99 }
100 sort(network, networks, desc_order_by, min);
101 sort(network, networks, desc_order_by, max);
102 for_each(ip, networks)
103 {
104 printf("%s/%d %s min=%d max=%d sum=%d\n",ip->addr, ip->mask, ip->name, ip->min, ip->max, ip->desired);
105 }
106 exit(-1);
107}
This page took 0.182663 seconds and 4 git commands to generate.