[sip-comm-dev] IPv6 dns resolver


#1

Hi,

It seems that JNDI does not like to parse IPv6 dns server (i.e. you can give a try using an IPv6 account with an IPv6 dns server in your configuration file like "/etc/resolv.conf").
In order to solve this problem, shall I propose to use another resolver which is "dnsjava" (can be found at : http://www.dnsjava.org) ?

You will find in attachment a simple correction (diff from release 1.0-alpha2-0) for resolving SRV records with dnsjava library (this correction uses version 2.0.3 of dnsjava : http://www.dnsjava.org/download/dnsjava-2.0.3.jar).

This solution as been just tested under "Linux" and must be validated under other OS.

Cheers,
Vincent Lucas

dns_ipv6_correction.diff (5.69 KB)


#2

Hey Vincent,

Very nice catch!

I've just applied the fix, and acked your effort.

Thanks!
Emil

Vincent Lucas wrote:

···

Hi,

It seems that JNDI does not like to parse IPv6 dns server (i.e. you can give a try using an IPv6 account with an IPv6 dns server in your configuration file like "/etc/resolv.conf").
In order to solve this problem, shall I propose to use another resolver which is "dnsjava" (can be found at : http://www.dnsjava.org) ?

You will find in attachment a simple correction (diff from release 1.0-alpha2-0) for resolving SRV records with dnsjava library (this correction uses version 2.0.3 of dnsjava : http://www.dnsjava.org/download/dnsjava-2.0.3.jar).

This solution as been just tested under "Linux" and must be validated under other OS.

Cheers,
Vincent Lucas

------------------------------------------------------------------------

? lib/installer-exclude/dnsjava-2.0.3.jar
Index: build.xml

RCS file: /cvs/sip-communicator/build.xml,v
retrieving revision 1.128
diff -r1.128 build.xml
942a943

            <zipfileset src="${lib.noinst}/dnsjava-2.0.3.jar" prefix=""/>

Index: lib/felix.client.run.properties

RCS file: /cvs/sip-communicator/lib/felix.client.run.properties,v
retrieving revision 1.12
diff -r1.12 felix.client.run.properties
37c37,38
< com.apple.eio;
---

com.apple.eio; \
org.xbill.DNS;

Index: src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java

RCS file: /cvs/sip-communicator/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java,v
retrieving revision 1.26
diff -r1.26 ProtocolProviderServiceJabberImpl.java
255,259c255,257
< try
< {
< String hosts[] =
< NetworkUtils.getSRVRecords(
< "_xmpp-client._tcp." + serviceName);
---

    String hosts[] =
        NetworkUtils.getSRVRecords(
          "_xmpp-client._tcp." + serviceName);

261,271c259,264
< if(hosts != null && hosts.length > 0)
< {
< logger.trace("Will set server address from SRV records "
< + hosts[0]);
< serverAddress = hosts[0];
< }
< }
< catch (NamingException ex1)
< {
< logger.error("Domain not resolved " + ex1.getMessage());
< }
---

    if(hosts != null && hosts.length > 0)
    {
        logger.trace("Will set server address from SRV records "
          + hosts[0]);
        serverAddress = hosts[0];
    }

Index: src/net/java/sip/communicator/util/NetworkUtils.java

RCS file: /cvs/sip-communicator/src/net/java/sip/communicator/util/NetworkUtils.java,v
retrieving revision 1.6
diff -r1.6 NetworkUtils.java
13a14,19

import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record;
import org.xbill.DNS.SRVRecord;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;

161d166
< throws NamingException
163,176c168
< InitialDirContext iDirC = new InitialDirContext();
< Attributes attributes =
< iDirC.getAttributes("dns:/" + domain, new String[]{"SRV"});
< Attribute attributeSRV = attributes.get("SRV");
< < // if there is no SRV record
< if(attributeSRV == null)
< return null;
< < String[][] pvhn = new String[attributeSRV.size()][2];
< for(int i = 0; i < attributeSRV.size(); i++)
< {
< pvhn[i] = ("" + attributeSRV.get(i)).split("\\s+");
< }
---

  Record[] records = null;

178,204c170,221
< // sort the SRV RRs by RR value (lower is preferred)
< Arrays.sort(pvhn, new Comparator()
< {
< public int compare(Object o1, Object o2)
< {
< return ( Integer.parseInt(((String[])o1)[0])
< - Integer.parseInt(((String[])o2)[0]));
< }
< });
< < // put sorted host names in an array, get rid of any trailing '.'
< String[] sortedHostNames = new String[pvhn.length];
< for(int i = 0; i < pvhn.length; i++)
< {
< sortedHostNames[i] = pvhn[i][3].endsWith(".") ?
< pvhn[i][3].substring(0, pvhn[i][3].length() - 1) : pvhn[i][3];
< }
< < if (logger.isTraceEnabled())
< {
< logger.trace("DNS SRV query for domain " + domain + " returned:");
< for (int i = 0; i < sortedHostNames.length; i++)
< {
< logger.trace(sortedHostNames[i]);
< }
< }
< return sortedHostNames;
---

  try
  {
      Lookup l = new Lookup(domain, Type.SRV);
      records = l.run();
  }
  catch(TextParseException tpe)
  {
      System.out.println(tpe);
  }
  if(records == null)
  {
      return null;
  }
  String[][] pvhn = new String[records.length][4];
  for (int i = 0; i < records.length; i++)
  {
      SRVRecord srvRecord = (SRVRecord) records[i];
      pvhn[i][0] = "" + srvRecord.getPriority();
      pvhn[i][1] = "" + srvRecord.getWeight();
      pvhn[i][2] = "" + srvRecord.getPort();
      pvhn[i][3] = srvRecord.getTarget().toString();
      if(pvhn[i][3].endsWith(".")){
    pvhn[i][3] = pvhn[i][3].substring(0, pvhn[i][3].length()-1);
      }
  }

  /* sort the SRV RRs by RR value (lower is preferred) */
  Arrays.sort( pvhn, new Comparator()
  {
      public int compare(Object o1, Object o2)
      {
    return ( Integer.parseInt(((String[])o1)[0])
    - Integer.parseInt(((String[])o2)[0]));
      }
  });

  /* put sorted host names in an array, get rid of any trailing '.' */
  String[] sortedHostNames = new String[pvhn.length];
  for(int i = 0; i < pvhn.length; i++)
  {
      sortedHostNames[i] = pvhn[i][3];
  }

  if (logger.isTraceEnabled())
  {
      logger.trace("DNS SRV query for domain " + domain + " returned:");
      for (int i = 0; i < sortedHostNames.length; i++)
      {
    logger.trace(sortedHostNames[i]);
      }
  }
  return sortedHostNames;

205a223
Index: src/net/java/sip/communicator/util/util.manifest.mf

RCS file: /cvs/sip-communicator/src/net/java/sip/communicator/util/util.manifest.mf,v
retrieving revision 1.3
diff -r1.3 util.manifest.mf
15a16

org.xbill.DNS,
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net