libssh  0.7
Functions
The SSH session functions.

Functions that manage a session. More...

Functions

int ssh_blocking_flush (ssh_session session, int timeout)
 Blocking flush of the outgoing buffer. More...
 
void ssh_clean_pubkey_hash (unsigned char **hash)
 Deallocate the hash obtained by ssh_get_pubkey_hash. More...
 
int ssh_connect (ssh_session session)
 Connect to the ssh server. More...
 
void ssh_disconnect (ssh_session session)
 Disconnect from a session (client or server). More...
 
void ssh_free (ssh_session session)
 Deallocate a SSH session handle. More...
 
const char * ssh_get_cipher_in (ssh_session session)
 get the name of the input cipher for the given session. More...
 
const char * ssh_get_cipher_out (ssh_session session)
 get the name of the output cipher for the given session. More...
 
const char * ssh_get_clientbanner (ssh_session session)
 get the client banner More...
 
const char * ssh_get_disconnect_message (ssh_session session)
 Get the disconnect message from the server. More...
 
socket_t ssh_get_fd (ssh_session session)
 Get the fd of a connection. More...
 
char * ssh_get_hexa (const unsigned char *what, size_t len)
 Convert a buffer into a colon separated hex string. More...
 
const char * ssh_get_hmac_in (ssh_session session)
 get the name of the input HMAC algorithm for the given session. More...
 
const char * ssh_get_hmac_out (ssh_session session)
 get the name of the output HMAC algorithm for the given session. More...
 
char * ssh_get_issue_banner (ssh_session session)
 Get the issue banner from the server. More...
 
const char * ssh_get_kex_algo (ssh_session session)
 get the name of the current key exchange algorithm. More...
 
int ssh_get_openssh_version (ssh_session session)
 Get the version of the OpenSSH server, if it is not an OpenSSH server then 0 will be returned. More...
 
int ssh_get_poll_flags (ssh_session session)
 Get poll flags for an external mainloop. More...
 
int ssh_get_pubkey_hash (ssh_session session, unsigned char **hash)
 
int ssh_get_publickey (ssh_session session, ssh_key *key)
 Get the server public key from a session. More...
 
int ssh_get_publickey_hash (const ssh_key key, enum ssh_publickey_hash_type type, unsigned char **hash, size_t *hlen)
 Allocates a buffer with the hash of the public key. More...
 
const char * ssh_get_serverbanner (ssh_session session)
 get the server banner More...
 
int ssh_get_status (ssh_session session)
 Get session status. More...
 
int ssh_get_version (ssh_session session)
 Get the protocol version of the session. More...
 
int ssh_is_blocking (ssh_session session)
 Return the blocking mode of libssh. More...
 
int ssh_is_connected (ssh_session session)
 Check if we are connected. More...
 
int ssh_is_server_known (ssh_session session)
 Check if the server is known. More...
 
ssh_session ssh_new (void)
 Create a new ssh session. More...
 
int ssh_options_copy (ssh_session src, ssh_session *dest)
 Duplicate the options of a session structure. More...
 
int ssh_options_get (ssh_session session, enum ssh_options_e type, char **value)
 This function can get ssh options, it does not support all options provided for ssh options set, but mostly those which a user-space program may care about having trusted the ssh driver to infer these values from underlaying configuration files. More...
 
int ssh_options_get_port (ssh_session session, unsigned int *port_target)
 This function can get ssh the ssh port. More...
 
int ssh_options_getopt (ssh_session session, int *argcptr, char **argv)
 Parse command line arguments. More...
 
int ssh_options_parse_config (ssh_session session, const char *filename)
 Parse the ssh config file. More...
 
int ssh_options_set (ssh_session session, enum ssh_options_e type, const void *value)
 This function can set all possible ssh options. More...
 
void ssh_print_hexa (const char *descr, const unsigned char *what, size_t len)
 Print a buffer as colon separated hex string. More...
 
int ssh_select (ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd, fd_set *readfds, struct timeval *timeout)
 A wrapper for the select syscall. More...
 
int ssh_send_debug (ssh_session session, const char *message, int always_display)
 Send a debug message. More...
 
