Annoying APIs: djbdns
Looking for a simple way to lookup the MXs for a given domain, I ran into libdjbdns. Which has a delightfully simple API.
Of course it has its wrinkles.
Consider the MX lookup interface:
dns_mx(&out,&fqdn);
Where out and fqdn are strallocs (a sort of string that can contain 0).
But just try parsing out! Here's the explanation:
Each MX record is a two-byte MX distance followed by a 0-terminated dot-encoded domain name. If the domain does not exist in DNS, or has no MX records, out will be empty.
Because almost noone uses MX distances higher than 256, sadly, this usually looks like this (sorry for the notation ;-)
\0 10 f i r s t . m x \0 \0 20 s e c o n d . m x
So, you can not split on the NULLs because there are NULLs in the distances.
Which is not hard to parse, but is definitely more annoying than it should be. How hard would it be to return an array of structs?
this is really interesting viewpoint on the subject i might add
Well, the write-up is truly the freshest on this laudable topic.