ng-eiface.c
int
lowest_hook(int ngs, const char *bridge)
{
	int		rc, idx;
	struct ng_mesg	*resp;
	struct hooklist *hlist;
	struct nodeinfo	*ninfo;

	/* Makefile generates same number strings in LinkMap */
	int		avail[NG_BRIDGE_MAX_LINKS] = {0};

	rc = NgSendMsg(ngs, bridge, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, NULL, 0);
	if (-1 == rc) return (-1);
	if (-1 == NgAllocRecvMsg(ngs, &resp, NULL)) return (-1);

	hlist = (struct hooklist *) resp->data;
	ninfo = &hlist->nodeinfo;

	/*
	 * because we have no order guarantee we scan through all existing
	 * links to see what is taken. The links are called `link<x>` where
	 * X is a zero based index into LinkMap.
	 */
	for (idx = 0; idx < ninfo->hooks; idx++) {
		struct linkinfo *const link = &hlist->link[idx];
		const char *key = link->ourhook + sizeof("link") - 1;
		sscanf(key, "%d", &rc);
		avail[rc] = 1;
	}	
	free(resp);
	/* accounted for all links */

	/* return first one avaiable or leave result as NULL */
	for (idx = 0; idx < NG_BRIDGE_MAX_LINKS; idx++) {
		if (0 == avail[idx])
			return (idx);
	}
	return (-1);
}
/*
 * return -1 if nothing available or err, otherwise return id that can be used.
 */
1 if nothing available or err, otherwise return id that can be used.
1 if nothing available or err otherwise return id that can be used .
int
lowest_hook(int ngs, const char *bridge)
{
	int		rc, idx;
	struct ng_mesg	*resp;
	struct hooklist *hlist;
	struct nodeinfo	*ninfo;
	int		avail[NG_BRIDGE_MAX_LINKS] = {0};
	rc = NgSendMsg(ngs, bridge, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, NULL, 0);
	if (-1 == rc) return (-1);
	if (-1 == NgAllocRecvMsg(ngs, &resp, NULL)) return (-1);
	hlist = (struct hooklist *) resp->data;
	ninfo = &hlist->nodeinfo;
	for (idx = 0; idx < ninfo->hooks; idx++) {
		struct linkinfo *const link = &hlist->link[idx];
		const char *key = link->ourhook + sizeof("link") - 1;
		sscanf(key, "%d", &rc);
		avail[rc] = 1;
	}	
	free(resp);
	for (idx = 0; idx < NG_BRIDGE_MAX_LINKS; idx++) {
		if (0 == avail[idx])
			return (idx);
	}
	return (-1);
}
int lowest_hook ( int ngs , const char * bridge ) { int rc , idx ; struct ng_mesg * resp ; struct hooklist * hlist ; struct nodeinfo * ninfo ; int avail [ NG_BRIDGE_MAX_LINKS ] = { 0 } ; rc = NgSendMsg ( ngs , bridge , NGM_GENERIC_COOKIE , NGM_LISTHOOKS , NULL , 0 ) ; if ( -1 == rc ) return ( -1 ) ; if ( -1 == NgAllocRecvMsg ( ngs , & resp , NULL ) ) return ( -1 ) ; hlist = ( struct hooklist * ) resp -> data ; ninfo = & hlist -> nodeinfo ; for ( idx = 0 ; idx < ninfo -> hooks ; idx ++ ) { struct linkinfo * const link = & hlist -> link [ idx ] ; const char * key = link -> ourhook + sizeof ( " " ) - 1 ; sscanf ( key , " " , & rc ) ; avail [ rc ] = 1 ; } free ( resp ) ; for ( idx = 0 ; idx < NG_BRIDGE_MAX_LINKS ; idx ++ ) { if ( 0 == avail [ idx ] ) return ( idx ) ; } return ( -1 ) ; }
return -1 if nothing available or err, otherwise return id that can be used.
return - 1 if nothing available or err otherwise return id that can be used .
/* Makefile generates same number strings in LinkMap */ /*
	 * because we have no order guarantee we scan through all existing
	 * links to see what is taken. The links are called `link<x>` where
	 * X is a zero based index into LinkMap.
	 */ /* accounted for all links */ /* return first one avaiable or leave result as NULL */