int ssh_send_ignore (ssh_session session, const char *data)
 Send a message that should be ignored. More...
 
void ssh_set_blocking (ssh_session session, int blocking)
 Set the session in blocking/nonblocking mode. More...
 
void ssh_set_counters (ssh_session session, ssh_counter scounter, ssh_counter rcounter)
 Set the session data counters. More...
 
void ssh_set_fd_except (ssh_session session)
 Tell the session it has an exception to catch on the file descriptor. More...
 
void ssh_set_fd_toread (ssh_session session)
 Tell the session it has data to read on the file descriptor without blocking. More...
 
void ssh_set_fd_towrite (ssh_session session)
 Tell the session it may write to the file descriptor without blocking. More...
 
void ssh_silent_disconnect (ssh_session session)
 Disconnect impolitely from a remote host by closing the socket. More...
 
int ssh_write_knownhost (ssh_session session)
 Write the current server as known in the known hosts file. More...
 

Detailed Description

Functions that manage a session.

Function Documentation

int ssh_blocking_flush ( ssh_session  session,
int  timeout 
)

Blocking flush of the outgoing buffer.

Parameters
[in]sessionThe SSH session
[in]timeoutSet an upper limit on the time for which this function will block, in milliseconds. Specifying -1 means an infinite timeout. This parameter is passed to the poll() function.
Returns
SSH_OK on success, SSH_AGAIN if timeout occurred, SSH_ERROR otherwise.
void ssh_clean_pubkey_hash ( unsigned char **  hash)

Deallocate the hash obtained by ssh_get_pubkey_hash.

This is required under Microsoft platform as this library might use a different C library than your software, hence a different heap.

Parameters
[in]hashThe buffer to deallocate.
See also
ssh_get_pubkey_hash()
int ssh_connect ( ssh_session  session)

Connect to the ssh server.

Parameters
[in]sessionThe ssh session to connect.
Returns
SSH_OK on success, SSH_ERROR on error.
SSH_AGAIN, if the session is in nonblocking mode, and call must be done again.
See also
ssh_new()
ssh_disconnect()

References ssh_init(), ssh_is_blocking(), SSH_LOG_PACKET, and SSH_LOG_PROTOCOL.

Referenced by ssh::Session::connect().

void ssh_disconnect ( ssh_session  session)

Disconnect from a session (client or server).

The session can then be reused to open a new session.

Parameters
[in]sessionThe SSH session to use.

References ssh_message_free().

Referenced by ssh::Session::disconnect(), and ssh_silent_disconnect().

void ssh_free ( ssh_session  session)

Deallocate a SSH session handle.

Parameters
[in]sessionThe SSH session to free.
See also
ssh_disconnect()
ssh_new()

References ssh_buffer_free(), ssh_key_free(), ssh_message_free(), and ssh_poll_ctx_free().

Referenced by ssh_new(), and ssh_options_copy().

const char* ssh_get_cipher_in ( ssh_session  session)

get the name of the input cipher for the given session.

Parameters
[in]sessionThe SSH session.
Returns
Returns cipher name or NULL.
const char* ssh_get_cipher_out ( ssh_session  session)

get the name of the output cipher for the given session.

Parameters
[in]sessionThe SSH session.
Returns
Returns cipher name or NULL.
const char* ssh_get_clientbanner ( ssh_session  session)

get the client banner

Parameters
[in]sessionThe SSH session
Returns
Returns the client banner string or NULL.
const char* ssh_get_disconnect_message ( ssh_session  session)

Get the disconnect message from the server.

Parameters
[in]sessionThe ssh session to use.
Returns
The message sent by the server along with the disconnect, or NULL in which case the reason of the disconnect may be found with ssh_get_error.
See also
ssh_get_error()

Referenced by ssh::Session::getDisconnectMessage().

socket_t ssh_get_fd ( ssh_session  session)

Get the fd of a connection.

In case you'd need the file descriptor of the connection to the server/client.

Parameters
[in]sessionThe ssh session to use.
Returns
The file descriptor of the connection, or -1 if it is not connected

Referenced by ssh::Session::getSocket().

char* ssh_get_hexa ( const unsigned char *  what,
size_t  len 
)

