FreeBSD/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.c
/*
 * Get the peer hook of a hook on a given node. Skip any tee nodes in between
 */
Get the peer hook of a hook on a given node. Skip any tee nodes in between
Get the peer hook of a hook on a given node . Skip any tee nodes in between
int
ng_peer_hook_id(ng_ID_t node, const char *hook, char *peerhook)
{
	struct ng_mesg *resp;
	struct hooklist *hooklist;
	u_int i;
	int ret;
	if ((resp = ng_dialog_id(node, NGM_GENERIC_COOKIE, NGM_LISTHOOKS,
	    NULL, 0)) == NULL) {
		syslog(LOG_ERR, "get hook list: %m");
		exit(1);
	}
	hooklist = (struct hooklist *)(void *)resp->data;
	for (i = 0; i < hooklist->nodeinfo.hooks; i++)
		if (strcmp(hooklist->link[i].ourhook, hook) == 0)
			break;
	if (i == hooklist->nodeinfo.hooks) {
		free(resp);
		return (-1);
	}
	node = hooklist->link[i].nodeinfo.id;
	ret = 0;
	if (strcmp(hooklist->link[i].nodeinfo.type, "tee") == 0) {
		if (strcmp(hooklist->link[i].peerhook, "left") == 0)
			ret = ng_peer_hook_id(node, "right", peerhook);
		else if (strcmp(hooklist->link[i].peerhook, "right") == 0)
			ret = ng_peer_hook_id(node, "left", peerhook);
		else
			strcpy(peerhook, hooklist->link[i].peerhook);
	} else 
		strcpy(peerhook, hooklist->link[i].peerhook);
	free(resp);
	return (ret);
}
int ng_peer_hook_id ( ng_ID_t node , const char * hook , char * peerhook ) { struct ng_mesg * resp ; struct hooklist * hooklist ; u_int i ; int ret ; if ( ( resp = ng_dialog_id ( node , NGM_GENERIC_COOKIE , NGM_LISTHOOKS , NULL , 0 ) ) == NULL ) { syslog ( LOG_ERR , " " ) ; exit ( 1 ) ; } hooklist = ( struct hooklist * ) ( void * ) resp -> data ; for ( i = 0 ; i < hooklist -> nodeinfo . hooks ; i ++ ) if ( strcmp ( hooklist -> link [ i ] . ourhook , hook ) == 0 ) break ; if ( i == hooklist -> nodeinfo . hooks ) { free ( resp ) ; return ( -1 ) ; } node = hooklist -> link [ i ] . nodeinfo . id ; ret = 0 ; if ( strcmp ( hooklist -> link [ i ] . nodeinfo . type , " " ) == 0 ) { if ( strcmp ( hooklist -> link [ i ] . peerhook , " " ) == 0 ) ret = ng_peer_hook_id ( node , " " , peerhook ) ; else if ( strcmp ( hooklist -> link [ i ] . peerhook , " " ) == 0 ) ret = ng_peer_hook_id ( node , " " , peerhook ) ; else strcpy ( peerhook , hooklist -> link [ i ] . peerhook ) ; } else strcpy ( peerhook , hooklist -> link [ i ] . peerhook ) ; free ( resp ) ; return ( ret ) ; }
Get the peer hook of a hook on a given node.
Get the peer hook of a hook on a given node .