1 /* Modified by: xChaos, 20131029 */
3 #include "cll1-0.6.2.h"
8 extern struct IP
*ips
, *networks
;
10 struct IP
* find_network_for_ip(char *ipaddr_orig
)
13 char *netaddr
, *lastnum
, *ipaddr
;
16 duplicate(ipaddr_orig
, ipaddr
);
17 lastnum
= strrchr(ipaddr
, '.');
20 ipnum
= atoi(lastnum
+ 1);
24 for_each(network
, networks
)
26 duplicate(network
->addr
, netaddr
);
27 lastnum
= strrchr(netaddr
, '.');
30 netnum
= atoi(lastnum
+ 1);
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
44 void analyse_topology(char *traceroute
)
46 char *buf
, *netaddr
, *ptr
, *lastnum
, *str
;
47 int col
, gateway
, netnum
, tracert
;
48 struct IP
*network
=NULL
, *ip
;
50 for_each(ip
, networks
)
52 printf("%s/%d %s min=%d max=%d sum=%d\n",ip
->addr
, ip
->mask
, ip
->name
, ip
->min
, ip
->max
, ip
->desired
);
55 /*-----------------------------------------------------------------*/
56 puts("Analysing network topology ...");
57 /*-----------------------------------------------------------------*/
58 for_each(ip
, networks
)
60 printf("%s/%d %s\n",ip
->addr
, ip
->mask
, ip
->name
);
61 duplicate(ip
->addr
, buf
);
62 lastnum
= strrchr(buf
, '.');
65 gateway
= atoi(lastnum
+ 1) + 1; /* this is just common rule... */
68 sprintf(str
, traceroute
, buf
, gateway
);
72 if( not strstr(str
, "traceroute")
73 and not strstr(str
, "* * *"))
77 valid_columns(ptr
, buf
, ' ', col
)
84 printf("via [%s]\n", ptr
);
85 network
= find_network_for_ip(ptr
);
88 network
->min
+= ip
->min
;
89 network
->desired
+= ip
->max
;
90 if(ip
->max
> network
->max
)
92 network
->max
= ip
->max
;
100 sort(network
, networks
, desc_order_by
, min
);
101 sort(network
, networks
, desc_order_by
, max
);
102 for_each(ip
, networks
)
104 printf("%s/%d %s min=%d max=%d sum=%d\n",ip
->addr
, ip
->mask
, ip
->name
, ip
->min
, ip
->max
, ip
->desired
);
This page took 2.286793 seconds and 5 git commands to generate.