title: Get DNS SRV record using JNDI
body: <p>I am trying to get SRV records from a DNS server using JNDI. </p>
  
  <pre><code>Hashtable&lt;String, String&gt; env = new Hashtable&lt;String, String&gt;();
  env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
  env.put("java.naming.provider.url", "dns://dns.server.com");
  DirContext ctx = new InitialDirContext(env);
  Attributes attributes = ctx.getAttributes("_sip._udp", new String [] { "SRV" });
  return attributes;
  </code></pre>
  
  <p>But when trying to get attributes I get the following exception</p>
  
  <blockquote>
    <p>DNS error [Root exception is
    java.net.PortUnreachableException:
    ICMP Port Unreachable]; remaining name
    '_sip._udp'</p>
  </blockquote>
  
  <p>I have verified host -t srv _sip._udp.server.com returns valid SRV record. </p>
  
  <p>Any reason as why this might happen?</p>