From: testttt <qwo...@ya...> - 2004-04-01 02:03:39
|
Hi, Brian and all others, In order to use DNSJava in my box without extensively configuring it, I found it's handy if DNSJava can query a sub-DNS before it returns an empty query result. This will work with the *nix resolv library. So, I did some very simple change to jnamed.java: 1. a new keyword 'sub-dns' for jnamed.conf. It has a ip and an optional port attribute; 2. create a SimpleResolver object for each sub-dns attribute; 3. When jnamed is returning response to a query, it checks if the answer section in the response is empty or not; 4. If empty, it will try the configured SimpleResolver object to resolve the query; 5. break until the response has non-empty answer section, or all sub-dns has been tried; So far, it works ok in my machine. I would like to get some comments from Brian or whoever is interested. And ultimately, I'd like this feature in DNSJava or merge my change into DNSJava. Please let me know! Ben. // below are some codelet I copied out: ... private ArrayList resolvers = new ArrayList(); ..... // add any sub-dns configured: else if(keyword.equals("resolver")){ String host = st.nextToken(); String port = null; if(st.hasMoreTokens()) port = st.nextToken(); addResolver(host, port); } ... private void addResolver(String host, String port) throws UnknownHostException{ SimpleResolver resolver = new SimpleResolver(host); if(port!=null && port.length()>0) resolver.setPort(Integer.parseInt(port)); resolvers.add(resolver); } .... // then when jnamed is going to return a query response, it do this: boolean hasAnswer = ... // if the response's answer section is not empty. if(resolvers.size()>0 && !hasAnswer){ Iterator it = resolvers.iterator(); while(it.hasNext()){ Resolver resolv = (Resolver)it.next(); response = resolv.send(query); if(response.hasAnswer()) break; } } |