TrustCore SDK NanoSSH API reference  version 7.0
Sync Server Connection Management Functions

Functions

MOC_EXTERN sbyte4 SSH_acceptConnection (TCP_SOCKET socket)
 Register an SSH client-server connection and get its connection instance. More...
 
MOC_EXTERN sbyte4 SSH_closeConnection (sbyte4 connectionInstance)
 Close an NanoSSH server session and releases its resources. More...
 
MOC_EXTERN sbyte4 SSH_init (sbyte4 sshMaxConnections)
 Initialize NanoSSH server internal structures. More...
 
MOC_EXTERN sbyte4 SSH_negotiateConnection (sbyte4 connectionInstance)
 Exchange keys and establishe a secure SSHv2 client-server connection. More...
 
MOC_EXTERN sbyte4 SSH_sendPing (sbyte4 connectionInstance)
 Determine which connections are alive by pinging each open connection. More...
 

Detailed Description

Function Documentation

◆ SSH_acceptConnection()

MOC_EXTERN sbyte4 SSH_acceptConnection ( TCP_SOCKET  socket)

This function registers a connection between SSH server and client and returns the session's connection instance.

Note
This function must be called from within the HTTPS daemon context. If you are using multiple HTTPS daemons, you must use a semaphore (mutex) around this function call.
If your web server and application server run as separate tasks, you should protect your call to SSH_acceptConnection with a semaphore to prevent race conditions.
Since
1.41
Version
1.41 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_SERVER__

Additionally, the following flag must not be defined:

  • __ENABLE_MOCANA_SSH_ASYNC_SERVER_API__
Parameters
tempSocketSocket or TCB identifier returned by a call to accept().

ssh.h

Returns
Value > 0 is the connection instance; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous servers.
intBoolean isBreakSignalRequest = FALSE
sbyte4 connectionInstance;
TCP_SOCKET socketClient;
status = TCP_ACCEPT_SOCKET(&socketClient, mListenSocket, &isBreakSignalRequest);
connectionInstance = SSH_acceptConnection(socketClient);

ssh.h

◆ SSH_closeConnection()

MOC_EXTERN sbyte4 SSH_closeConnection ( sbyte4  connectionInstance)

This function closes an NanoSSH server session and releases all its resources.

Since
1.41
Version
1.41 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_SERVER__

Additionally, the following flag must not be defined:

  • __ENABLE_MOCANA_SSH_ASYNC_SERVER_API__
Parameters
connectionInstanceConnection instance returned from SSH_acceptConnection().

ssh.h

Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous servers.
sbyte4 status = 0;sbyte4 connectionInstance;
status = SSH_closeConnection(connectionInstance);

ssh.h

◆ SSH_init()

MOC_EXTERN sbyte4 SSH_init ( sbyte4  sshMaxConnections)

This function initializes NanoSSH server internal structures. Your application should call this function before starting the HTTPS and application servers.

Since
1.41
Version
1.41 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_SERVER__

Additionally, the following flag must not be defined:

  • __ENABLE_MOCANA_SSH_ASYNC_SERVER_API__
Parameters
sshMaxConnectionsMaximum number of SSH server connections to allow. (Each connection requires only a few bytes of memory.)

ssh.h

Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous servers.
if (0 > SSH_init(MAX_SSH_CONNECTIONS_ALLOWED))
goto exit;

ssh.h

◆ SSH_negotiateConnection()

MOC_EXTERN sbyte4 SSH_negotiateConnection ( sbyte4  connectionInstance)

This function exchanges keys and establishes a secure SSHv2 client-server connection.

Note
You should not call this function until a connection instance is available from a previous call to SSH_acceptConnection().
Key exchange is a complex process, and may take a few seconds to perform on older (slower) platforms. However, the key exchange typically is performed only once during a session's lifetime (at startup), so there is no effect on regular communication.
Since
1.41
Version
1.41 and later

To enable this function, the following flag must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_SERVER__

Additionally, the following flag must not be defined:

  • __ENABLE_MOCANA_SSH_ASYNC_SERVER_API__
Parameters
connectionInstanceConnection instance returned from SSH_acceptConnection().

ssh.h

Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous servers.
sbyte4 status = 0;sbyte4 connectionInstance;
status = SSH_negotiateConnection(connectionInstance);

ssh.h

◆ SSH_sendPing()

MOC_EXTERN sbyte4 SSH_sendPing ( sbyte4  connectionInstance)

This function determines which connections are alive by pinging (sending an message with no data) each open connection.

Since
1.41
Version
1.41 and later

To enable this function, the following flags must be defined in moptions.h:

  • __ENABLE_MOCANA_SSH_SERVER__
  • __ENABLE_MOCANA_SSH_PING__

Additionally, the following flag must not be defined:

  • __ENABLE_MOCANA_SSH_ASYNC_SERVER_API__
Parameters
connectionInstanceConnection instance returned from SSH_acceptConnection().

ssh.h

Returns
OK (0) if successful; otherwise a negative number error code definition from merrors.h. To retrieve a string containing an English text error identifier corresponding to the function's returned error status, use the DISPLAY_ERROR macro.
Remarks
This function is applicable to synchronous servers.

ssh.h