MS Suckage Beyond My Wildest Imagination

OK, so I’ve been working on some stuff related to the .tel domains – basically an extension for Thunderbird / Firefox for synchronizing contact info through a domain. Best I can tell the DNS support in Firefox already doesn’t support the NAPTR (Naming Authority Pointer) records used by .tel lookups. So I’m having to write an XPCOM component to handle it. On Windows I’m using MS’s windns lib (for the time being) and there the troubles began…

So let me state up front I’m NOT much of a C++ programmer. Mostly Java and C#, with some occaisional plain old C. So I’ve been wrestling a bit with the C++ elements of XPCOM, but getting through it. WinDNS is just C though, and should be straightforward. And in fact it is pretty simple to use to make DNS calls. Extracting and using the results however are another matter.

The DnsQuery call populates a DNS_RECORD structure with the results of the lookup. There are a few standard fields common to all lookups (including a message length), and then a Data field. Data is a union of MANY structs, one per type of lookup. Sounds reasonable enough, right? The struct I’m most interested in right now is DNS_NAPTR_DATA. NAPTR data consists of a couple of 16-bit unsigned ints for the record order and preference fields and 4 strings. DNS strings are interesting, with an 8-bit length followed by that number of characters. The last field is (when used, at least in .tel) a domain name, and rather than being a single dot-delimited string (like a typical address) it is a set of separate strings as defined above. The DNS_NAPTR_DATA struct mirrors this:


typedef struct _DNS_NAPTR_DATA {
WORD wOrder;
WORD wPreference;
PWSTR pFlags;
PWSTR pService;
PWSTR pRegularExpression;
PWSTR pReplacement;
}DNS_NAPTR_DATA, *PDNS_NAPTR_DATA;

Looks basic enough. The PWSTR are essentially pointers to Unicode strings. Seemed a little odd since DNS doesn’t use Unicode, but I figured the library translated them appropriately. So I put together some code, tried it out, and bada bing…

Garbage.

The order and preference were sort of OK, requiring conversion from network byte order to host. That should have set off some alarms right away. The strings were a mess. Debugging was showing some strange stuff, though I could see the expected data in there somewhere.

I’ll save the hours of frustration though and jump to the chase.

I finally realized that what is in the Data field as returned from DnsQuery ISN’T a nicely populated struct. It’s just the raw DNS message with a struct definition overlayed on it in memory. WTH? Maybe there’s a way to make it parse it out correctly, but I can’t find anything. So I ended up just ignoring the struct and parsing out the raw data on my own. Unless I’m doing something really wrong (I don’t think so) I can’t believe something so completely WRONG made it out of Microsoft. This isn’t even in the ballpark of correct. Sheesh!

This entry was posted in .tel, General, Windows, XPCOM. Bookmark the permalink.

2 Responses to MS Suckage Beyond My Wildest Imagination

Leave a Reply