possible name resolution problem in 1.5.0_11-p5
Nick Johnson
freebsd at spatula.net
Tue Jul 24 21:37:47 UTC 2007
I've attached a snippet of code that demonstrates the problem.
In the example, note this line:
Attributes attrs = attrs = ictx.getAttributes("mac.com", new String[] { "MX", "A"});
The behaviour is that IF the name being resolved is already in the local
name server's cache (and resolv.conf is pointing at the local name
server), it will retrieve the records requested.
If it's not, some records will be retrieved, but they won't include an MX
record.
If you request JUST an MX record (ie new String[] { "MX" } by itself),
then the MX record will be found.
To use the test, you'd need to substitute "mac.com" for any foreign
hostname that isn't already in your name server's cache. This is with
Java 1.5.0_11-p5 built from ports on Jun 19 running on 6.2-STABLE built on
Sun Jan 21 2007.
I'm not entirely certain that this problem isn't something particular to
my system / configuration. If some others could play with the test a bit
and see if they get the same behaviour, that would help.
Nick
-------------- next part --------------
import java.util.*;
import javax.naming.*;
import javax.naming.directory.*;
import java.net.*;
public class FreeBsdDnsTest {
public static void main(String[] args) {
System.setProperty("java.net.preferIPv4Stack", "true"); // definitely won't work otherwise
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
// env.put("java.naming.provider.url", "dns://localhost:53/");
env.put("com.sun.jndi.dns.timeout.initial", "2000");
env.put("com.sun.jndi.dns.timeout.retries", "3");
try {
DirContext ictx = new InitialDirContext(env);
// The next call seems to return attributes for an MX record ONLY if an MX record
// is already held in the local name server's cache.
// If only one attribute is requsted (e.g. just MX or just A) then that attribute
// seems to be found regardless.
Attributes attrs = attrs = ictx.getAttributes("mac.com", new String[] { "MX", "A"});
if (attrs == null) {
System.out.println("No records returned :(");
}
Attribute attr = attrs.get("MX");
if (attr != null) {
System.out.println("Found MX hosts! :)");
} else {
System.out.println("Found no MX hosts :(");
}
} catch (NamingException e) {
e.printStackTrace();
}
}
}
More information about the freebsd-java
mailing list