Convert a buffer into a colon separated hex string.

The caller has to free the memory.

Parameters
whatWhat should be converted to a hex string.
lenLength of the buffer to convert.
Returns
The hex string or NULL on error.
See also
ssh_string_free_char()

Referenced by ssh_print_hexa().

const char* ssh_get_hmac_in ( ssh_session  session)

get the name of the input HMAC algorithm for the given session.

Parameters
[in]sessionThe SSH session.
Returns
Returns HMAC algorithm name or NULL if unknown.
const char* ssh_get_hmac_out ( ssh_session  session)

get the name of the output HMAC algorithm for the given session.

Parameters
[in]sessionThe SSH session.
Returns
Returns HMAC algorithm name or NULL if unknown.
char* ssh_get_issue_banner ( ssh_session  session)

Get the issue banner from the server.

This is the banner showing a disclaimer to users who log in, typically their right or the fact that they will be monitored.

Parameters
[in]sessionThe SSH session to use.
Returns
A newly allocated string with the banner, NULL on error.

References ssh_string_to_char().

Referenced by ssh::Session::getIssueBanner().

const char* ssh_get_kex_algo ( ssh_session  session)

get the name of the current key exchange algorithm.

Parameters
[in]sessionThe SSH session
Returns
Returns the key exchange algorithm string or NULL.
int ssh_get_openssh_version ( ssh_session  session)

Get the version of the OpenSSH server, if it is not an OpenSSH server then 0 will be returned.

You can use the SSH_VERSION_INT macro to compare version numbers.

Parameters
[in]sessionThe SSH session to use.
Returns
The version number if available, 0 otherwise.
1 int openssh = ssh_get_openssh_version();
2 
3 if (openssh == SSH_INT_VERSION(6, 1, 0)) {
4  printf("Version match!\m");
5 }

Referenced by ssh::Session::getOpensshVersion(), and sftp_symlink().

int ssh_get_poll_flags ( ssh_session  session)

Get poll flags for an external mainloop.

Parameters
sessionThe ssh session to use.
Returns
A bitmask including SSH_READ_PENDING or SSH_WRITE_PENDING. For SSH_READ_PENDING, your invocation of poll() should include POLLIN. For SSH_WRITE_PENDING, your invocation of poll() should include POLLOUT.
int ssh_get_pubkey_hash ( ssh_session  session,
unsigned char **  hash 
)
int ssh_get_publickey ( ssh_session  session,
ssh_key *  key 
)

Get the server public key from a session.

Parameters
[in]sessionThe session to get the key from.
[out]keyA pointer to store the allocated key. You need to free the key.
Returns
SSH_OK on success, SSH_ERROR on errror.
See also
ssh_key_free()
int ssh_get_publickey_hash ( const ssh_key  key,
enum ssh_publickey_hash_type  type,
unsigned char **  hash,
size_t *  hlen 
)

Allocates a buffer with the hash of the public key.

This function allows you to get a hash of the public key. You can then print this hash in a human-readable form to the user so that he is able to verify it. Use ssh_get_hexa() or ssh_print_hexa() to display it.

Parameters
[in]keyThe public key to create the hash for.
[in]typeThe type of the hash you want.
[in]hashA pointer to store the allocated buffer. It can be freed using ssh_clean_pubkey_hash().
[in]hlenThe length of the hash.
Returns
0 on success, -1 if an error occured.
Warning
It is very important that you verify at some moment that the hash matches a known server. If you don't do it, cryptography wont help you at making things secure. OpenSSH uses SHA1 to print public key digests.
See also
ssh_is_server_known()
ssh_get_hexa()
ssh_print_hexa()
ssh_clean_pubkey_hash()

References ssh_string_data(), ssh_string_free(), and ssh_string_len().

const char* ssh_get_serverbanner ( ssh_session  session)

get the server banner

Parameters
[in]sessionThe SSH session
Returns
Returns the server banner string or NULL.
int ssh_get_status ( ssh_session  session)

Get session status.

