# ne7ssh_transport Class Reference

`#include <ne7ssh_transport.h>`

Collaboration diagram for ne7ssh_transport:

[legend]

List of all members.

## 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

## Detailed Description

Author:
  Andrew Useckas

## Constructor & Destructor Documentation

ne7ssh_transport::ne7ssh_transport | ( | ne7ssh_session * | _session | ) |

ne7ssh_transport class constructor.

Transport class handles all socket communications for the ne7ssh library.

Parameters:

  | _session | Pointer to ne7ssh_session instance.

ne7ssh_transport::~ne7ssh_transport | ( |  | ) |

ne7ssh_transport class destructor.

## Member Function Documentation

SOCKET ne7ssh_transport::establish | ( | const char * | host,
|  | uint32 | port,
|  | int | timeout = `0` |
| ) |  |  |

Establishes connection to a remote host.

Parameters:

  | host | Host name or IP.
  | port | Port.
  | timeout | Timeout for the establish procedure, in seconds.

Returns:
  Socket number or -1 on failure.

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.

Parameters:

  | result | The payload will be stored here.

Returns:
  The SSH packet passing length.

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.

Returns:
  True if there is data to be read, otherwise false is returned.

References wait().

bool ne7ssh_transport::NoBlock | ( | SOCKET | socket,
|  | bool | on |
| ) |  |  | `[private]`

Switches socket's NonBlocking option on or off.

Parameters:

  | socket | Socket number.
  | on | If set to true, NonBlocking option will be turned on, and vice versa.

Returns:
  True if options have been successfuly set, otherwise false is returned.

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.

Parameters:

  | buffer | The data will be placed here.
  | append | If set to true, received data will be appended to the buffer, instead of overwriting it.

Returns:
  True if data successfuly read, otherwise false is returned.

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.

Parameters:

  | buffer | Data to be written to the socket.

Returns:
  True if data successful sent, otherwise false is returned.

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.

Parameters:

  | buffer | Payload to be sent.

Returns:
  True if send successful, otherwise false is returned.

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.

Parameters:

  | 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.

Returns:
  True if socket is ready for reading/writting, otherwise false is returned.

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.

Parameters:

  | 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.

Returns:
  1 if desired packet is received, 0 if there another packet is received, or -1 if HMAC checking is enabled, and remote and local HMACs do not match.

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().

The documentation for this class was generated from the following files:

- ne7ssh_transport.h
- ne7ssh_transport.cpp