@Test public void testIPv4Mixed() throws IPStringConversionException { assertTrue("Expected IPv4 mixed address to work", bytes_match(ipv4Mixed_bytes, IPv6.IpString2bytes(ipv4Mixed_compressed))); }
public static byte[] IpString2bytes(String ipStr) throws IPStringConversionException { int i; int j; int val; byte[] out; String expanded_ipStr; Matcher ipMatch = ipPattern.matcher(ipStr); if (ipMatch.find()) { String hex_part = ipMatch.group(1); String ip4_part = ipMatch.group(2); if (hex_part == null && ip4_part == null) { hex_part = ipMatch.group(3); ip4_part = ipMatch.group(4); } IPv4 ipv4 = new IPv4(ip4_part); byte[] ipv4_bytes = ipv4.getBytes(); byte[] hex_bytes = hex_part.getBytes(); int last = hex_bytes.length - 1; int hi_word = (IPUtils.ubyte2int(ipv4_bytes[0]) << 8) + (IPUtils.ubyte2int(ipv4_bytes[1])); int lo_word = (IPUtils.ubyte2int(ipv4_bytes[2]) << 8) + (IPUtils.ubyte2int(ipv4_bytes[3])); String hi_str = IPUtils.int16bit2hex(hi_word); String lo_str = IPUtils.int16bit2hex(lo_word); expanded_ipStr = expand(hex_part, 6) + String.format(":%s:%s", hi_str, lo_str); } else { String hex_part = ipStr; expanded_ipStr = expand(hex_part, 8); } i = 0; out = new byte[16]; for (String word : expanded_ipStr.split(":")) { val = IPUtils.hex16bit2int(word); out[i] = IPUtils.int2ubyte((val & 0xff00) >> 8); out[i + 1] = IPUtils.int2ubyte((val & 0x00ff)); i += 2; } return out; }
IPv6 { public static byte[] IpString2bytes(String ipStr) throws IPStringConversionException { int i; int j; int val; byte[] out; String expanded_ipStr; Matcher ipMatch = ipPattern.matcher(ipStr); if (ipMatch.find()) { String hex_part = ipMatch.group(1); String ip4_part = ipMatch.group(2); if (hex_part == null && ip4_part == null) { hex_part = ipMatch.group(3); ip4_part = ipMatch.group(4); } IPv4 ipv4 = new IPv4(ip4_part); byte[] ipv4_bytes = ipv4.getBytes(); byte[] hex_bytes = hex_part.getBytes(); int last = hex_bytes.length - 1; int hi_word = (IPUtils.ubyte2int(ipv4_bytes[0]) << 8) + (IPUtils.ubyte2int(ipv4_bytes[1])); int lo_word = (IPUtils.ubyte2int(ipv4_bytes[2]) << 8) + (IPUtils.ubyte2int(ipv4_bytes[3])); String hi_str = IPUtils.int16bit2hex(hi_word); String lo_str = IPUtils.int16bit2hex(lo_word); expanded_ipStr = expand(hex_part, 6) + String.format(":%s:%s", hi_str, lo_str); } else { String hex_part = ipStr; expanded_ipStr = expand(hex_part, 8); } i = 0; out = new byte[16]; for (String word : expanded_ipStr.split(":")) { val = IPUtils.hex16bit2int(word); out[i] = IPUtils.int2ubyte((val & 0xff00) >> 8); out[i + 1] = IPUtils.int2ubyte((val & 0x00ff)); i += 2; } return out; } }
IPv6 { public static byte[] IpString2bytes(String ipStr) throws IPStringConversionException { int i; int j; int val; byte[] out; String expanded_ipStr; Matcher ipMatch = ipPattern.matcher(ipStr); if (ipMatch.find()) { String hex_part = ipMatch.group(1); String ip4_part = ipMatch.group(2); if (hex_part == null && ip4_part == null) { hex_part = ipMatch.group(3); ip4_part = ipMatch.group(4); } IPv4 ipv4 = new IPv4(ip4_part); byte[] ipv4_bytes = ipv4.getBytes(); byte[] hex_bytes = hex_part.getBytes(); int last = hex_bytes.length - 1; int hi_word = (IPUtils.ubyte2int(ipv4_bytes[0]) << 8) + (IPUtils.ubyte2int(ipv4_bytes[1])); int lo_word = (IPUtils.ubyte2int(ipv4_bytes[2]) << 8) + (IPUtils.ubyte2int(ipv4_bytes[3])); String hi_str = IPUtils.int16bit2hex(hi_word); String lo_str = IPUtils.int16bit2hex(lo_word); expanded_ipStr = expand(hex_part, 6) + String.format(":%s:%s", hi_str, lo_str); } else { String hex_part = ipStr; expanded_ipStr = expand(hex_part, 8); } i = 0; out = new byte[16]; for (String word : expanded_ipStr.split(":")) { val = IPUtils.hex16bit2int(word); out[i] = IPUtils.int2ubyte((val & 0xff00) >> 8); out[i + 1] = IPUtils.int2ubyte((val & 0x00ff)); i += 2; } return out; } IPv6();  IPv6(String ip);  IPv6(byte[] in); }
IPv6 { public static byte[] IpString2bytes(String ipStr) throws IPStringConversionException { int i; int j; int val; byte[] out; String expanded_ipStr; Matcher ipMatch = ipPattern.matcher(ipStr); if (ipMatch.find()) { String hex_part = ipMatch.group(1); String ip4_part = ipMatch.group(2); if (hex_part == null && ip4_part == null) { hex_part = ipMatch.group(3); ip4_part = ipMatch.group(4); } IPv4 ipv4 = new IPv4(ip4_part); byte[] ipv4_bytes = ipv4.getBytes(); byte[] hex_bytes = hex_part.getBytes(); int last = hex_bytes.length - 1; int hi_word = (IPUtils.ubyte2int(ipv4_bytes[0]) << 8) + (IPUtils.ubyte2int(ipv4_bytes[1])); int lo_word = (IPUtils.ubyte2int(ipv4_bytes[2]) << 8) + (IPUtils.ubyte2int(ipv4_bytes[3])); String hi_str = IPUtils.int16bit2hex(hi_word); String lo_str = IPUtils.int16bit2hex(lo_word); expanded_ipStr = expand(hex_part, 6) + String.format(":%s:%s", hi_str, lo_str); } else { String hex_part = ipStr; expanded_ipStr = expand(hex_part, 8); } i = 0; out = new byte[16]; for (String word : expanded_ipStr.split(":")) { val = IPUtils.hex16bit2int(word); out[i] = IPUtils.int2ubyte((val & 0xff00) >> 8); out[i + 1] = IPUtils.int2ubyte((val & 0x00ff)); i += 2; } return out; } IPv6();  IPv6(String ip);  IPv6(byte[] in); static int[] splitvals(String ipStr); static int countnegatives(int[] in); static String expand(String ipStr, int nwords); String expand(); static int[] expand(int[] vals, int nwords); static byte[] IpString2bytes(String ipStr); static String bytes2IpString(byte[] in); void setIp(byte[] in); String getString(); byte[] getBytes(); void setIp(String ip); }
IPv6 { public static byte[] IpString2bytes(String ipStr) throws IPStringConversionException { int i; int j; int val; byte[] out; String expanded_ipStr; Matcher ipMatch = ipPattern.matcher(ipStr); if (ipMatch.find()) { String hex_part = ipMatch.group(1); String ip4_part = ipMatch.group(2); if (hex_part == null && ip4_part == null) { hex_part = ipMatch.group(3); ip4_part = ipMatch.group(4); } IPv4 ipv4 = new IPv4(ip4_part); byte[] ipv4_bytes = ipv4.getBytes(); byte[] hex_bytes = hex_part.getBytes(); int last = hex_bytes.length - 1; int hi_word = (IPUtils.ubyte2int(ipv4_bytes[0]) << 8) + (IPUtils.ubyte2int(ipv4_bytes[1])); int lo_word = (IPUtils.ubyte2int(ipv4_bytes[2]) << 8) + (IPUtils.ubyte2int(ipv4_bytes[3])); String hi_str = IPUtils.int16bit2hex(hi_word); String lo_str = IPUtils.int16bit2hex(lo_word); expanded_ipStr = expand(hex_part, 6) + String.format(":%s:%s", hi_str, lo_str); } else { String hex_part = ipStr; expanded_ipStr = expand(hex_part, 8); } i = 0; out = new byte[16]; for (String word : expanded_ipStr.split(":")) { val = IPUtils.hex16bit2int(word); out[i] = IPUtils.int2ubyte((val & 0xff00) >> 8); out[i + 1] = IPUtils.int2ubyte((val & 0x00ff)); i += 2; } return out; } IPv6();  IPv6(String ip);  IPv6(byte[] in); static int[] splitvals(String ipStr); static int countnegatives(int[] in); static String expand(String ipStr, int nwords); String expand(); static int[] expand(int[] vals, int nwords); static byte[] IpString2bytes(String ipStr); static String bytes2IpString(byte[] in); void setIp(byte[] in); String getString(); byte[] getBytes(); void setIp(String ip);  }