void lcl_cache_destroy(lcl_cache * head, int *counter) { lcl_cache *alcl = head, *next; if (!alcl || !lcl_counter) return; list_safe_for(alcl, next) { lcl_cache_free(alcl); xfree(alcl); }
/* * Converts a lcl_cache struct to a set of dns answers. * Returns the number of answers added. */ int lcl_cache_to_dansws(dns_pkt *dp,lcl_cache *lc) { dns_pkt_a *dpa; int res=0; list_for(lc) { dpa=DP_ADD_ANSWER(dp); dns_a_default_fill(dp,dpa); strcpy(dpa->rdata,lc->hostname); res++; } if(lc) lcl_cache_free(lc); return res; }
/* * Converts a lcl_cache to andns data. * Returns the number of bytes writed. */ size_t lcl_cache_to_aansws(char *buf,lcl_cache *lc,int *count) { uint16_t slen; size_t ret=0; int lcount=0; lcl_cache *lcl=lc; list_for(lcl) { slen=strlen(lc->hostname); ret+=2+slen; slen=htons(slen); memcpy(buf,&slen,2); buf+=2; strcpy(buf,lc->hostname); lcount++; } *count=lcount; lcl_cache_free(lc); return ret; }