Parameters
sessionThe ssh session to use.
Returns
A bitmask including SSH_CLOSED, SSH_READ_PENDING, SSH_WRITE_PENDING or SSH_CLOSED_ERROR which respectively means the session is closed, has data to read on the connection socket and session was closed due to an error.
int ssh_get_version ( ssh_session  session)

Get the protocol version of the session.

Parameters
sessionThe ssh session to use.
Returns
1 or 2, for ssh1 or ssh2, < 0 on error.

Referenced by ssh::Session::getVersion().

int ssh_is_blocking ( ssh_session  session)

Return the blocking mode of libssh.

Parameters
[in]sessionThe SSH session
Returns
0 if the session is nonblocking,
1 if the functions may block.

Referenced by ssh_channel_read_nonblocking(), and ssh_connect().

int ssh_is_connected ( ssh_session  session)

Check if we are connected.

Parameters
[in]sessionThe session to check if it is connected.
Returns
1 if we are connected, 0 if not.
int ssh_is_server_known ( ssh_session  session)

Check if the server is known.

Checks the user's known host file for a previous connection to the current server.

Parameters
[in]sessionThe SSH session to use.
Returns
SSH_SERVER_KNOWN_OK: The server is known and has not changed.
SSH_SERVER_KNOWN_CHANGED: The server key has changed. Either you are under attack or the administrator changed the key. You HAVE to warn the user about a possible attack.
SSH_SERVER_FOUND_OTHER: The server gave use a key of a type while we had an other type recorded. It is a possible attack.
SSH_SERVER_NOT_KNOWN: The server is unknown. User should confirm the MD5 is correct.
SSH_SERVER_FILE_NOT_FOUND: The known host file does not exist. The host is thus unknown. File will be created if host key is accepted.
SSH_SERVER_ERROR: Some error happened.
See also
ssh_get_pubkey_hash()
Bug:
There is no current way to remove or modify an entry into the known host table.

References SSH_LOG_PACKET, and ssh_write_knownhost().

Referenced by ssh::Session::isServerKnown().

ssh_session ssh_new ( void  )

Create a new ssh session.

Returns
A new ssh_session pointer, NULL on error.

References ssh_buffer_new(), ssh_free(), and ssh_set_blocking().

Referenced by ssh_options_copy().

int ssh_options_copy ( ssh_session  src,
ssh_session *  dest 
)

Duplicate the options of a session structure.

If you make several sessions with the same options this is useful. You cannot use twice the same option structure in ssh_session_connect.

Parameters
srcThe session to use to copy the options.
destA pointer to store the allocated session with duplicated options. You have to free the memory.
Returns
0 on sucess, -1 on error with errno set.
See also
ssh_session_connect()

References ssh_free(), and ssh_new().

Referenced by ssh::Session::optionsCopy().

int ssh_options_get ( ssh_session  session,
enum ssh_options_e  type,
char **  value 
)

This function can get ssh options, it does not support all options provided for ssh options set, but mostly those which a user-space program may care about having trusted the ssh driver to infer these values from underlaying configuration files.

It operates only on those SSH_OPTIONS_* which return char*. If you wish to receive the port then please use ssh_options_get_port() which returns an unsigned int.

Parameters
sessionAn allocated SSH session structure.
typeThe option type to get. This could be one of the following:
  • SSH_OPTIONS_HOST: The hostname or ip address to connect to (const char *).
  • SSH_OPTIONS_USER: The username for authentication (const char *).

    when not explicitly set this will be inferred from the ~/.ssh/config file.
  • SSH_OPTIONS_IDENTITY: Set the identity file name (const char *,format string).

    By default identity, id_dsa and id_rsa are checked.

    The identity file used authenticate with public key. It may include "%s" which will be replaced by the user home directory.
  • SSH_OPTIONS_PROXYCOMMAND: Get the proxycommand necessary to log into the remote host. When not explicitly set, it will be read from the ~/.ssh/config file.
Parameters
valueThe value to get into. As a char**, space will be allocated by the function for the value, it is your responsibility to free the memory using ssh_string_free_char().
Returns
SSH_OK on success, SSH_ERROR on error.
int ssh_options_get_port ( ssh_session  session,
unsigned int *  port_target 
)

This function can get ssh the ssh port.

