From d4d7a2e361ca28cc6b01f5a457a7a8f57a305855 Mon Sep 17 00:00:00 2001 From: Paul Jensen Date: Tue, 13 May 2014 19:05:13 -0400 Subject: [PATCH] Add Network-specific host name resolution API. Change-Id: I932f73158a8f6e3ccc36c319d138180dff2aa070 --- core/java/android/net/Network.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/core/java/android/net/Network.java b/core/java/android/net/Network.java index f82bc22483..ac1289b93a 100644 --- a/core/java/android/net/Network.java +++ b/core/java/android/net/Network.java @@ -19,6 +19,8 @@ package android.net; import android.os.Parcelable; import android.os.Parcel; +import java.net.InetAddress; +import java.net.UnknownHostException; /** * Identifies the Network. @@ -36,6 +38,32 @@ public class Network implements Parcelable { this.netId = that.netId; } + /** + * Operates the same as {@code InetAddress.getAllByName} except that host + * resolution is done on this network. + * + * @param host the hostname or literal IP string to be resolved. + * @return the array of addresses associated with the specified host. + * @throws UnknownHostException if the address lookup fails. + */ + public InetAddress[] getAllByName(String host) throws UnknownHostException { + return InetAddress.getAllByNameOnNet(host, netId); + } + + /** + * Operates the same as {@code InetAddress.getByName} except that host + * resolution is done on this network. + * + * @param host + * the hostName to be resolved to an address or {@code null}. + * @return the {@code InetAddress} instance representing the host. + * @throws UnknownHostException + * if the address lookup fails. + */ + public InetAddress getByName(String host) throws UnknownHostException { + return InetAddress.getByNameOnNet(host, netId); + } + // implement the Parcelable interface public int describeContents() { return 0;