Example #1
0
/**
 * List iterator.
 *
 * Goes through all nodes in the list and calls the callback
 * function for each node.
 * If the call back returns non-zero iteration stops.
 */
int ListForAll(DiskList* dList,ListCbFn fn,void* args) {
   ListNode* node;
   int rv=0;
   node  = ListLoadNode(dList,GetFirst(dList));
   assert(node);
   while (_O(&node->curPtr) != _O(&dList->header->head)) {
      ListNode* tmp = node;
      rv = fn(dList,node,args);
      if (rv) {
         break;
      }
      node  = ListLoadNode(dList,node->nodePtr->next);
      assert(node);
      ListNodeFree(tmp);
   }
   return rv;
}
Example #2
0
static int addr_filter(struct nl_object *obj, struct nl_object *filter)
{
	struct rtnl_addr *o = (struct rtnl_addr *) obj;
	struct rtnl_addr *f = (struct rtnl_addr *) filter;

#define REQ(F) (f->a_mask & ADDR_ATTR_##F)
#define AVAIL(F) (o->a_mask & ADDR_ATTR_##F)
#define _O(F, EXPR) (REQ(F) && (!AVAIL(F) || (EXPR)))
#define _C(F, N) (REQ(F) && (!AVAIL(F) || (o->N != f->N)))
	if (_C(IFINDEX,	   a_ifindex)					||
	    _C(FAMILY,	   a_family)					||
	    _C(SCOPE,	   a_scope)					||
	    _O(FLAGS,	   f->a_flags ^ (o->a_flags & f->a_flag_mask))	||
	    _O(LABEL,	   strcmp(o->a_label, f->a_label))		||
	    _O(PEER, 	   nl_addr_cmp(o->a_peer, f->a_peer))		||
	    _O(LOCAL,	   nl_addr_cmp(o->a_local, f->a_local))		||
	    _O(ANYCAST,	   nl_addr_cmp(o->a_anycast, f->a_anycast))	||
	    _O(MULTICAST,  nl_addr_cmp(o->a_multicast, f->a_multicast))	||
	    _O(BROADCAST,  nl_addr_cmp(o->a_bcast, f->a_bcast)))
		return 0;
#undef REQ
#undef AVAIL
#undef _O
#undef _C

	return 1;
}