Deprecate a method that formats only IPv4 addresses.
Anyone calling this method is probably storing IP addresses in an int, which doesn't make sense anymore. Change-Id: Iba535b66f6cff47ce07b5ecc6427e3b2fd846998
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