void coms_test()
{
   IF_SET set;
   uint8_t ifaces=0;
   comBuf *recvd;
   com_mode(IFACE_SERIAL, IF_LISTEN);

#ifdef PLATFORM_LINUX
   com_mode(IFACE_TERMINAL, IF_LISTEN);
#else
   com_mode(IFACE_RADIO, IF_LISTEN);
#endif

   
   while(1){
      IF_ZERO(&set);

    
      IF_SET(IFACE_SERIAL, &set);

#ifdef PLATFORM_LINUX
      IF_SET(IFACE_TERMINAL, &set);
#else
      IF_SET(IFACE_RADIO, &set);
#endif
      
      ifaces = com_select(&set,2000);
      
      if(IF_ISSET(IFACE_SERIAL, &set)){
	 printf("serial brought us back\n");
	 recvd = com_recv(IFACE_SERIAL);
	 com_free_buf(recvd);
      }
#ifdef PLATFORM_LINUX
      else if(IF_ISSET(IFACE_TERMINAL, &set)){
	 printf("terminal brought us back\n");
	 recvd = com_recv(IFACE_TERMINAL);
	 com_free_buf(recvd);
      }
#else
      else if(IF_ISSET(IFACE_RADIO, &set)){
	 printf("radio brought us back\n");
	 recvd = com_recv(IFACE_RADIO);

	 printf("[%C-%C]", recvd->data[0], recvd->data[recvd->size-1]);
	 com_free_buf(recvd);
      } 
#endif
      else {
	 printf("timed out, returned %d ifaces\n",ifaces);
      }
     
   }
}
示例#2
0
文件: mroute6.c 项目: MarginC/kame
void
mroute6pr(u_long mfcaddr, u_long mifaddr)
{
    struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
    struct mif6 mif6table[MAXMIFS];
    struct mf6c mfc;
    struct rtdetq rte, *rtep;
    struct mif6 *mifp;
    mifi_t mifi;
    int i;
    int banner_printed;
    int saved_numeric_addr;
    mifi_t maxmif = 0;
    long int waitings;

    if (mfcaddr == 0 || mifaddr == 0) {
        printf("No IPv6 multicast routing compiled into this"
               " system.\n");
        return;
    }

    saved_numeric_addr = numeric_addr;
    numeric_addr = 1;

    if (kread(mifaddr, (char *)&mif6table, sizeof(mif6table)))
        return;
    banner_printed = 0;
    for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
        struct ifnet ifnet;
        char ifname[IFNAMSIZ];

        if (mifp->m6_ifp == NULL)
            continue;

        if (kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet)))
            return;
        maxmif = mifi;
        if (!banner_printed) {
            printf("\nIPv6 Multicast Interface Table\n"
                   " Mif   Rate   PhyIF   "
                   "Pkts-In   Pkts-Out\n");
            banner_printed = 1;
        }

        printf("  %2u   %4d",
               mifi, mifp->m6_rate_limit);
        printf("   %5s", (mifp->m6_flags & MIFF_REGISTER) ?
               "reg0" : if_indextoname(ifnet.if_index, ifname));

        printf(" %9llu  %9llu\n", (unsigned long long)mifp->m6_pkt_in,
               (unsigned long long)mifp->m6_pkt_out);
    }
    if (!banner_printed)
        printf("\nIPv6 Multicast Interface Table is empty\n");

    if (kread(mfcaddr, (char *)&mf6ctable, sizeof(mf6ctable)))
        return;
    banner_printed = 0;
    for (i = 0; i < MF6CTBLSIZ; ++i) {
        mfcp = mf6ctable[i];
        while(mfcp) {
            if (kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)))
                return;
            if (!banner_printed) {
                printf ("\nIPv6 Multicast Forwarding Cache\n");
                printf(" %-*.*s %-*.*s %s",
                       WID_ORG, WID_ORG, "Origin",
                       WID_GRP, WID_GRP, "Group",
                       "  Packets Waits In-Mif  Out-Mifs\n");
                banner_printed = 1;
            }

            printf(" %-*.*s", WID_ORG, WID_ORG,
                   routename6(&mfc.mf6c_origin));
            printf(" %-*.*s", WID_GRP, WID_GRP,
                   routename6(&mfc.mf6c_mcastgrp));
            printf(" %9llu", (unsigned long long)mfc.mf6c_pkt_cnt);

            for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
                waitings++;
                if (kread((u_long)rtep, (char *)&rte, sizeof(rte)))
                    return;
                rtep = rte.next;
            }
            printf("   %3ld", waitings);

            if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT)
                printf(" ---   ");
            else
                printf("  %3d   ", mfc.mf6c_parent);
            for (mifi = 0; mifi <= maxmif; mifi++) {
                if (IF_ISSET(mifi, &mfc.mf6c_ifset))
                    printf(" %u", mifi);
            }
            printf("\n");

            mfcp = mfc.mf6c_next;
        }
    }
    if (!banner_printed)
        printf("\nIPv6 Multicast Routing Table is empty\n");

    printf("\n");
    numeric_addr = saved_numeric_addr;
}
示例#3
0
void
mroute6pr()
{
	struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
	struct mif6_sctl mif6table[MAXMIFS];
	struct mf6c mfc;
	struct rtdetq rte, *rtep;
	struct mif6_sctl *mifp;
	mifi_t mifi;
	int i;
	int banner_printed;
	int saved_numeric_addr;
	mifi_t maxmif = 0;
	long int waitings;
	size_t len;

	if (live == 0)
		return;

	len = sizeof(mif6table);
	if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len, NULL, 0) <
	    0) {
		xo_warn("sysctl: net.inet6.ip6.mif6table");
		return;
	}

	saved_numeric_addr = numeric_addr;
	numeric_addr = 1;
	banner_printed = 0;

	for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
		char ifname[IFNAMSIZ];

		if (mifp->m6_ifp == 0)
			continue;

		maxmif = mifi;
		if (!banner_printed) {
			xo_open_list("multicast-interface");
			xo_emit("\n{T:IPv6 Multicast Interface Table}\n"
			    "{T: Mif   Rate   PhyIF   Pkts-In   Pkts-Out}\n");
			banner_printed = 1;
		}

		xo_open_instance("multicast-interface");
		xo_emit("  {:mif/%2u}   {:rate-limit/%4d}",
		    mifi, mifp->m6_rate_limit);
		xo_emit("   {:ifname/%5s}", (mifp->m6_flags & MIFF_REGISTER) ?
		    "reg0" : if_indextoname(mifp->m6_ifp, ifname));

		xo_emit(" {:received-packets/%9ju}  {:sent-packets/%9ju}\n",
		    (uintmax_t)mifp->m6_pkt_in,
		    (uintmax_t)mifp->m6_pkt_out);
		xo_close_instance("multicast-interface");
	}
	if (banner_printed)
		xo_open_list("multicast-interface");
	else
		xo_emit("\n{T:IPv6 Multicast Interface Table is empty}\n");

	len = sizeof(mf6ctable);
	if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len, NULL, 0) <
	    0) {
		xo_warn("sysctl: net.inet6.ip6.mf6ctable");
		return;
	}

	banner_printed = 0;

	for (i = 0; i < MF6CTBLSIZ; ++i) {
		mfcp = mf6ctable[i];
		while(mfcp) {
			kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
			if (!banner_printed) {
				xo_open_list("multicast-forwarding-cache");
				xo_emit("\n"
				    "{T:IPv6 Multicast Forwarding Cache}\n");
				xo_emit(" {T:%-*.*s} {T:%-*.*s} {T:%s}",
				    WID_ORG, WID_ORG, "Origin",
				    WID_GRP, WID_GRP, "Group",
				    "  Packets Waits In-Mif  Out-Mifs\n");
				banner_printed = 1;
			}

			xo_open_instance("multicast-forwarding-cache");

			xo_emit(" {:origin/%-*.*s}", WID_ORG, WID_ORG,
			    routename(sin6tosa(&mfc.mf6c_origin),
			    numeric_addr));
			xo_emit(" {:group/%-*.*s}", WID_GRP, WID_GRP,
			    routename(sin6tosa(&mfc.mf6c_mcastgrp),
			    numeric_addr));
			xo_emit(" {:total-packets/%9ju}",
			    (uintmax_t)mfc.mf6c_pkt_cnt);

			for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
				waitings++;
				/* XXX KVM */
				kread((u_long)rtep, (char *)&rte, sizeof(rte));
				rtep = rte.next;
			}
			xo_emit("   {:waitings/%3ld}", waitings);

			if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT)
				xo_emit(" ---   ");
			else
				xo_emit("  {:parent/%3d}   ", mfc.mf6c_parent);
			xo_open_list("mif");
			for (mifi = 0; mifi <= maxmif; mifi++) {
				if (IF_ISSET(mifi, &mfc.mf6c_ifset))
					xo_emit(" {l:%u}", mifi);
			}
			xo_close_list("mif");
			xo_emit("\n");

			mfcp = mfc.mf6c_next;
			xo_close_instance("multicast-forwarding-cache");
		}
	}
	if (banner_printed)
		xo_close_list("multicast-forwarding-cache");
	else
		xo_emit("\n{T:IPv6 Multicast Forwarding Table is empty}\n");

	xo_emit("\n");
	numeric_addr = saved_numeric_addr;
}
示例#4
0
void
mroute6pr(u_long mfcaddr, u_long mifaddr)
{
	int banner_printed, saved_nflag, waitings, i;
	struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
	struct mif6 mif6table[MAXMIFS], *mifp;
	struct rtdetq rte, *rtep;
	mifi_t maxmif = 0, mifi;
	struct mf6c mfc;
	u_int mrtproto;
	int mib[] = { CTL_NET, AF_INET6, IPPROTO_IPV6, IPV6CTL_MRTPROTO };
	size_t len = sizeof(int);

	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]),
	    &mrtproto, &len, NULL, 0) == -1) {
		if (errno != ENOPROTOOPT)
			warn("mroute");
		return;
	}
	switch (mrtproto) {
	case 0:
		printf("no IPv6 multicast routing compiled into this system\n");
		return;
	case IPPROTO_PIM:
		break;
	default:
		printf("IPv6 multicast routing protocol %u, unknown\n",
		    mrtproto);
		return;
	}

	if (mfcaddr == 0) {
		printf("mf6ctable: symbol not in namelist\n");
		return;
	}
	if (mifaddr == 0) {
		printf("miftable: symbol not in namelist\n");
		return;
	}

	saved_nflag = nflag;
	nflag = 1;

	kread(mifaddr, &mif6table, sizeof(mif6table));
	banner_printed = 0;
	for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
		struct ifnet ifnet;
		char ifname[IFNAMSIZ];

		if (mifp->m6_ifp == NULL)
			continue;

		kread((u_long)mifp->m6_ifp, &ifnet, sizeof(ifnet));
		maxmif = mifi;
		if (!banner_printed) {
			printf("\nIPv6 Multicast Interface Table\n"
			    " Mif   Rate   PhyIF   "
			    "Pkts-In   Pkts-Out\n");
			banner_printed = 1;
		}

		printf("  %2u   %4d",
		    mifi, mifp->m6_rate_limit);
		printf("   %5s", (mifp->m6_flags & MIFF_REGISTER) ?
		    "reg0" : if_indextoname(ifnet.if_index, ifname));

		printf(" %9llu  %9llu\n", mifp->m6_pkt_in, mifp->m6_pkt_out);
	}
	if (!banner_printed)
		printf("IPv6 Multicast Interface Table is empty\n");

	kread(mfcaddr, &mf6ctable, sizeof(mf6ctable));
	banner_printed = 0;
	for (i = 0; i < MF6CTBLSIZ; ++i) {
		mfcp = mf6ctable[i];
		while (mfcp) {
			kread((u_long)mfcp, &mfc, sizeof(mfc));
			if (!banner_printed) {
				printf("\nIPv6 Multicast Forwarding Cache\n");
				printf(" %-*.*s %-*.*s %s",
				    WID_ORG, WID_ORG, "Origin",
				    WID_GRP, WID_GRP, "Group",
				    "  Packets Waits In-Mif  Out-Mifs\n");
				banner_printed = 1;
			}

			printf(" %-*.*s", WID_ORG, WID_ORG,
			    routename6(&mfc.mf6c_origin));
			printf(" %-*.*s", WID_GRP, WID_GRP,
			    routename6(&mfc.mf6c_mcastgrp));
			printf(" %9llu", mfc.mf6c_pkt_cnt);

			for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
				waitings++;
				kread((u_long)rtep, &rte, sizeof(rte));
				rtep = rte.next;
			}
			printf("   %3d", waitings);

			if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT)
				printf("  ---   ");
			else
				printf("  %3d   ", mfc.mf6c_parent);
			for (mifi = 0; mifi <= MAXMIFS; mifi++) {
				if (IF_ISSET(mifi, &mfc.mf6c_ifset))
					printf(" %u", mifi);
			}
			printf("\n");

			mfcp = mfc.mf6c_next;
		}
	}
	if (!banner_printed)
		printf("IPv6 Multicast Routing Table is empty");

	printf("\n");
	nflag = saved_nflag;
}
示例#5
0
void
mroute6pr()
{
	struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
	struct mif6 mif6table[MAXMIFS];
	struct mf6c mfc;
	struct rtdetq rte, *rtep;
	struct mif6 *mifp;
	u_long mfcaddr, mifaddr;
	mifi_t mifi;
	int i;
	int banner_printed;
	int saved_numeric_addr;
	mifi_t maxmif = 0;
	long int waitings;
	size_t len;

	kresolve_list(mrl);
	mfcaddr = mrl[N_MF6CTABLE].n_value;
	mifaddr = mrl[N_MIF6TABLE].n_value;

	if (mfcaddr == 0 || mifaddr == 0) {
		fprintf(stderr, "No IPv6 MROUTING kernel support.\n");
		return;
	}

	len = sizeof(mif6table);
	if (live) {
		if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len,
		    NULL, 0) < 0) {
			warn("sysctl: net.inet6.ip6.mif6table");
			return;
		}
	} else
		kread(mifaddr, (char *)mif6table, sizeof(mif6table));

	saved_numeric_addr = numeric_addr;
	numeric_addr = 1;
	banner_printed = 0;

	for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
		struct ifnet ifnet;
		char ifname[IFNAMSIZ];

		if (mifp->m6_ifp == NULL)
			continue;

		/* XXX KVM */
		kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));

		maxmif = mifi;
		if (!banner_printed) {
			printf("\nIPv6 Multicast Interface Table\n"
			       " Mif   Rate   PhyIF   "
			       "Pkts-In   Pkts-Out\n");
			banner_printed = 1;
		}

		printf("  %2u   %4d",
		       mifi, mifp->m6_rate_limit);
		printf("   %5s", (mifp->m6_flags & MIFF_REGISTER) ?
		       "reg0" : if_indextoname(ifnet.if_index, ifname));

		printf(" %9ju  %9ju\n", (uintmax_t)mifp->m6_pkt_in,
		    (uintmax_t)mifp->m6_pkt_out);
	}
	if (!banner_printed)
		printf("\nIPv6 Multicast Interface Table is empty\n");

	len = sizeof(mf6ctable);
	if (live) {
		if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len,
		    NULL, 0) < 0) {
			warn("sysctl: net.inet6.ip6.mf6ctable");
			return;
		}
	} else
		kread(mfcaddr, (char *)mf6ctable, sizeof(mf6ctable));

	banner_printed = 0;

	for (i = 0; i < MF6CTBLSIZ; ++i) {
		mfcp = mf6ctable[i];
		while(mfcp) {
			kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
			if (!banner_printed) {
				printf ("\nIPv6 Multicast Forwarding Cache\n");
				printf(" %-*.*s %-*.*s %s",
				       WID_ORG, WID_ORG, "Origin",
				       WID_GRP, WID_GRP, "Group",
				       "  Packets Waits In-Mif  Out-Mifs\n");
				banner_printed = 1;
			}

			printf(" %-*.*s", WID_ORG, WID_ORG,
			       routename6(&mfc.mf6c_origin));
			printf(" %-*.*s", WID_GRP, WID_GRP,
			       routename6(&mfc.mf6c_mcastgrp));
			printf(" %9ju", (uintmax_t)mfc.mf6c_pkt_cnt);

			for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
				waitings++;
				/* XXX KVM */
				kread((u_long)rtep, (char *)&rte, sizeof(rte));
				rtep = rte.next;
			}
			printf("   %3ld", waitings);

			if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT)
				printf(" ---   ");
			else
				printf("  %3d   ", mfc.mf6c_parent);
			for (mifi = 0; mifi <= maxmif; mifi++) {
				if (IF_ISSET(mifi, &mfc.mf6c_ifset))
					printf(" %u", mifi);
			}
			printf("\n");

			mfcp = mfc.mf6c_next;
		}
	}
	if (!banner_printed)
		printf("\nIPv6 Multicast Forwarding Table is empty\n");

	printf("\n");
	numeric_addr = saved_numeric_addr;
}