private static InetAddress[] lookupHostByName(String host, int netId)
            throws UnknownHostException {
        BlockGuard.getThreadPolicy().onNetwork();
        // Do we have a result cached?
        Object cachedResult = addressCache.get(host, netId);
        if (cachedResult != null) {
            if (cachedResult instanceof InetAddress[]) {
                // A cached positive result.
                return (InetAddress[]) cachedResult;
            } else {
                // A cached negative result.
                throw new UnknownHostException((String) cachedResult);
            }
        }
        try {
            StructAddrinfo hints = new StructAddrinfo();
            hints.ai_flags = AI_ADDRCONFIG;
            hints.ai_family = AF_UNSPEC;
            // If we don't specify a socket type, every address will appear twice, once
            // for SOCK_STREAM and one for SOCK_DGRAM. Since we do not return the family
            // anyway, just pick one.
            hints.ai_socktype = SOCK_STREAM;
            InetAddress[] addresses = NetworkOs.getaddrinfo(host, hints);
            // TODO: should getaddrinfo set the hostname of the InetAddresses it returns?
            for (InetAddress address : addresses) {
                address.holder().hostName = host;
            }
            addressCache.put(host, netId, addresses);
            return addresses;
        } catch (GaiException gaiException) {
            // If the failure appears to have been a lack of INTERNET permission, throw a clear
            // SecurityException to aid in debugging this common mistake.
            // http://code.google.com/p/android/issues/detail?id=15722
            if (gaiException.getCause() instanceof ErrnoException) {
                if (((ErrnoException) gaiException.getCause()).errno == EACCES) {
                    throw new SecurityException("Permission denied (missing INTERNET permission?)", gaiException);
                }
            }
            // Otherwise, throw an UnknownHostException.
            String detailMessage = "Unable to resolve host \"" + host + "\": " + NetworkOs.gai_strerror(gaiException.error);
            addressCache.putUnknownHost(host, netId, detailMessage);
            throw gaiException.rethrowAsUnknownHostException(detailMessage);
        }
    }
private static InetAddress [ ] lookupHostByName ( String host , int netId ) throws UnknownHostException { BlockGuard . getThreadPolicy ( ) . onNetwork ( ) ; Object cachedResult = addressCache . get ( host , netId ) ; if ( cachedResult != null ) { if ( cachedResult instanceof InetAddress [ ] ) { return ( InetAddress [ ] ) cachedResult ; } else { throw new UnknownHostException ( ( String ) cachedResult ) ; } } try { StructAddrinfo hints = new StructAddrinfo ( ) ; hints . ai_flags = AI_ADDRCONFIG ; hints . ai_family = AF_UNSPEC ; hints . ai_socktype = SOCK_STREAM ; InetAddress [ ] addresses = NetworkOs . getaddrinfo ( host , hints ) ; for ( InetAddress address : addresses ) { address . holder ( ) . hostName = host ; } addressCache . put ( host , netId , addresses ) ; return addresses ; } catch ( GaiException gaiException ) { if ( gaiException . getCause ( ) instanceof ErrnoException ) { if ( ( ( ErrnoException ) gaiException . getCause ( ) ) . errno == EACCES ) { throw new SecurityException ( "Permission denied (missing INTERNET permission?)" , gaiException ) ; } } String detailMessage = "Unable to resolve host \"" + host + "\": " + NetworkOs . gai_strerror ( gaiException . error ) ; addressCache . putUnknownHost ( host , netId , detailMessage ) ; throw gaiException . rethrowAsUnknownHostException ( detailMessage ) ; } }
Resolves a hostname to its IP addresses using a cache.

@param host the hostname to resolve.
@param netId the network to perform resolution upon.
@return the IP addresses of the host.