/** * Converts 4-byte or 16-byte data into an IPv4 or IPv6 string respectively. * * @throws IllegalArgumentException * if {@code length} is not {@code 4} nor {@code 16} */ public static String bytesToIpAddress(byte[] bytes) { return bytesToIpAddress(bytes, 0, bytes.length); }
/** * Converts 4-byte or 16-byte data into an IPv4 or IPv6 string respectively. * * @throws IllegalArgumentException * if {@code length} is not {@code 4} nor {@code 16} */ public static String bytesToIpAddress(byte[] bytes) { return bytesToIpAddress(bytes, 0, bytes.length); }
/** * Converts 4-byte or 16-byte data into an IPv4 or IPv6 string respectively. * * @throws IllegalArgumentException * if {@code length} is not {@code 4} nor {@code 16} */ public static String bytesToIpAddress(byte[] bytes) { return bytesToIpAddress(bytes, 0, bytes.length); }
@Override public String decodeAddress(Socks5AddressType addrType, ByteBuf in) throws Exception { if (addrType == Socks5AddressType.IPv4) { return NetUtil.intToIpAddress(in.readInt()); } if (addrType == Socks5AddressType.DOMAIN) { final int length = in.readUnsignedByte(); final String domain = in.toString(in.readerIndex(), length, CharsetUtil.US_ASCII); in.skipBytes(length); return domain; } if (addrType == Socks5AddressType.IPv6) { if (in.hasArray()) { final int readerIdx = in.readerIndex(); in.readerIndex(readerIdx + IPv6_LEN); return NetUtil.bytesToIpAddress(in.array(), in.arrayOffset() + readerIdx, IPv6_LEN); } else { byte[] tmp = new byte[IPv6_LEN]; in.readBytes(tmp); return NetUtil.bytesToIpAddress(tmp); } } else { throw new DecoderException("unsupported address type: " + (addrType.byteValue() & 0xFF)); } } };
ipAddr = NetUtil.bytesToIpAddress(addrBytes, 12, 4); ipAddr = NetUtil.bytesToIpAddress(addrBytes, 12, 4); } else { ipAddr = NetUtil.bytesToIpAddress(addrBytes); ipAddr = NetUtil.bytesToIpAddress(addrBytes); ipAddr = NetUtil.bytesToIpAddress(addrBytes);
/** * Converts 4-byte or 16-byte data into an IPv4 or IPv6 string respectively. * * @throws IllegalArgumentException * if {@code length} is not {@code 4} nor {@code 16} */ public static String bytesToIpAddress(byte[] bytes) { return bytesToIpAddress(bytes, 0, bytes.length); }
/** * Converts 4-byte or 16-byte data into an IPv4 or IPv6 string respectively. * * @throws IllegalArgumentException * if {@code length} is not {@code 4} nor {@code 16} */ public static String bytesToIpAddress(byte[] bytes) { return bytesToIpAddress(bytes, 0, bytes.length); }
/** * Converts 4-byte or 16-byte data into an IPv4 or IPv6 string respectively. * * @throws IllegalArgumentException * if {@code length} is not {@code 4} nor {@code 16} */ public static String bytesToIpAddress(byte[] bytes) { return bytesToIpAddress(bytes, 0, bytes.length); }
/** * Converts 4-byte or 16-byte data into an IPv4 or IPv6 string respectively. * * @throws IllegalArgumentException * if {@code length} is not {@code 4} nor {@code 16} */ public static String bytesToIpAddress(byte[] bytes) { return bytesToIpAddress(bytes, 0, bytes.length); }
@Override public String decodeAddress(Socks5AddressType addrType, ByteBuf in) throws Exception { if (addrType == Socks5AddressType.IPv4) { return NetUtil.intToIpAddress(in.readInt()); } if (addrType == Socks5AddressType.DOMAIN) { final int length = in.readUnsignedByte(); final String domain = in.toString(in.readerIndex(), length, CharsetUtil.US_ASCII); in.skipBytes(length); return domain; } if (addrType == Socks5AddressType.IPv6) { if (in.hasArray()) { final int readerIdx = in.readerIndex(); in.readerIndex(readerIdx + IPv6_LEN); return NetUtil.bytesToIpAddress(in.array(), in.arrayOffset() + readerIdx, IPv6_LEN); } else { byte[] tmp = new byte[IPv6_LEN]; in.readBytes(tmp); return NetUtil.bytesToIpAddress(tmp); } } else { throw new DecoderException("unsupported address type: " + (addrType.byteValue() & 0xFF)); } } };
@Override public String decodeAddress(Socks5AddressType addrType, ByteBuf in) throws Exception { if (addrType == Socks5AddressType.IPv4) { return NetUtil.intToIpAddress(in.readInt()); } if (addrType == Socks5AddressType.DOMAIN) { final int length = in.readUnsignedByte(); final String domain = in.toString(in.readerIndex(), length, CharsetUtil.US_ASCII); in.skipBytes(length); return domain; } if (addrType == Socks5AddressType.IPv6) { if (in.hasArray()) { final int readerIdx = in.readerIndex(); in.readerIndex(readerIdx + IPv6_LEN); return NetUtil.bytesToIpAddress(in.array(), in.arrayOffset() + readerIdx, IPv6_LEN); } else { byte[] tmp = new byte[IPv6_LEN]; in.readBytes(tmp); return NetUtil.bytesToIpAddress(tmp); } } else { throw new DecoderException("unsupported address type: " + (addrType.byteValue() & 0xFF)); } } };