예제 #1
0
  void SocksConnection::HandleRequest() 
  {
    if(_socket->bytesAvailable() < _addr_len) {
      return;
    }

    QByteArray socks_addr = _socket->read(_addr_len);
    QString host;
    quint16 port;
    if(!ParseSocksAddress(socks_addr, host, port)) {
      EstablishFail(SocksReply_AddressTypeNotSupported);
      return;
    }

    qDebug() << "SOCKS Host Parsed:" << host << port;

    switch(_command) {
      case SocksCommand_Connect:
        StartConnect(host, port);
        break;
      case SocksCommand_UdpAssociate:
        StartUdpAssociate(host, port);
        break;
      default:
        qDebug() << "FAIL: Command not supported";
        EstablishFail(SocksReply_CommandNotSupported);
        return;
    }

    if(_socket->bytesAvailable()) {
      ReadFromSocket();
    }
  }
예제 #2
0
  void SocksConnection::ProcessRequest() {
    if(_addr_buf.count() < 3) {
      qDebug() << "Address string is too short";
      return EstablishFail(SocksReply_AddressTypeNotSupported);
    }

    int bytes_read;
    SocksHostAddress dest_addr;

    SocksAddressType code = ParseSocksAddressBytes(_addr_type, _addr_buf, dest_addr, bytes_read);

    if(!(code == SocksAddress_IPv4 || code == SocksAddress_DomainName)) {
      qDebug() << "SOCKS FAIL!";
      return EstablishFail(SocksReply_AddressTypeNotSupported);
    }

    qDebug() << "SOCKS Parsed Host" << dest_addr.ToString();

    switch(_command) {
      case SocksCommand_Connect:
        StartConnect(dest_addr);
        return;

      case SocksCommand_UdpAssociate:
        StartUdpAssociate(dest_addr);
        return;

      default:
        qDebug() << "FAIL: Command not supported";
        return EstablishFail(SocksReply_CommandNotSupported);
    } 
  }