It must only be used on a valid ssh session. This function is useful when the session options have been automatically inferred from the environment or configuration files and one

Parameters
sessionAn allocated SSH session structure.
port_targetAn unsigned integer into which the port will be set from the ssh session.
Returns
0 on success, < 0 on error.
int ssh_options_getopt ( ssh_session  session,
int *  argcptr,
char **  argv 
)

Parse command line arguments.

This is a helper for your application to generate the appropriate options from the command line arguments.
The argv array and argc value are changed so that the parsed arguments wont appear anymore in them.
The single arguments (without switches) are not parsed. thus, myssh -l user localhost
The command wont set the hostname value of options to localhost.

Parameters
sessionThe session to configure.
argcptrThe pointer to the argument count.
argvThe arguments list pointer.
Returns
0 on success, < 0 on error.
See also
ssh_session_new()

References ssh_options_set(), and ssh_set_log_level().

int ssh_options_parse_config ( ssh_session  session,
const char *  filename 
)

Parse the ssh config file.

This should be the last call of all options, it may overwrite options which are already set. It requires that the host name is already set with ssh_options_set_host().

Parameters
sessionSSH session handle
filenameThe options file to use, if NULL the default ~/.ssh/config will be used.
Returns
0 on success, < 0 on error.
See also
ssh_options_set_host()

References ssh_options_set().

Referenced by ssh::Session::optionsParseConfig().

int ssh_options_set ( ssh_session  session,
enum ssh_options_e  type,
const void *  value 
)

This function can set all possible ssh options.

