Skip to main content

Ralsina.Me — Roberto Alsina's website

Annoying APIs: djbdns

Look­ing for a sim­ple way to lookup the MXs for a giv­en do­main, I ran in­to lib­d­jbdns. Which has a de­light­ful­ly sim­ple API.

Of course it has its wrin­kles.

Con­sid­er the MX lookup in­ter­face:

dns_mx(&out,&fqdn);

Where out and fqdn are stral­locs (a sort of string that can con­tain 0).

But just try pars­ing out! Here's the ex­pla­na­tion:

Each MX record is a two-byte MX dis­tance fol­lowed by a 0-ter­mi­nat­ed dot-en­cod­ed do­main name. If the do­main does not ex­ist in DNS, or has no MX record­s, out will be emp­ty.

Be­cause al­most noone us­es MX dis­tances high­er than 256, sad­ly, this usu­al­ly looks like this (sor­ry for the no­ta­tion ;-)

\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 be­cause there are NULLs in the dis­tances.

Which is not hard to parse, but is def­i­nite­ly more an­noy­ing than it should be. How hard would it be to re­turn an ar­ray of struct­s?

phone number lookup / 2011-12-03 22:39:

this is really interesting viewpoint on the subject i might add

employment background check / 2011-12-27 23:32:


Well, the write-up is truly the freshest on this laudable topic.