FreeBSD/contrib/bsnmp/snmpd/main.c
/*
 * Register an object resource and return the index (or 0 on failures)
 */
Register an object resource and return the index (or 0 on failures)
Register an object resource and return the index ( or 0 on failures )
u_int
or_register(const struct asn_oid *or, const char *descr, struct lmodule *mod)
{
	struct objres *objres, *or1;
	u_int idx;
	idx = 1;
	for (objres = TAILQ_FIRST(&objres_list);
	     objres != NULL;
	     objres = TAILQ_NEXT(objres, link)) {
		if ((or1 = TAILQ_NEXT(objres, link)) == NULL ||
		    or1->index > objres->index + 1) {
			idx = objres->index + 1;
			break;
		}
	}
	if ((objres = malloc(sizeof(*objres))) == NULL)
		return (0);
	objres->index = idx;
	objres->oid = *or;
	strlcpy(objres->descr, descr, sizeof(objres->descr));
	objres->uptime = (uint32_t)(get_ticks() - start_tick);
	objres->module = mod;
	INSERT_OBJECT_INT(objres, &objres_list);
	systemg.or_last_change = objres->uptime;
	return (idx);
}
u_int or_register ( const struct asn_oid * or , const char * descr , struct lmodule * mod ) { struct objres * objres , * or1 ; u_int idx ; idx = 1 ; for ( objres = TAILQ_FIRST ( & objres_list ) ; objres != NULL ; objres = TAILQ_NEXT ( objres , link ) ) { if ( ( or1 = TAILQ_NEXT ( objres , link ) ) == NULL || or1 -> index > objres -> index + 1 ) { idx = objres -> index + 1 ; break ; } } if ( ( objres = malloc ( sizeof ( * objres ) ) ) == NULL ) return ( 0 ) ; objres -> index = idx ; objres -> oid = * or ; strlcpy ( objres -> descr , descr , sizeof ( objres -> descr ) ) ; objres -> uptime = ( uint32_t ) ( get_ticks ( ) - start_tick ) ; objres -> module = mod ; INSERT_OBJECT_INT ( objres , & objres_list ) ; systemg . or_last_change = objres -> uptime ; return ( idx ) ; }
Register an object resource and return the index (or 0 on failures)
Register an object resource and return the index ( or 0 on failures )
/* find a free index */