mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-30 13:01:23 +03:00
channel: Add ssh_channel_accept_forward().
This works same way as ssh_forward_accept() but can return a destination port of the channel (useful if SSH connection forwarding several TCP/IP ports). Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
6d09104ad3
commit
a1c4fc07d4
@@ -406,6 +406,7 @@ LIBSSH_API void ssh_disconnect(ssh_session session);
|
|||||||
LIBSSH_API char *ssh_dirname (const char *path);
|
LIBSSH_API char *ssh_dirname (const char *path);
|
||||||
LIBSSH_API int ssh_finalize(void);
|
LIBSSH_API int ssh_finalize(void);
|
||||||
LIBSSH_API ssh_channel ssh_forward_accept(ssh_session session, int timeout_ms);
|
LIBSSH_API ssh_channel ssh_forward_accept(ssh_session session, int timeout_ms);
|
||||||
|
LIBSSH_API ssh_channel ssh_channel_accept_forward(ssh_session session, int timeout_ms, int *destination_port);
|
||||||
LIBSSH_API int ssh_forward_cancel(ssh_session session, const char *address, int port);
|
LIBSSH_API int ssh_forward_cancel(ssh_session session, const char *address, int port);
|
||||||
LIBSSH_API int ssh_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
|
LIBSSH_API int ssh_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
|
||||||
LIBSSH_API void ssh_free(ssh_session session);
|
LIBSSH_API void ssh_free(ssh_session session);
|
||||||
|
|||||||
@@ -1989,7 +1989,7 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ssh_channel ssh_channel_accept(ssh_session session, int channeltype,
|
static ssh_channel ssh_channel_accept(ssh_session session, int channeltype,
|
||||||
int timeout_ms) {
|
int timeout_ms, int *destination_port) {
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
static const struct timespec ts = {
|
static const struct timespec ts = {
|
||||||
.tv_sec = 0,
|
.tv_sec = 0,
|
||||||
@@ -2016,6 +2016,10 @@ static ssh_channel ssh_channel_accept(ssh_session session, int channeltype,
|
|||||||
ssh_message_subtype(msg) == channeltype) {
|
ssh_message_subtype(msg) == channeltype) {
|
||||||
ssh_list_remove(session->ssh_message_list, iterator);
|
ssh_list_remove(session->ssh_message_list, iterator);
|
||||||
channel = ssh_message_channel_request_open_reply_accept(msg);
|
channel = ssh_message_channel_request_open_reply_accept(msg);
|
||||||
|
if(destination_port) {
|
||||||
|
*destination_port=msg->channel_request_open.destination_port;
|
||||||
|
}
|
||||||
|
|
||||||
ssh_message_free(msg);
|
ssh_message_free(msg);
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
@@ -2046,7 +2050,7 @@ static ssh_channel ssh_channel_accept(ssh_session session, int channeltype,
|
|||||||
* the server.
|
* the server.
|
||||||
*/
|
*/
|
||||||
ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms) {
|
ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms) {
|
||||||
return ssh_channel_accept(channel->session, SSH_CHANNEL_X11, timeout_ms);
|
return ssh_channel_accept(channel->session, SSH_CHANNEL_X11, timeout_ms, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2300,7 +2304,23 @@ error:
|
|||||||
* the server
|
* the server
|
||||||
*/
|
*/
|
||||||
ssh_channel ssh_forward_accept(ssh_session session, int timeout_ms) {
|
ssh_channel ssh_forward_accept(ssh_session session, int timeout_ms) {
|
||||||
return ssh_channel_accept(session, SSH_CHANNEL_FORWARDED_TCPIP, timeout_ms);
|
return ssh_channel_accept(session, SSH_CHANNEL_FORWARDED_TCPIP, timeout_ms, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Accept an incoming TCP/IP forwarding channel and get information
|
||||||
|
* about incomming connection
|
||||||
|
* @param[in] session The ssh session to use.
|
||||||
|
*
|
||||||
|
* @param[in] timeout_ms A timeout in milliseconds.
|
||||||
|
*
|
||||||
|
* @param[in] destination_port A pointer to destination port or NULL.
|
||||||
|
*
|
||||||
|
* @return Newly created channel, or NULL if no incoming channel request from
|
||||||
|
* the server
|
||||||
|
*/
|
||||||
|
ssh_channel ssh_channel_accept_forward(ssh_session session, int timeout_ms, int* destination_port) {
|
||||||
|
return ssh_channel_accept(session, SSH_CHANNEL_FORWARDED_TCPIP, timeout_ms, destination_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user