FreeBSD/contrib/bsnmp/snmp_mibII/mibII.c
/*
 * Verify an interface address without fetching the entire list
 */
Verify an interface address without fetching the entire list
Verify an interface address without fetching the entire list
static int
verify_ifa(const char *name, struct mibifa *ifa)
{
	struct ifreq req;
	struct sockaddr_in *sa;
	memset(&req, 0, sizeof(req));
	strncpy(req.ifr_name, name, sizeof(req.ifr_name));
	sa = (struct sockaddr_in *)(void *)&req.ifr_addr;
	sa->sin_family = AF_INET;
	sa->sin_len = sizeof(*sa);
	sa->sin_addr = ifa->inaddr;
	if (ioctl(mib_netsock, SIOCGIFADDR, &req) == -1)
		return (-1);
	if (ifa->inaddr.s_addr != sa->sin_addr.s_addr) {
		syslog(LOG_ERR, "%s: address mismatch", __func__);
		return (-1);
	}
	if (ioctl(mib_netsock, SIOCGIFNETMASK, &req) == -1)
		return (-1);
	if (ifa->inmask.s_addr != sa->sin_addr.s_addr) {
		syslog(LOG_ERR, "%s: netmask mismatch", __func__);
		return (-1);
	}
	return (0);
}
static int verify_ifa ( const char * name , struct mibifa * ifa ) { struct ifreq req ; struct sockaddr_in * sa ; memset ( & req , 0 , sizeof ( req ) ) ; strncpy ( req . ifr_name , name , sizeof ( req . ifr_name ) ) ; sa = ( struct sockaddr_in * ) ( void * ) & req . ifr_addr ; sa -> sin_family = AF_INET ; sa -> sin_len = sizeof ( * sa ) ; sa -> sin_addr = ifa -> inaddr ; if ( ioctl ( mib_netsock , SIOCGIFADDR , & req ) == -1 ) return ( -1 ) ; if ( ifa -> inaddr . s_addr != sa -> sin_addr . s_addr ) { syslog ( LOG_ERR , " " , __func__ ) ; return ( -1 ) ; } if ( ioctl ( mib_netsock , SIOCGIFNETMASK , & req ) == -1 ) return ( -1 ) ; if ( ifa -> inmask . s_addr != sa -> sin_addr . s_addr ) { syslog ( LOG_ERR , " " , __func__ ) ; return ( -1 ) ; } return ( 0 ) ; }
Verify an interface address without fetching the entire list
Verify an interface address without fetching the entire list