/** * Constructs an IPv6 address according to the given {@code host}, {@code * addr} and {@code scope_id}. * * @param host * the host name associated with the address. * @param addr * the network address. * @param scope_id * the scope id for link- or site-local addresses. * @return the Inet6Address instance representing the IP address. * @throws UnknownHostException * if the address is null or has an invalid length. */ public static Inet6Address getByAddress(String host, byte[] addr, int scope_id) throws UnknownHostException { if (addr == null || addr.length != 16) { throw new UnknownHostException("Not an IPv6 address: " + Arrays.toString(addr)); } if (scope_id < 0) { scope_id = 0; } // TODO: should we clone 'addr'? return new Inet6Address(addr, host, scope_id); }
private static InetAddress makeInetAddress(byte[] bytes, String hostName) throws UnknownHostException { if (bytes.length == 4) { return new Inet4Address(bytes, hostName); } else if (bytes.length == 16) { return new Inet6Address(bytes, hostName, 0); } else { throw badAddressLength(bytes); } }
private static void collectIpv6Addresses(String interfaceName, int interfaceIndex, List<InetAddress> addresses, List<InterfaceAddress> interfaceAddresses) throws SocketException { // RoboVM note: This method used to read from /proc/net/if_inet6 which isn't available on // Darwin. byte[] bytes = getIpv6Addresses(interfaceName); if (bytes != null) { for (int i = 0; i < bytes.length; i += 32) { byte[] addressBytes = new byte[16]; byte[] netmaskBytes = new byte[16]; System.arraycopy(bytes, i, addressBytes, 0, 16); System.arraycopy(bytes, i + 16, netmaskBytes, 0, 16); Inet6Address inet6Address = new Inet6Address(addressBytes, null, interfaceIndex); addresses.add(inet6Address); interfaceAddresses.add(new InterfaceAddress(inet6Address, (short) ipv6NetmaskToPrefixLength(netmaskBytes))); } } }
private static InetAddress getByAddress(String hostName, byte[] ipAddress, int scopeId) throws UnknownHostException { if (ipAddress == null) { throw new UnknownHostException("ipAddress == null"); } if (ipAddress.length == 4) { return new Inet4Address(ipAddress.clone(), hostName); } else if (ipAddress.length == 16) { // First check to see if the address is an IPv6-mapped // IPv4 address. If it is, then we can make it a IPv4 // address, otherwise, we'll create an IPv6 address. if (isIPv4MappedAddress(ipAddress)) { return new Inet4Address(ipv4MappedToIPv4(ipAddress), hostName); } else { return new Inet6Address(ipAddress.clone(), hostName, scopeId); } } else { throw badAddressLength(ipAddress); } }
int addressType = InetAddress.getAddressType(address); InetAddress ia = null; switch (addressType) { case V4 : ia = new Inet4Address(); break; case V6 : ia = new Inet6Address(); break; default : throw new RuntimeException("bad address"); }
private static InetAddress makeInetAddress(byte[] bytes, String hostName) throws UnknownHostException { if (bytes.length == 4) { return new Inet4Address(bytes, hostName); } else if (bytes.length == 16) { return new Inet6Address(bytes, hostName, 0); } else { throw badAddressLength(bytes); } }
private static InetAddress makeInetAddress(byte[] bytes, String hostName) throws UnknownHostException { if (bytes.length == 4) { return new Inet4Address(bytes, hostName); } else if (bytes.length == 16) { return new Inet6Address(bytes, hostName, 0); } else { throw badAddressLength(bytes); } }
private static InetAddress makeInetAddress(byte[] bytes, String hostName) throws UnknownHostException { if (bytes.length == 4) { return new Inet4Address(bytes, hostName); } else if (bytes.length == 16) { return new Inet6Address(bytes, hostName, 0); } else { throw badAddressLength(bytes); } }
private static InetAddress makeInetAddress(byte[] bytes, String hostName) throws UnknownHostException { if (bytes.length == 4) { return new Inet4Address(bytes, hostName); } else if (bytes.length == 16) { return new Inet6Address(bytes, hostName, 0); } else { throw badAddressLength(bytes); } }
private static void collectIpv6Addresses(String interfaceName, int interfaceIndex, List<InetAddress> addresses, List<InterfaceAddress> interfaceAddresses) throws SocketException { // RoboVM note: This method used to read from /proc/net/if_inet6 which isn't available on // Darwin. byte[] bytes = getIpv6Addresses(interfaceName); if (bytes != null) { for (int i = 0; i < bytes.length; i += 32) { byte[] addressBytes = new byte[16]; byte[] netmaskBytes = new byte[16]; System.arraycopy(bytes, i, addressBytes, 0, 16); System.arraycopy(bytes, i + 16, netmaskBytes, 0, 16); Inet6Address inet6Address = new Inet6Address(addressBytes, null, interfaceIndex); addresses.add(inet6Address); interfaceAddresses.add(new InterfaceAddress(inet6Address, (short) ipv6NetmaskToPrefixLength(netmaskBytes))); } } }
private static InetAddress makeInetAddress(byte[] bytes, String hostName) throws UnknownHostException { if (bytes.length == 4) { return new Inet4Address(bytes, hostName); } else if (bytes.length == 16) { return new Inet6Address(bytes, hostName, 0); } else { throw badAddressLength(bytes); } }
private static void collectIpv6Addresses(String interfaceName, int interfaceIndex, List<InetAddress> addresses, List<InterfaceAddress> interfaceAddresses) throws SocketException { // BugVM note: This method used to read from /proc/net/if_inet6 which isn't available on // Darwin. byte[] bytes = getIpv6Addresses(interfaceName); if (bytes != null) { for (int i = 0; i < bytes.length; i += 32) { byte[] addressBytes = new byte[16]; byte[] netmaskBytes = new byte[16]; System.arraycopy(bytes, i, addressBytes, 0, 16); System.arraycopy(bytes, i + 16, netmaskBytes, 0, 16); Inet6Address inet6Address = new Inet6Address(addressBytes, null, interfaceIndex); addresses.add(inet6Address); interfaceAddresses.add(new InterfaceAddress(inet6Address, (short) ipv6NetmaskToPrefixLength(netmaskBytes))); } } }
private static InetAddress makeInetAddress(byte[] bytes, String hostName) throws UnknownHostException { if (bytes.length == 4) { return new Inet4Address(bytes, hostName); } else if (bytes.length == 16) { return new Inet6Address(bytes, hostName, 0); } else { throw badAddressLength(bytes); } }
private static void collectIpv6Addresses(String interfaceName, int interfaceIndex, List<InetAddress> addresses, List<InterfaceAddress> interfaceAddresses) throws SocketException { // BugVM note: This method used to read from /proc/net/if_inet6 which isn't available on // Darwin. byte[] bytes = getIpv6Addresses(interfaceName); if (bytes != null) { for (int i = 0; i < bytes.length; i += 32) { byte[] addressBytes = new byte[16]; byte[] netmaskBytes = new byte[16]; System.arraycopy(bytes, i, addressBytes, 0, 16); System.arraycopy(bytes, i + 16, netmaskBytes, 0, 16); Inet6Address inet6Address = new Inet6Address(addressBytes, null, interfaceIndex); addresses.add(inet6Address); interfaceAddresses.add(new InterfaceAddress(inet6Address, (short) ipv6NetmaskToPrefixLength(netmaskBytes))); } } }
private static void collectIpv6Addresses(String interfaceName, int interfaceIndex, List<InetAddress> addresses, List<InterfaceAddress> interfaceAddresses) throws SocketException { // RoboVM note: This method used to read from /proc/net/if_inet6 which isn't available on // Darwin. byte[] bytes = getIpv6Addresses(interfaceName); if (bytes != null) { for (int i = 0; i < bytes.length; i += 32) { byte[] addressBytes = new byte[16]; byte[] netmaskBytes = new byte[16]; System.arraycopy(bytes, i, addressBytes, 0, 16); System.arraycopy(bytes, i + 16, netmaskBytes, 0, 16); Inet6Address inet6Address = new Inet6Address(addressBytes, null, interfaceIndex); addresses.add(inet6Address); interfaceAddresses.add(new InterfaceAddress(inet6Address, (short) ipv6NetmaskToPrefixLength(netmaskBytes))); } } }
private static void collectIpv6Addresses(String interfaceName, int interfaceIndex, List<InetAddress> addresses, List<InterfaceAddress> interfaceAddresses) throws SocketException { // RoboVM note: This method used to read from /proc/net/if_inet6 which isn't available on // Darwin. byte[] bytes = getIpv6Addresses(interfaceName); if (bytes != null) { for (int i = 0; i < bytes.length; i += 32) { byte[] addressBytes = new byte[16]; byte[] netmaskBytes = new byte[16]; System.arraycopy(bytes, i, addressBytes, 0, 16); System.arraycopy(bytes, i + 16, netmaskBytes, 0, 16); Inet6Address inet6Address = new Inet6Address(addressBytes, null, interfaceIndex); addresses.add(inet6Address); interfaceAddresses.add(new InterfaceAddress(inet6Address, (short) ipv6NetmaskToPrefixLength(netmaskBytes))); } } }
private static InetAddress getByAddress(String hostName, byte[] ipAddress, int scopeId) throws UnknownHostException { if (ipAddress == null) { throw new UnknownHostException("ipAddress == null"); } if (ipAddress.length == 4) { return new Inet4Address(ipAddress.clone(), hostName); } else if (ipAddress.length == 16) { // First check to see if the address is an IPv6-mapped // IPv4 address. If it is, then we can make it a IPv4 // address, otherwise, we'll create an IPv6 address. if (isIPv4MappedAddress(ipAddress)) { return new Inet4Address(ipv4MappedToIPv4(ipAddress), hostName); } else { return new Inet6Address(ipAddress.clone(), hostName, scopeId); } } else { throw badAddressLength(ipAddress); } }
private static InetAddress getByAddress(String hostName, byte[] ipAddress, int scopeId) throws UnknownHostException { if (ipAddress == null) { throw new UnknownHostException("ipAddress == null"); } if (ipAddress.length == 4) { return new Inet4Address(ipAddress.clone(), hostName); } else if (ipAddress.length == 16) { // First check to see if the address is an IPv6-mapped // IPv4 address. If it is, then we can make it a IPv4 // address, otherwise, we'll create an IPv6 address. if (isIPv4MappedAddress(ipAddress)) { return new Inet4Address(ipv4MappedToIPv4(ipAddress), hostName); } else { return new Inet6Address(ipAddress.clone(), hostName, scopeId); } } else { throw badAddressLength(ipAddress); } }
private static InetAddress getByAddress(String hostName, byte[] ipAddress, int scopeId) throws UnknownHostException { if (ipAddress == null) { throw new UnknownHostException("ipAddress == null"); } if (ipAddress.length == 4) { return new Inet4Address(ipAddress.clone(), hostName); } else if (ipAddress.length == 16) { // First check to see if the address is an IPv6-mapped // IPv4 address. If it is, then we can make it a IPv4 // address, otherwise, we'll create an IPv6 address. if (isIPv4MappedAddress(ipAddress)) { return new Inet4Address(ipv4MappedToIPv4(ipAddress), hostName); } else { return new Inet6Address(ipAddress.clone(), hostName, scopeId); } } else { throw badAddressLength(ipAddress); } }
private static InetAddress getByAddress(String hostName, byte[] ipAddress, int scopeId) throws UnknownHostException { if (ipAddress == null) { throw new UnknownHostException("ipAddress == null"); } if (ipAddress.length == 4) { return new Inet4Address(ipAddress.clone(), hostName); } else if (ipAddress.length == 16) { // First check to see if the address is an IPv6-mapped // IPv4 address. If it is, then we can make it a IPv4 // address, otherwise, we'll create an IPv6 address. if (isIPv4MappedAddress(ipAddress)) { return new Inet4Address(ipv4MappedToIPv4(ipAddress), hostName); } else { return new Inet6Address(ipAddress.clone(), hostName, scopeId); } } else { throw badAddressLength(ipAddress); } }