Deprecate a method that formats only IPv4 addresses. am: 3741bedee7
Original change: undetermined Change-Id: Icb81e5e13a333d07c51428b4fd829ae5674831c7
This commit is contained in:
@@ -125,24 +125,19 @@ public class NetworkUtils {
|
||||
|
||||
/**
|
||||
* Convert a IPv4 address from an integer to an InetAddress.
|
||||
* @param hostAddr is an Int corresponding to the IPv4 address in network byte order
|
||||
* @return the IP address as an {@code InetAddress}, returns null if
|
||||
* unable to convert or if the int is an invalid address.
|
||||
* @param hostAddress an int corresponding to the IPv4 address in network byte order
|
||||
*/
|
||||
public static InetAddress intToInetAddress(int hostAddress) {
|
||||
InetAddress inetAddress;
|
||||
byte[] addressBytes = { (byte)(0xff & hostAddress),
|
||||
(byte)(0xff & (hostAddress >> 8)),
|
||||
(byte)(0xff & (hostAddress >> 16)),
|
||||
(byte)(0xff & (hostAddress >> 24)) };
|
||||
|
||||
try {
|
||||
inetAddress = InetAddress.getByAddress(addressBytes);
|
||||
} catch(UnknownHostException e) {
|
||||
return null;
|
||||
return InetAddress.getByAddress(addressBytes);
|
||||
} catch (UnknownHostException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
return inetAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user