Esempio n. 1
0
        static byte[] GetCommandResponse(Socks5Reply reply, IPEndPoint server)
        {
            // +-----+-----+-------+------+----------+----------+
            // | VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |
            // +-----+-----+-------+------+----------+----------+
            // |  1  |  1  | X'00' |  1   | Variable |    2     |
            // +-----+-----+-------+------+----------+----------+
            var addr     = server?.Address.GetAddressBytes();
            var response = new byte[6 + (addr != null ? addr.Length : 0)];
            int port     = server != null ? server.Port : 0;
            int n        = 0;

            response[n++] = 0x05;
            response[n++] = (byte)reply;
            response[n++] = 0x00;
            if (server != null)
            {
                if (server.Address.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    response[n++] = (byte)Socks5AddressType.IPv6;
                }
                else
                {
                    response[n++] = (byte)Socks5AddressType.IPv4;
                }
                Buffer.BlockCopy(addr, 0, response, n, addr.Length);
                n            += addr.Length;
                response[n++] = (byte)(port >> 8);
                response[n++] = (byte)port;
            }

            return(response);
        }
Esempio n. 2
0
 public Socks5ProtocolErrorException(string message, Socks5Reply socks5Reply) : base(message)
 {
     Socks5Reply = socks5Reply;
 }