Trying to fetch SRV data with libunbound / libldns

Willem Toorop willem at nlnetlabs.nl
Thu May 12 14:45:40 UTC 2016


Op 12-05-16 om 16:16 schreef W.C.A. Wijngaards via Unbound-users:
> The data[i] elements contain self-contained, uncompressed, rdata
> elements that do not point to a packet somewhere.
> 
> For SRV that means there is an uncompressed domainname in there.  In
> wireformat.  LDNS can parse the rdata in data[i].

Ah yes.. that is much better, so rewriting the example:

char **data;
int *len;

for (data = res->data, len = res->len; *data; data++, len++) {
	if (*len < 7) {
		/* Handle error */
		continue;
	}
	uint16_t priority = ((*data)[0] << 8) | (*data)[1];
	uint16_t weight   = ((*data)[2] << 8) | (*data)[3];
	uint16_t port     = ((*data)[4] << 8) | (*data)[5];
	ldns_rdf *target_rdf =
	    ldns_dname_new_frm_data(*len - 6, *data + 6);
	char *target = ldns_rdf2str(target_rdf);
	ldns_rdf_free(target_rdf);	
}

I haven't tested, so there might be errors...

> 
> Best regards, Wouter
> 
>>
>> I can hardly believe that this hasn't been tried before :) but as I
>> said, I can't find the documentation that answers this with clarity.  So
>> any help is welcome, including pointers to documentation that I've
>> overlooked!
>>
>> Thanks,
>>  -Rick
>>
> 
> 




More information about the Unbound-users mailing list