Ejemplo n.º 1
0
/*
 * Print routing tables.
 */
void
show_route_statistic()
{

    struct radix_node_head *rnh, *head;
    int i;

    printf("Routing tables\n");

    if (Aflag == 0 && NewTree)
        ntreestuff();
    else
    {
        //kget(rtree, rt_tables);
        for (i = 0; i <= AF_MAX; i++)
        {
            if ((rnh = rt_tables[i]) == 0)
                continue;
            //kget(rnh, head);
            head = rnh;
            if (i == AF_UNSPEC)
            {
                if (Aflag && af == 0)
                {
                    printf("Netmasks:\n");
                    p_tree(head->rnh_treetop);
                }
            }
            else if (af == AF_UNSPEC || af == i)
            {
                size_cols(i, head->rnh_treetop);
                pr_family(i);
                do_rtent = 1;
                pr_rthdr(i);
                p_tree(head->rnh_treetop);
            }
        }
    }
}
Ejemplo n.º 2
0
Archivo: route.c Proyecto: MarginC/kame
/*
 * Print routing tables.
 */
void
routepr(u_long rtree)
{
	struct radix_node_head *rnh, head;
	int i;

	printf("Routing tables\n");

	if (Aflag == 0 && NewTree)
		ntreestuff();
	else {
		if (rtree == 0) {
			printf("rt_tables: symbol not in namelist\n");
			return;
		}

		kget(rtree, rt_tables);
		for (i = 0; i <= AF_MAX; i++) {
			if ((rnh = rt_tables[i]) == 0)
				continue;
			kget(rnh, head);
			if (i == AF_UNSPEC) {
				if (Aflag && af == 0) {
					printf("Netmasks:\n");
					p_tree(head.rnh_treetop);
				}
			} else if (af == AF_UNSPEC || af == i) {
				size_cols(i, head.rnh_treetop);
				pr_family(i);
				do_rtent = 1;
				pr_rthdr(i);
				p_tree(head.rnh_treetop);
			}
		}
	}
}
Ejemplo n.º 3
0
/*
 * Print routing tables.
 */
void
routepr(u_long rtree)
{
	struct radix_node_head **rnhp, *rnh, head;
	size_t intsize;
	int fam, fibnum, numfibs;

	intsize = sizeof(int);
	if (sysctlbyname("net.my_fibnum", &fibnum, &intsize, NULL, 0) == -1)
		fibnum = 0;
	if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1)
		numfibs = 1;
	rt_tables = calloc(numfibs * (AF_MAX+1),
	    sizeof(struct radix_node_head *));
	if (rt_tables == NULL)
		err(EX_OSERR, "memory allocation failed");
	/*
	 * Since kernel & userland use different timebase
	 * (time_uptime vs time_second) and we are reading kernel memory
	 * directly we should do rt_rmx.rmx_expire --> expire_time conversion.
	 */
	if (clock_gettime(CLOCK_UPTIME, &uptime) < 0)
		err(EX_OSERR, "clock_gettime() failed");

	printf("Routing tables\n");

	if (Aflag == 0 && NewTree)
		ntreestuff();
	else {
		if (rtree == 0) {
			printf("rt_tables: symbol not in namelist\n");
			return;
		}

		if (kread((u_long)(rtree), (char *)(rt_tables), (numfibs *
		    (AF_MAX+1) * sizeof(struct radix_node_head *))) != 0)
			return;
		for (fam = 0; fam <= AF_MAX; fam++) {
			int tmpfib;

			switch (fam) {
			case AF_INET6:
			case AF_INET:
				tmpfib = fibnum;
				break;
			default:
				tmpfib = 0;
			}
			rnhp = (struct radix_node_head **)*rt_tables;
			/* Calculate the in-kernel address. */
			rnhp += tmpfib * (AF_MAX+1) + fam;
			/* Read the in kernel rhn pointer. */
			if (kget(rnhp, rnh) != 0)
				continue;
			if (rnh == NULL)
				continue;
			/* Read the rnh data. */
			if (kget(rnh, head) != 0)
				continue;
			if (fam == AF_UNSPEC) {
				if (Aflag && af == 0) {
					printf("Netmasks:\n");
					p_tree(head.rnh_treetop);
				}
			} else if (af == AF_UNSPEC || af == fam) {
				size_cols(fam, head.rnh_treetop);
				pr_family(fam);
				do_rtent = 1;
				pr_rthdr(fam);
				p_tree(head.rnh_treetop);
			}
		}
	}
}