Parameters
sessionAn allocated SSH session structure.
typeThe option type to set. This could be one of the following:
  • SSH_OPTIONS_HOST: The hostname or ip address to connect to (const char *).
  • SSH_OPTIONS_PORT: The port to connect to (unsigned int).
  • SSH_OPTIONS_PORT_STR: The port to connect to (const char *).
  • SSH_OPTIONS_FD: The file descriptor to use (socket_t).

    If you wish to open the socket yourself for a reason or another, set the file descriptor. Don't forget to set the hostname as the hostname is used as a key in the known_host mechanism.
  • SSH_OPTIONS_BINDADDR: The address to bind the client to (const char *).
  • SSH_OPTIONS_USER: The username for authentication (const char *).

    If the value is NULL, the username is set to the default username.
  • SSH_OPTIONS_SSH_DIR: Set the ssh directory (const char *,format string).

    If the value is NULL, the directory is set to the default ssh directory.

    The ssh directory is used for files like known_hosts and identity (private and public key). It may include "%s" which will be replaced by the user home directory.
  • SSH_OPTIONS_KNOWNHOSTS: Set the known hosts file name (const char *,format string).

    If the value is NULL, the directory is set to the default known hosts file, normally ~/.ssh/known_hosts.

    The known hosts file is used to certify remote hosts are genuine. It may include "%s" which will be replaced by the user home directory.
  • SSH_OPTIONS_IDENTITY: Set the identity file name (const char *,format string).

    By default identity, id_dsa and id_rsa are checked.

    The identity file used authenticate with public key. It may include "%s" which will be replaced by the user home directory.
  • SSH_OPTIONS_TIMEOUT: Set a timeout for the connection in seconds (long).
  • SSH_OPTIONS_TIMEOUT_USEC: Set a timeout for the connection in micro seconds (long).
  • SSH_OPTIONS_SSH1: Allow or deny the connection to SSH1 servers (int, 0 is false).
  • SSH_OPTIONS_SSH2: Allow or deny the connection to SSH2 servers (int, 0 is false).
  • SSH_OPTIONS_LOG_VERBOSITY: Set the session logging verbosity (int).

    The verbosity of the messages. Every log smaller or equal to verbosity will be shown.
    • SSH_LOG_NOLOG: No logging
    • SSH_LOG_RARE: Rare conditions or warnings
    • SSH_LOG_ENTRY: API-accessible entrypoints
    • SSH_LOG_PACKET: Packet id and size
    • SSH_LOG_FUNCTIONS: Function entering and leaving
  • SSH_OPTIONS_LOG_VERBOSITY_STR: Set the session logging verbosity (const char *).

    The verbosity of the messages. Every log smaller or equal to verbosity will be shown.
    • SSH_LOG_NOLOG: No logging
    • SSH_LOG_RARE: Rare conditions or warnings
    • SSH_LOG_ENTRY: API-accessible entrypoints
    • SSH_LOG_PACKET: Packet id and size
    • SSH_LOG_FUNCTIONS: Function entering and leaving
      See the corresponding numbers in libssh.h.
  • SSH_OPTIONS_AUTH_CALLBACK: Set a callback to use your own authentication function (function pointer).
  • SSH_OPTIONS_AUTH_USERDATA: Set the user data passed to the authentication function (generic pointer).
  • SSH_OPTIONS_LOG_CALLBACK: Set a callback to use your own logging function (function pointer).
  • SSH_OPTIONS_LOG_USERDATA: Set the user data passed to the logging function (generic pointer).
  • SSH_OPTIONS_STATUS_CALLBACK: Set a callback to show connection status in realtime (function pointer).

    1 fn(void *arg, float status)

    During ssh_connect(), libssh will call the callback with status from 0.0 to 1.0.
  • SSH_OPTIONS_STATUS_ARG: Set the status argument which should be passed to the status callback (generic pointer).
  • SSH_OPTIONS_CIPHERS_C_S: Set the symmetric cipher client to server (const char *, comma-separated list).
  • SSH_OPTIONS_CIPHERS_S_C: Set the symmetric cipher server to client (const char *, comma-separated list).
  • SSH_OPTIONS_KEY_EXCHANGE: Set the key exchange method to be used (const char *, comma-separated list). ex: "ecdh-sha2-nistp256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1"
  • SSH_OPTIONS_HOSTKEYS: Set the preferred server host key types (const char *, comma-separated list). ex: "ssh-rsa,ssh-dsa,ecdh-sha2-nistp256"
  • SSH_OPTIONS_COMPRESSION_C_S: Set the compression to use for client to server communication (const char *, "yes", "no" or a specific algorithm name if needed ("zlib","zlib@openssh.com","none").
  • SSH_OPTIONS_COMPRESSION_S_C: Set the compression to use for server to client communication (const char *, "yes", "no" or a specific algorithm name if needed ("zlib","zlib@openssh.com","none").
  • SSH_OPTIONS_COMPRESSION: Set the compression to use for both directions communication (const char *, "yes", "no" or a specific algorithm name if needed ("zlib","zlib@openssh.com","none").
  • SSH_OPTIONS_COMPRESSION_LEVEL: Set the compression level to use for zlib functions. (int, value from 1 to 9, 9 being the most efficient but slower).
  • SSH_OPTIONS_STRICTHOSTKEYCHECK: Set the parameter StrictHostKeyChecking to avoid asking about a fingerprint (int, 0 = false).
  • SSH_OPTIONS_PROXYCOMMAND: Set the command to be executed in order to connect to server (const char *).
  • SSH_OPTIONS_GSSAPI_SERVER_IDENTITY Set it to specify the GSSAPI server identity that libssh should expect when connecting to the server (const char *).
  • SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY Set it to specify the GSSAPI client identity that libssh should expect when connecting to the server (const char *).
  • SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS Set it to specify that GSSAPI should delegate credentials to the server (int, 0 = false).
Parameters
valueThe value to set. This is a generic pointer and the datatype which is used should be set according to the type set.
Returns
0 on success, < 0 on error.

References ssh_path_expand_tilde(), and ssh_set_log_level().

Referenced by ssh::Session::setOption(), ssh_options_getopt(), and ssh_options_parse_config().

void ssh_print_hexa ( const char *  descr,
const unsigned char *  what,
size_t  len 
)

Print a buffer as colon separated hex string.

Parameters
descrDescription printed in front of the hex string.
whatWhat should be converted to a hex string.
lenLength of the buffer to convert.

References ssh_get_hexa().

int ssh_select ( ssh_channel *  channels,
ssh_channel *  outchannels,
socket_t  maxfd,
fd_set *  readfds,
struct timeval *  timeout 
)

A wrapper for the select syscall.

This functions acts more or less like the select(2) syscall.
There is no support for writing or exceptions.

Parameters
[in]channelsArrays of channels pointers terminated by a NULL. It is never rewritten.
[out]outchannelsArrays of same size that "channels", there is no need to initialize it.
[in]maxfdMaximum +1 file descriptor from readfds.
[in]readfdsA fd_set of file descriptors to be select'ed for reading.
[in]timeoutThe timeout in milliseconds.
Returns
SSH_OK on success, SSH_ERROR on error, SSH_EINTR if it was interrupted. In that case, just restart it.
Warning
libssh is not reentrant here. That means that if a signal is caught during the processing of this function, you cannot call libssh functions on sessions that are busy with ssh_select().
See also
select(2)

References ssh_channel_poll(), ssh_event_add_fd(), ssh_event_add_session(), ssh_event_dopoll(), ssh_event_free(), ssh_event_new(), ssh_event_remove_fd(), and ssh_timeout_update().

int ssh_send_debug ( ssh_session  session,
const char *  message,
int  always_display 
)

Send a debug message.

Parameters
[in]sessionThe SSH session
[in]messageData to be sent
[in]always_displayMessage SHOULD be displayed by the server. It SHOULD NOT be displayed unless debugging information has been explicitly requested.
Returns
SSH_OK on success, SSH_ERROR otherwise.
int ssh_send_ignore ( ssh_session  session,
const char *  data 
)

Send a message that should be ignored.

Parameters
[in]sessionThe SSH session
[in]dataData to be sent
Returns
SSH_OK on success, SSH_ERROR otherwise.
void ssh_set_blocking ( ssh_session  session,
int  blocking 
)

Set the session in blocking/nonblocking mode.

Parameters
[in]sessionThe ssh session to change.
[in]blockingZero for nonblocking mode.

Referenced by ssh_channel_read_nonblocking(), ssh_channel_set_blocking(), and ssh_new().

void ssh_set_counters ( ssh_session  session,
ssh_counter  scounter,
ssh_counter  rcounter 
)

Set the session data counters.

This functions sets the counter structures to be used to calculate data which comes in and goes out through the session at different levels.

1 struct ssh_counter_struct scounter = {
2  .in_bytes = 0,
3  .out_bytes = 0,
4  .in_packets = 0,
5  .out_packets = 0
6 };
7 
8 struct ssh_counter_struct rcounter = {
9  .in_bytes = 0,
10  .out_bytes = 0,
11  .in_packets = 0,
12  .out_packets = 0
13 };
14 
15 ssh_set_counters(session, &scounter, &rcounter);
Parameters
[in]sessionThe SSH session.
[in]scounterCounter for byte data handled by the session sockets.
[in]rcounterCounter for byte and packet data handled by the session, prior compression and SSH overhead.
void ssh_set_fd_except ( ssh_session  session)

Tell the session it has an exception to catch on the file descriptor.

Parameters
[in]sessionThe ssh session to use.
void ssh_set_fd_toread ( ssh_session  session)

Tell the session it has data to read on the file descriptor without blocking.

Parameters
[in]sessionThe ssh session to use.
void ssh_set_fd_towrite ( ssh_session  session)

Tell the session it may write to the file descriptor without blocking.

Parameters
[in]sessionThe ssh session to use.
void ssh_silent_disconnect ( ssh_session  session)

Disconnect impolitely from a remote host by closing the socket.

Suitable if you forked and want to destroy this session.

Parameters
[in]sessionThe SSH session to disconnect.

References ssh_disconnect().

Referenced by ssh::Session::silentDisconnect().

int ssh_write_knownhost ( ssh_session  session)

Write the current server as known in the known hosts file.

This will create the known hosts file if it does not exist. You generaly use it when ssh_is_server_known() answered SSH_SERVER_NOT_KNOWN.

Parameters
[in]sessionThe ssh session to use.
Returns
SSH_OK on success, SSH_ERROR on error.

References ssh_dirname(), ssh_key_free(), ssh_mkdir(), and ssh_pki_export_pubkey_base64().

Referenced by ssh_is_server_known(), and ssh::Session::writeKnownhost().