iter_dp_is_useless(struct query_info* qinfo, uint16_t qflags,
	struct delegpt* dp, int supports_ipv4, int supports_ipv6)
{
	struct delegpt_ns* ns;
	struct delegpt_addr* a;
	/* check:
	 *      o RD qflag is on.
	 *      o no addresses are provided.
	 *      o all NS items are required glue.
	 * OR
	 *      o RD qflag is on.
	 *      o no addresses are provided.
	 *      o the query is for one of the nameservers in dp,
	 *        and that nameserver is a glue-name for this dp.
	 */
	if(!(qflags&BIT_RD))
		return 0;
	/* either available or unused targets,
	 * if they exist, the dp is not useless. */
	for(a = dp->usable_list; a; a = a->next_usable) {
		if(!addr_is_ip6(&a->addr, a->addrlen) && supports_ipv4)
			return 0;
		else if(addr_is_ip6(&a->addr, a->addrlen) && supports_ipv6)
			return 0;
	}
	for(a = dp->result_list; a; a = a->next_result) {
		if(!addr_is_ip6(&a->addr, a->addrlen) && supports_ipv4)
			return 0;
		else if(addr_is_ip6(&a->addr, a->addrlen) && supports_ipv6)
			return 0;
	}

	/* see if query is for one of the nameservers, which is glue */
	if( ((qinfo->qtype == LDNS_RR_TYPE_A && supports_ipv4) ||
		(qinfo->qtype == LDNS_RR_TYPE_AAAA && supports_ipv6)) &&
		dname_subdomain_c(qinfo->qname, dp->name) &&
		delegpt_find_ns(dp, qinfo->qname, qinfo->qname_len))
		return 1;

	for(ns = dp->nslist; ns; ns = ns->next) {
		if(ns->resolved) /* skip failed targets */
			continue;
		if(!dname_subdomain_c(ns->name, dp->name))
			return 0; /* one address is not required glue */
	}
	return 1;
}
iter_dp_is_useless(struct query_info* qinfo, uint16_t qflags,
	struct delegpt* dp, int supports_ipv4, int supports_ipv6)
{
	struct delegpt_ns* ns;
	struct delegpt_addr* a;
	 
	if(!(qflags&BIT_RD))
		return 0;
	 
	for(a = dp->usable_list; a; a = a->next_usable) {
		if(!addr_is_ip6(&a->addr, a->addrlen) && supports_ipv4)
			return 0;
		else if(addr_is_ip6(&a->addr, a->addrlen) && supports_ipv6)
			return 0;
	}
	for(a = dp->result_list; a; a = a->next_result) {
		if(!addr_is_ip6(&a->addr, a->addrlen) && supports_ipv4)
			return 0;
		else if(addr_is_ip6(&a->addr, a->addrlen) && supports_ipv6)
			return 0;
	}

	 
	if( ((qinfo->qtype == LDNS_RR_TYPE_A && supports_ipv4) ||
		(qinfo->qtype == LDNS_RR_TYPE_AAAA && supports_ipv6)) &&
		dname_subdomain_c(qinfo->qname, dp->name) &&
		delegpt_find_ns(dp, qinfo->qname, qinfo->qname_len))
		return 1;

	for(ns = dp->nslist; ns; ns = ns->next) {
		if(ns->resolved)  
			continue;
		if(!dname_subdomain_c(ns->name, dp->name))
			return 0;  
	}
	return 1;
}