/** * Parse byte array returned by VPP representing an Ipv6 address. Vpp returns IP byte arrays in natural order. * * @return Ipv46ddressNoZone containing string representation of IPv6 address constructed from submitted bytes. No * change in order. */ @Nonnull public static Ipv6AddressNoZone arrayToIpv6AddressNoZoneReversed(@Nonnull byte[] ip) { checkArgument(ip.length == 16, "Illegal array length"); ip = reverseBytes(ip); try { return new Ipv6AddressNoZone(InetAddresses.toAddrString(InetAddresses.fromLittleEndianByteArray(ip))); } catch (UnknownHostException e) { throw new IllegalArgumentException("Unable to parse ipv6", e); } }
/** * Parse byte array returned by VPP representing an Ipv4 address. Vpp returns IP byte arrays in reversed order. * * @return Ipv4AddressNoZone containing string representation of IPv4 address constructed from submitted bytes. No * change in order. */ @Nonnull public static Ipv4AddressNoZone arrayToIpv4AddressNoZoneReversed(@Nonnull byte[] ip) { // VPP sends ipv4 in a 16 byte array if (ip.length == 16) { ip = Arrays.copyOfRange(ip, 0, 4); } ip = reverseBytes(ip); try { // Not reversing the byte array here!! because the IP coming from VPP is in reversed byte order // compared to byte order it was submitted return new Ipv4AddressNoZone(InetAddresses.toAddrString(InetAddresses.fromLittleEndianByteArray(ip))); } catch (UnknownHostException e) { throw new IllegalArgumentException("Unable to parse ipv4", e); } }