#include <ne7ssh_transport.h>
Public Member Functions | |
ne7ssh_transport (ne7ssh_session *_session) | |
~ne7ssh_transport () | |
SOCKET | establish (const char *host, uint32 port, int timeout=0) |
bool | receive (Botan::SecureVector< Botan::byte > &buffer, bool append=false) |
bool | send (Botan::SecureVector< Botan::byte > &buffer) |
bool | sendPacket (Botan::SecureVector< Botan::byte > &buffer) |
short | waitForPacket (Botan::byte cmd, bool bufferOnly=false) |
uint32 | getPacket (Botan::SecureVector< Botan::byte > &result) |
bool | haveData () |
Private Member Functions | |
bool | NoBlock (SOCKET socket, bool on) |
bool | wait (SOCKET socket, int rw, int timeout=-1) |
Private Attributes | |
uint32 | seq |
uint32 | rSeq |
const ne7ssh_session * | session |
SOCKET | sock |
Botan::SecureVector< Botan::byte > | in |
Botan::SecureVector< Botan::byte > | inBuffer |
ne7ssh_transport::ne7ssh_transport | ( | ne7ssh_session * | _session | ) |
ne7ssh_transport class constructor.
Transport class handles all socket communications for the ne7ssh library.
_session | Pointer to ne7ssh_session instance. |
ne7ssh_transport::~ne7ssh_transport | ( | ) |
ne7ssh_transport class destructor.
SOCKET ne7ssh_transport::establish | ( | const char * | host, | |
uint32 | port, | |||
int | timeout = 0 | |||
) |
Establishes connection to a remote host.
host | Host name or IP. | |
port | Port. | |
timeout | Timeout for the establish procedure, in seconds. |
References ne7ssh::errors(), NoBlock(), and Ne7sshError::push().
Referenced by ne7ssh_connection::connectWithKey(), and ne7ssh_connection::connectWithPassword().
uint32 ne7ssh_transport::getPacket | ( | Botan::SecureVector< Botan::byte > & | result | ) |
Gets the payload section from an SSH packet received by waitForPacket() function.
result | The payload will be stored here. |
References ne7ssh_crypt::decompressData(), ne7ssh_crypt::getMacInLen(), and ne7ssh_crypt::isInited().
Referenced by ne7ssh_connection::authWithKey(), ne7ssh_connection::authWithPassword(), ne7ssh_channel::handleChannelConfirm(), ne7ssh_kex::handleInit(), ne7ssh_kex::handleKexDHReply(), ne7ssh_channel::receive(), Ne7sshSftp::receiveUntil(), Ne7sshSftp::receiveWhile(), and Ne7sshSftp::receiveWindowAdjust().
bool ne7ssh_transport::haveData | ( | ) |
Checks to see if there is more data to be read from the socket.
References wait().
bool ne7ssh_transport::NoBlock | ( | SOCKET | socket, | |
bool | on | |||
) | [private] |
Switches socket's NonBlocking option on or off.
socket | Socket number. | |
on | If set to true, NonBlocking option will be turned on, and vice versa. |
References ne7ssh::errors(), and Ne7sshError::push().
Referenced by establish().
bool ne7ssh_transport::receive | ( | Botan::SecureVector< Botan::byte > & | buffer, | |
bool | append = false | |||
) |
Reads data from the socket.
buffer | The data will be placed here. | |
append | If set to true, received data will be appended to the buffer, instead of overwriting it. |
References ne7ssh::errors(), Ne7sshError::push(), and wait().
Referenced by ne7ssh_connection::checkRemoteVersion(), and waitForPacket().
bool ne7ssh_transport::send | ( | Botan::SecureVector< Botan::byte > & | buffer | ) |
Writes a buffer to the socket.
buffer | Data to be written to the socket. |
References ne7ssh::errors(), Ne7sshError::push(), and wait().
Referenced by ne7ssh_connection::sendLocalVersion(), and sendPacket().
bool ne7ssh_transport::sendPacket | ( | Botan::SecureVector< Botan::byte > & | buffer | ) |
Assembles an SSH packet, as specified in SSH standards and passes the buffer to send() function.
buffer | Payload to be sent. |
References ne7ssh_string::addBytes(), ne7ssh_string::addChar(), ne7ssh_string::addInt(), ne7ssh_string::addVector(), ne7ssh_crypt::encryptPacket(), ne7ssh::errors(), ne7ssh_crypt::getEncryptBlock(), ne7ssh_crypt::isInited(), Ne7sshError::push(), send(), and ne7ssh_string::value().
Referenced by ne7ssh_connection::authWithKey(), ne7ssh_connection::authWithPassword(), ne7ssh_channel::execCmd(), ne7ssh_channel::getShell(), Ne7sshSftp::init(), ne7ssh_channel::open(), ne7ssh_connection::requestService(), ne7ssh_channel::sendAdjustWindow(), ne7ssh_channel::sendAll(), ne7ssh_channel::sendClose(), ne7ssh_channel::sendEof(), ne7ssh_kex::sendInit(), ne7ssh_kex::sendKexDHInit(), and ne7ssh_kex::sendKexNewKeys().
bool ne7ssh_transport::wait | ( | SOCKET | socket, | |
int | rw, | |||
int | timeout = -1 | |||
) | [private] |
Waits for activity on a socket.
socket | Socket number. | |
rw | If set to true, checks if process can write to the socket, otherwise checks if there is data to be read from the socket. | |
timeout | Desired timeout. By default the function will block until socket is ready for reading/writting. If set to '0', the function will return right away. |
Referenced by haveData(), receive(), and send().
short ne7ssh_transport::waitForPacket | ( | Botan::byte | cmd, | |
bool | bufferOnly = false | |||
) |
Waits until specified type of packet is received.
If cmd is 0, waits for the first available packet of any kind.
Once the desired packet is received, it is decrypted / decommpressed, the hMac is checked, and dropped into inBuffer class variable.
cmd | SSH2 packet to wait for. If 0, first available packet will be read into inBuffer class variable. | |
bufferOnly | Does not wait to receive a new packet, only checks existing receive buffer for unprocessed packets. |
References ne7ssh_crypt::computeMac(), ne7ssh_crypt::decryptPacket(), ne7ssh::errors(), ne7ssh_crypt::getDecryptBlock(), ne7ssh_crypt::getMacInLen(), ne7ssh_crypt::isInited(), Ne7sshError::push(), and receive().
Referenced by ne7ssh_connection::authWithKey(), ne7ssh_connection::authWithPassword(), ne7ssh_channel::open(), ne7ssh_channel::receive(), Ne7sshSftp::receiveUntil(), Ne7sshSftp::receiveWhile(), Ne7sshSftp::receiveWindowAdjust(), ne7ssh_connection::requestService(), ne7ssh_kex::sendInit(), ne7ssh_kex::sendKexDHInit(), and ne7ssh_kex::sendKexNewKeys().