dnsjava oddity
I’m currently writing a Java library to implement client-side ENUM lookups [RFC3761].
The standard class libraries don’t provide access to NAPTR records, so I’m using the dnsjava library to perform the actual DNS lookups.
I was puzzled to find that the result of calling (String)NAPTRRecord.getRegexp() on any RR containing backslash escaped strings (i.e. !^\+441865332...) ended up with the backslashes apparently doubled-up, i.e I’d see !^\\+441865332... in the result of the function.
At first I thought that it was the actual zone data that had the extra backslashes in it, and this was further confused by the fact that dig’s output also showed two backslashes. However tcpdump showed that the wire format of the DNS responses was in fact correct and only contained single backslashes.
It turns out that dnsjava intentionally stores and returns all string fields in escaped format. If the data itself contains a backslash then that backslash in turn is escaped
If you want to use dnsjava to output a zone file for loading into your favourite name server that’s very useful, since name servers typically expect to read escaped data from their zone files. This is why dig works the way it does - the output from dig is a legal zone file.
However if you actually want to use these strings as data in your own code, make sure you unescape the values yourself!



