aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Viennot <nicolas@viennot.biz>2013-11-06 20:08:11 -0500
committerAndreas Schneider <asn@cryptomilk.org>2013-11-24 23:21:39 +0100
commit78e78642e7d5a7b23b28624f0f595de760105f43 (patch)
tree055305d13c5fd8b7b65337ba944ff0e5d3eb9bc6
parent7ab0e3fe6258d04b9c2b9424c134e2cafafe78c0 (diff)
downloadlibssh-78e78642e7d5a7b23b28624f0f595de760105f43.tar.gz
libssh-78e78642e7d5a7b23b28624f0f595de760105f43.tar.xz
libssh-78e78642e7d5a7b23b28624f0f595de760105f43.zip
server: Add a ssh_send_keepalive() function.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--include/libssh/server.h2
-rw-r--r--src/server.c41
2 files changed, 43 insertions, 0 deletions
diff --git a/include/libssh/server.h b/include/libssh/server.h
index dbffecdd..9d095feb 100644
--- a/include/libssh/server.h
+++ b/include/libssh/server.h
@@ -382,6 +382,8 @@ LIBSSH_API int ssh_channel_write_stderr(ssh_channel channel,
const void *data,
uint32_t len);
+LIBSSH_API int ssh_send_keepalive(ssh_session session);
+
/* deprecated functions */
SSH_DEPRECATED LIBSSH_API int ssh_accept(ssh_session session);
SSH_DEPRECATED LIBSSH_API int channel_write_stderr(ssh_channel channel,
diff --git a/src/server.c b/src/server.c
index a8ecc6be..bc6dc6c9 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1221,6 +1221,47 @@ int ssh_execute_message_callbacks(ssh_session session){
return SSH_OK;
}
+int ssh_send_keepalive(ssh_session session)
+{
+ struct ssh_string_struct *req;
+ int rc;
+
+ rc = buffer_add_u8(session->out_buffer, SSH2_MSG_GLOBAL_REQUEST);
+ if (rc < 0) {
+ goto err;
+ }
+
+ req = ssh_string_from_char("keepalive@openssh.com");
+ if (req == NULL) {
+ goto err;
+ }
+
+ rc = buffer_add_ssh_string(session->out_buffer, req);
+ ssh_string_free(req);
+ if (rc < 0) {
+ goto err;
+ }
+
+ rc = buffer_add_u8(session->out_buffer, 1);
+ if (rc < 0) {
+ goto err;
+ }
+
+ if (packet_send(session) == SSH_ERROR) {
+ goto err;
+ }
+
+ ssh_handle_packets(session, 0);
+
+ SSH_LOG(SSH_LOG_PACKET, "Sent a keepalive");
+ return SSH_OK;
+
+err:
+ ssh_set_error_oom(session);
+ buffer_reinit(session->out_buffer);
+ return SSH_ERROR;
+}
+
/** @} */
/* vim: set ts=4 sw=4 et cindent: */