aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libssh/libssh.h1
-rw-r--r--src/session.c15
2 files changed, 16 insertions, 0 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 93d6dba6..a215c31e 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -386,6 +386,7 @@ LIBSSH_API int ssh_get_version(ssh_session session);
LIBSSH_API int ssh_get_status(ssh_session session);
LIBSSH_API int ssh_init(void);
LIBSSH_API int ssh_is_blocking(ssh_session session);
+LIBSSH_API int ssh_is_connected(ssh_session session);
LIBSSH_API int ssh_is_server_known(ssh_session session);
LIBSSH_API void ssh_log(ssh_session session, int prioriry, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
LIBSSH_API ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg);
diff --git a/src/session.c b/src/session.c
index 02e48d0c..d279142a 100644
--- a/src/session.c
+++ b/src/session.c
@@ -298,6 +298,21 @@ int ssh_is_blocking(ssh_session session){
}
/**
+ * @brief Check if we are connected.
+ *
+ * @param[in] session The session to check if it is connected.
+ *
+ * @return 1 if we are connected, 0 if not.
+ */
+int ssh_is_connected(ssh_session session) {
+ if (session == NULL) {
+ return 0;
+ }
+
+ return session->alive;
+}
+
+/**
* @brief Get the fd of a connection.
*
* In case you'd need the file descriptor of the connection to the server/client.