String host = NetUtil.intToIpAddress(byteBuf.readInt()); int port = byteBuf.readUnsignedShort(); out.add(new SocksCmdResponse(cmdStatus, addressType, host, port)); break; String host = SocksCommonUtils.readUsAscii(byteBuf, fieldLength); int port = byteBuf.readUnsignedShort(); out.add(new SocksCmdResponse(cmdStatus, addressType, host, port)); break; String host = SocksCommonUtils.ipv6toStr(bytes); int port = byteBuf.readUnsignedShort(); out.add(new SocksCmdResponse(cmdStatus, addressType, host, port)); break;
@Override public void encodeAsByteBuf(ByteBuf byteBuf) { byteBuf.writeByte(protocolVersion().byteValue()); byteBuf.writeByte(cmdStatus.byteValue()); byteBuf.writeByte(0x00);
protected SocksCmdResponseWrap(BytestreamsProxy proxy, SocksCmdResponse cmd) { super(cmd.responseType()); this.cmd = cmd; this.proxy = proxy; }
@Override public void encodeAsByteBuf(ByteBuf buf) { try { this.cmd.encodeAsByteBuf(buf); byte[] proxy = this.proxy.getDomain().getBytes("UTF-8"); buf.writerIndex(START_DOMAIN).writeByte(proxy.length).writeBytes(proxy).writeByte(0).writeByte(0); } catch (Exception e) { throw new RuntimeException(e); } } }
private SocksCmdResponse getFailureResponse(SocksCmdRequest request) { return new SocksCmdResponse(SocksCmdStatus.FAILURE, SocksAddressType.IPv4); }
@Override public void encodeAsByteBuf(ByteBuf byteBuf) { byteBuf.writeByte(protocolVersion().byteValue()); byteBuf.writeByte(cmdStatus.byteValue()); byteBuf.writeByte(0x00);
private SocksCmdResponse getSuccessResponse(SocksCmdRequest request) { return new SocksCmdResponse(SocksCmdStatus.SUCCESS, SocksAddressType.IPv4); }
@Override public void encodeAsByteBuf(ByteBuf byteBuf) { byteBuf.writeByte(protocolVersion().byteValue()); byteBuf.writeByte(cmdStatus.byteValue()); byteBuf.writeByte(0x00);
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { ctx.channel().writeAndFlush(new SocksCmdResponse(SocksCmdStatus.FAILURE, request.addressType())); if (ctx.channel().isActive()) { ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } } } });
private ByteBuf buildCmd(BytestreamsProxy proxy) { ByteBuf buf = Unpooled.buffer(); new SocksCmdResponseWrap(proxy, new SocksCmdResponse(SocksCmdStatus.SUCCESS, SocksAddressType.DOMAIN)).encodeAsByteBuf(buf); return buf; }
String host = NetUtil.intToIpAddress(byteBuf.readInt()); int port = byteBuf.readUnsignedShort(); out.add(new SocksCmdResponse(cmdStatus, addressType, host, port)); break; String host = SocksCommonUtils.readUsAscii(byteBuf, fieldLength); int port = byteBuf.readUnsignedShort(); out.add(new SocksCmdResponse(cmdStatus, addressType, host, port)); break; String host = SocksCommonUtils.ipv6toStr(bytes); int port = byteBuf.readUnsignedShort(); out.add(new SocksCmdResponse(cmdStatus, addressType, host, port)); break;
String host = NetUtil.intToIpAddress(byteBuf.readInt()); int port = byteBuf.readUnsignedShort(); out.add(new SocksCmdResponse(cmdStatus, addressType, host, port)); break; String host = SocksCommonUtils.readUsAscii(byteBuf, fieldLength); int port = byteBuf.readUnsignedShort(); out.add(new SocksCmdResponse(cmdStatus, addressType, host, port)); break; String host = SocksCommonUtils.ipv6toStr(bytes); int port = byteBuf.readUnsignedShort(); out.add(new SocksCmdResponse(cmdStatus, addressType, host, port)); break;
InetSocketAddress udpAddr = UdpServer.getUdpAddr(); ctx.channel() .writeAndFlush(new SocksCmdResponse(SocksCmdStatus.SUCCESS, SocksAddressType.IPv4, udpAddr.getHostString(), udpAddr.getPort())); } else { ctx.channel() .writeAndFlush(new SocksCmdResponse(SocksCmdStatus.SUCCESS, request.addressType())) .addListener(channelFuture -> { ByteBuf byteBuf = Unpooled.buffer(); ctx.channel().writeAndFlush(new SocksCmdResponse(SocksCmdStatus.FAILURE, request.addressType()));
ctx.write(new SocksCmdResponse(SocksCmdStatus.ADDRESS_NOT_SUPPORTED, ((SocksCmdRequest) request).addressType())); log.warn("\tBad Handshake! (UDP request addr_type not support: {})", ((SocksCmdRequest) request).addressType()); ctx.close();