Browse Source

Define socks5 command

tags/4.1.8.0
celeron533 5 years ago
parent
commit
aa8dac1a10
1 changed files with 17 additions and 12 deletions
  1. +17
    -12
      shadowsocks-csharp/Controller/Service/TCPRelay.cs

+ 17
- 12
shadowsocks-csharp/Controller/Service/TCPRelay.cs View File

@@ -157,6 +157,7 @@ namespace Shadowsocks.Controller
private int _firstPacketLength; private int _firstPacketLength;
private const int CMD_CONNECT = 0x01; private const int CMD_CONNECT = 0x01;
private const int CMD_BIND = 0x02;
private const int CMD_UDP_ASSOC = 0x03; private const int CMD_UDP_ASSOC = 0x03;
private int _addrBufLength = -1; private int _addrBufLength = -1;
@@ -339,23 +340,27 @@ namespace Shadowsocks.Controller
if (bytesRead >= 5) if (bytesRead >= 5)
{ {
_command = _connetionRecvBuffer[1]; _command = _connetionRecvBuffer[1];
if (_command != CMD_CONNECT && _command != CMD_UDP_ASSOC)
switch(_command)
{ {
Logging.Debug("Unsupported CMD=" + _command);
Close();
}
else
{
if (_command == CMD_CONNECT)
{
case CMD_CONNECT:
// +----+-----+-------+------+----------+----------+
// |VER | REP | RSV | ATYP | BND.ADDR | BND.PORT |
// +----+-----+-------+------+----------+----------+
// | 1 | 1 | X'00' | 1 | Variable | 2 |
// +----+-----+-------+------+----------+----------+
byte[] response = { 5, 0, 0, 1, 0, 0, 0, 0, 0, 0 }; byte[] response = { 5, 0, 0, 1, 0, 0, 0, 0, 0, 0 };
_connection.BeginSend(response, 0, response.Length, SocketFlags.None, _connection.BeginSend(response, 0, response.Length, SocketFlags.None,
ResponseCallback, null); ResponseCallback, null);
}
else if (_command == CMD_UDP_ASSOC)
{
break;
case CMD_UDP_ASSOC:
ReadAddress(HandleUDPAssociate); ReadAddress(HandleUDPAssociate);
}
break;
case CMD_BIND: // not implemented
default:
Logging.Debug("Unsupported CMD=" + _command);
Close();
break;
} }
} }
else else


Loading…
Cancel
Save