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)
| 983 | |
| 984 | |
| 985 | public static InetAddress increment(InetAddress address) { |
| 986 | byte[] addr = address.getAddress(); |
| 987 | int i = addr.length - 1; |
| 988 | while (i >= 0 && addr[i] == (byte) 0xff) { |
| 989 | addr[i] = 0; |
| 990 | i--; |
| 991 | } |
| 992 | Preconditions.checkArgument(i >= 0, "Incrementing %s would wrap.", address); |
| 993 | addr[i]++; |
| 994 | return bytesToInetAddress(addr); |
| 995 | } |
| 996 | |
| 997 | /** |
| 998 | * Returns true if the InetAddress is either 255.255.255.255 for IPv4 or |
nothing calls this directly
no test coverage detected