Returns a new InetAddress that is one more than the passed in address. This method works for both IPv4 and IPv6 addresses. @param address the InetAddress to increment @return a new InetAddress that is one more than the passed in address @throws IllegalArgumentException if InetAddress is at the end
(InetAddress address)
| 984 | |
| 985 | |
| 986 | public static InetAddress increment(InetAddress address) { |
| 987 | byte[] addr = address.getAddress(); |
| 988 | int i = addr.length - 1; |
| 989 | while (i >= 0 && addr[i] == (byte) 0xff) { |
| 990 | addr[i] = 0; |
| 991 | i--; |
| 992 | } |
| 993 | Preconditions.checkArgument(i >= 0, "Incrementing %s would wrap.", address); |
| 994 | addr[i]++; |
| 995 | return bytesToInetAddress(addr); |
| 996 | } |
| 997 | |
| 998 | /** |
| 999 | * Returns true if the InetAddress is either 255.255.255.255 for IPv4 or |
nothing calls this directly
no test coverage detected