Merge "BUG-49 : added tests & removed warnings: bgp-parser-spi"
[bgpcep.git] / concepts / src / main / java / org / opendaylight / protocol / concepts / Ipv6Util.java
index eea9d0aa48e238fee11acd095c17ea4537ea7f95..57e224ed2ebf35659973fb21a141e760a0e027f6 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.protocol.concepts;
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -49,7 +50,14 @@ public class Ipv6Util {
 
        public static Ipv6Prefix prefixForBytes(final byte[] bytes, final int length) {
                Preconditions.checkArgument(length <= bytes.length * 8);
-               return new Ipv6Prefix(addressForBytes(bytes).toString() + "/" + length);
+               byte[] tmp = Arrays.copyOfRange(bytes, 0, 16);
+               InetAddress a = null;
+               try {
+                       a = InetAddress.getByAddress(tmp);
+               } catch (UnknownHostException e) {
+                       throw new IllegalArgumentException(e.getMessage());
+               }
+               return new Ipv6Prefix(InetAddresses.toAddrString(a) + "/" + length);
        }
 
        public static List<Ipv6Prefix> prefixListForBytes(final byte[] bytes) {