Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

InetAddress.getByName failing for valid domains

843790Jul 20 2010 — edited Jul 23 2010
On some machines, domains starting with the hyphen (and other non-alphabetic characters) are not resolved by InetAddress.getByName()
nslookup does resolve the domains, so they seem to be valid - perhaps not by the RFC, but it seems that other common tools do consider the domain to be valid.

here are some domains that fail:
----thomiiii.hi5.com
*.letsgodigital.es
*.chordie.com
I found the org.xbill.DNS package that resolves these domains.

Wondering why the InetAddress class does not. I tried looking at the source, but it led me to a native implemention:

static native InetAddress getHostByNameImpl(String name, boolean preferIPv6Address) throws UnknownHostException;

but i couldn't find the source for this native implementation.

Here is a bit of code that runs the two functions together. After it hits the exception with the InetAddress function, it retries with the Address function (from the org.xbill.DNS package, which works)
import java.net.InetAddress;
import org.xbill.DNS.Address;

public class MemLimitCheck {
    public static void main(String[] args) {

        try {
            InetAddress ia = InetAddress.getByName(args[0]);
            byte[] addr = ia.getAddress();
            String host = ia.getHostAddress();
            System.out.println(host);
        } catch (Exception e){
            System.err.println(e.getMessage());
            e.printStackTrace();

            try {
                InetAddress ia = Address.getByName(args[0]);
                byte[] addr = ia.getAddress();
                String host = ia.getHostAddress();
                System.out.println(host);                
            } catch (Exception t) {
                System.err.println(t.getMessage());
                t.printStackTrace();
            }

        }

    }
}
Edited by: thushw on Jul 20, 2010 11:40 AM

Edited by: thushw on Jul 20, 2010 11:40 AM

Edited by: thushw on Jul 20, 2010 11:41 AM

Edited by: thushw on Jul 20, 2010 11:42 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 20 2010
Added on Jul 20 2010
17 comments
1,167 views