FreeBSD/contrib/bsnmp/snmp_mibII/mibII.c
/**
 * Fetch the GENERIC IFMIB and update the HC counters
 */
Fetch the GENERIC IFMIB and update the HC counters
Fetch the GENERIC IFMIB and update the HC counters
static int
fetch_generic_mib(struct mibif *ifp, const struct ifmibdata *old)
{
	int name[6];
	size_t len;
	struct mibif_private *p = ifp->private;
	name[0] = CTL_NET;
	name[1] = PF_LINK;
	name[2] = NETLINK_GENERIC;
	name[3] = IFMIB_IFDATA;
	name[4] = ifp->sysindex;
	name[5] = IFDATA_GENERAL;
	len = sizeof(ifp->mib);
	if (sysctl(name, 6, &ifp->mib, &len, NULL, 0) == -1) {
		if (errno != ENOENT)
			syslog(LOG_WARNING, "sysctl(ifmib, %s) failed %m",
			    ifp->name);
		return (-1);
	}
	if (ULONG_MAX >= 0xffffffffffffffffULL) {
		p->hc_inoctets = ifp->mib.ifmd_data.ifi_ibytes;
		p->hc_outoctets = ifp->mib.ifmd_data.ifi_obytes;
		p->hc_omcasts = ifp->mib.ifmd_data.ifi_omcasts;
		p->hc_opackets = ifp->mib.ifmd_data.ifi_opackets;
		p->hc_imcasts = ifp->mib.ifmd_data.ifi_imcasts;
		p->hc_ipackets = ifp->mib.ifmd_data.ifi_ipackets;
	} else if (ULONG_MAX >= 0xffffffff) {
#define	UPDATE(HC, MIB)							\
		if (old->ifmd_data.MIB > ifp->mib.ifmd_data.MIB)	\
			p->HC += (0x100000000ULL +			\
			    ifp->mib.ifmd_data.MIB) -			\
			    old->ifmd_data.MIB;				\
		else							\
			p->HC += ifp->mib.ifmd_data.MIB -		\
			    old->ifmd_data.MIB;
		UPDATE(hc_inoctets, ifi_ibytes)
		UPDATE(hc_outoctets, ifi_obytes)
		UPDATE(hc_omcasts, ifi_omcasts)
		UPDATE(hc_opackets, ifi_opackets)
		UPDATE(hc_imcasts, ifi_imcasts)
		UPDATE(hc_ipackets, ifi_ipackets)
#undef	UPDATE
	} else
		abort();
	return (0);
}
static int fetch_generic_mib ( struct mibif * ifp , const struct ifmibdata * old ) { int name [ 6 ] ; size_t len ; struct mibif_private * p = ifp -> private ; name [ 0 ] = CTL_NET ; name [ 1 ] = PF_LINK ; name [ 2 ] = NETLINK_GENERIC ; name [ 3 ] = IFMIB_IFDATA ; name [ 4 ] = ifp -> sysindex ; name [ 5 ] = IFDATA_GENERAL ; len = sizeof ( ifp -> mib ) ; if ( sysctl ( name , 6 , & ifp -> mib , & len , NULL , 0 ) == -1 ) { if ( errno != ENOENT ) syslog ( LOG_WARNING , " " , ifp -> name ) ; return ( -1 ) ; } if ( ULONG_MAX >= 0xffffffffffffffffULL ) { p -> hc_inoctets = ifp -> mib . ifmd_data . ifi_ibytes ; p -> hc_outoctets = ifp -> mib . ifmd_data . ifi_obytes ; p -> hc_omcasts = ifp -> mib . ifmd_data . ifi_omcasts ; p -> hc_opackets = ifp -> mib . ifmd_data . ifi_opackets ; p -> hc_imcasts = ifp -> mib . ifmd_data . ifi_imcasts ; p -> hc_ipackets = ifp -> mib . ifmd_data . ifi_ipackets ; } else if ( ULONG_MAX >= 0xffffffff ) { #define UPDATE ( HC , MIB ) 							\
		if (old->ifmd_data.MIB > ifp->mib.ifmd_data.MIB)	\
			p->HC += (0x100000000ULL +			\
			    ifp->mib.ifmd_data.MIB) -			\
			    old->ifmd_data.MIB;				\
		else							\
			p->HC += ifp->mib.ifmd_data.MIB -		\
			    old->ifmd_data.MIB; UPDATE ( hc_inoctets , ifi_ibytes ) UPDATE ( hc_outoctets , ifi_obytes ) UPDATE ( hc_omcasts , ifi_omcasts ) UPDATE ( hc_opackets , ifi_opackets ) UPDATE ( hc_imcasts , ifi_imcasts ) UPDATE ( hc_ipackets , ifi_ipackets ) #undef 	UPDATE } else abort ( ) ; return ( 0 ) ; }
Fetch the GENERIC IFMIB and update the HC counters
Fetch the GENERIC IFMIB and update the HC counters
/*
	 * Assume that one of the two following compounds is optimized away
	 */