FreeBSD/sbin/atm/atmconfig/diag.c
/*
 * Fetch the list of all ATM network interfaces and their MIBs.
 */
Fetch the list of all ATM network interfaces and their MIBs.
Fetch the list of all ATM network interfaces and their MIBs .
void
diagif_fetch(void)
{
	size_t len;
	int count;
	int name[6];
	struct ifmibdata mib;
	struct ifatm_mib atm;
	int idx;
	struct diagif *d;
	while ((d = TAILQ_FIRST(&diagif_list)) != NULL) {
		if (d->vtab != NULL)
			free(d->vtab);
		TAILQ_REMOVE(&diagif_list, d, link);
		free(d);
	}
	len = sizeof(count);
	if (sysctlbyname("net.link.generic.system.ifcount", &count, &len,
	    NULL, 0) == -1)
		err(1, "ifcount");
	name[0] = CTL_NET;
	name[1] = PF_LINK;
	name[2] = NETLINK_GENERIC;
	name[3] = IFMIB_IFDATA;
	for (idx = 1; idx <= count; idx++) {
		name[4] = idx;
		name[5] = IFDATA_GENERAL;
		len = sizeof(mib);
		if (sysctl(name, 6, &mib, &len, NULL, 0) == -1)
			err(1, "interface %d: general mib", idx);
		if (mib.ifmd_data.ifi_type == IFT_ATM) {
			name[5] = IFDATA_LINKSPECIFIC;
			len = sizeof(atm);
			if (sysctl(name, 6, &atm, &len, NULL, 0) == -1)
				err(1, "interface %d: ATM mib", idx);
			d = malloc(sizeof(*d));
			if (d == NULL)
				err(1, NULL);
			bzero(d, sizeof(*d));
			d->mib = atm;
			d->index = idx;
			strcpy(d->ifname, mib.ifmd_name);
			TAILQ_INSERT_TAIL(&diagif_list, d, link);
			if (phy_fetch(d->ifname, "type", &d->phy_type,
			    sizeof(d->phy_type), 0) == 0) {
				d->phy_present = 1;
				phy_fetch(d->ifname, "loopback",
				    &d->phy_loopback,
				    sizeof(d->phy_loopback), 1);
				phy_fetch(d->ifname, "name", &d->phy_name,
				    sizeof(d->phy_name), 1);
				phy_fetch(d->ifname, "state", &d->phy_state,
				    sizeof(d->phy_state), 1);
				phy_fetch(d->ifname, "carrier", &d->phy_carrier,
				    sizeof(d->phy_carrier), 1);
			}
		}
	}
}
void diagif_fetch ( void ) { size_t len ; int count ; int name [ 6 ] ; struct ifmibdata mib ; struct ifatm_mib atm ; int idx ; struct diagif * d ; while ( ( d = TAILQ_FIRST ( & diagif_list ) ) != NULL ) { if ( d -> vtab != NULL ) free ( d -> vtab ) ; TAILQ_REMOVE ( & diagif_list , d , link ) ; free ( d ) ; } len = sizeof ( count ) ; if ( sysctlbyname ( " " , & count , & len , NULL , 0 ) == -1 ) err ( 1 , " " ) ; name [ 0 ] = CTL_NET ; name [ 1 ] = PF_LINK ; name [ 2 ] = NETLINK_GENERIC ; name [ 3 ] = IFMIB_IFDATA ; for ( idx = 1 ; idx <= count ; idx ++ ) { name [ 4 ] = idx ; name [ 5 ] = IFDATA_GENERAL ; len = sizeof ( mib ) ; if ( sysctl ( name , 6 , & mib , & len , NULL , 0 ) == -1 ) err ( 1 , " " , idx ) ; if ( mib . ifmd_data . ifi_type == IFT_ATM ) { name [ 5 ] = IFDATA_LINKSPECIFIC ; len = sizeof ( atm ) ; if ( sysctl ( name , 6 , & atm , & len , NULL , 0 ) == -1 ) err ( 1 , " " , idx ) ; d = malloc ( sizeof ( * d ) ) ; if ( d == NULL ) err ( 1 , NULL ) ; bzero ( d , sizeof ( * d ) ) ; d -> mib = atm ; d -> index = idx ; strcpy ( d -> ifname , mib . ifmd_name ) ; TAILQ_INSERT_TAIL ( & diagif_list , d , link ) ; if ( phy_fetch ( d -> ifname , " " , & d -> phy_type , sizeof ( d -> phy_type ) , 0 ) == 0 ) { d -> phy_present = 1 ; phy_fetch ( d -> ifname , " " , & d -> phy_loopback , sizeof ( d -> phy_loopback ) , 1 ) ; phy_fetch ( d -> ifname , " " , & d -> phy_name , sizeof ( d -> phy_name ) , 1 ) ; phy_fetch ( d -> ifname , " " , & d -> phy_state , sizeof ( d -> phy_state ) , 1 ) ; phy_fetch ( d -> ifname , " " , & d -> phy_carrier , sizeof ( d -> phy_carrier ) , 1 ) ; } } } }
Fetch the list of all ATM network interfaces and their MIBs.
Fetch the list of all ATM network interfaces and their MIBs .