Logo Search packages:      
Sourcecode: pwlib version File versions

BOOL PSocks4Socket::ReceiveSocksResponse ( PTCPSocket socket,
PIPSocket::Address addr,
WORD &  port 
) [protected, virtual]

= SOCKS_VERSION_4

Reimplemented from PSocksProtocol.

Definition at line 508 of file socks.cxx.

References PChannel::AccessDenied, PChannel::Miscellaneous, PSocket::Net2Host(), PChannel::NotFound, PChannel::ReadBlock(), and PChannel::ReadChar().

{
  int reply;
  if ((reply = socket.ReadChar()) < 0)
    return FALSE;

  if (reply != 0 /*!= SOCKS_VERSION_4*/) {
    SetErrorCodes(PChannel::Miscellaneous, EINVAL);
    return FALSE;
  }

  if ((reply = socket.ReadChar()) < 0)
    return FALSE;

  switch (reply) {
    case 90 :  // No error
      break;

    case 91 : // Connection refused
      SetErrorCodes(PChannel::NotFound, EHOSTUNREACH);
      return FALSE;

    case 92 :  // Refused permission
      SetErrorCodes(PChannel::AccessDenied, EACCES);
      return FALSE;

    default :
      SetErrorCodes(PChannel::Miscellaneous, EINVAL);
      return FALSE;
  }

  WORD rxPort;
  if (!socket.ReadBlock(&rxPort, sizeof(rxPort)))
    return FALSE;

  port = PSocket::Net2Host(rxPort);

  in_addr add;
  if ( socket.ReadBlock(&add, sizeof(add)) )
  {
    addr = add;
    return TRUE;
  }

  return FALSE;
}


Generated by  Doxygen 1.6.0   Back to index