Skip to content

Commit

Permalink
src,include,test: make ssh server port configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
bk138 committed Jan 7, 2024
1 parent 152c214 commit 697cd52
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/libsshtunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ int ssh_tunnel_init();
Once established, the tunnel entry will listen on localhost on the port
indicated by \ref ssh_tunnel_get_port().
@param ssh_host The SSH server host to connect to.
@param ssh_port The SSH server host's port to connect to.
@param ssh_user The SSH user to authenticate as.
@param ssh_password The SSH user password to authenticate with.
@param remote_host The remote host to connect to from the SSH server.
Expand All @@ -100,6 +101,7 @@ int ssh_tunnel_init();
@return An open SSH tunnel to \p remote_host via \p ssh_host, listening on localhost.
*/
ssh_tunnel_t* ssh_tunnel_open_with_password(const char *ssh_host,
int ssh_port,
const char *ssh_user,
const char *ssh_password,
const char *remote_host,
Expand All @@ -114,6 +116,7 @@ ssh_tunnel_t* ssh_tunnel_open_with_password(const char *ssh_host,
Once established, the tunnel entry will listen on localhost on the port
indicated by \ref ssh_tunnel_get_port().
@param ssh_host The SSH server host to connect to.
@param ssh_port The SSH server host's port to connect to.
@param ssh_user The SSH user to authenticate as.
@param ssh_priv_key The SSH private key to authenticate with.
@param ssh_priv_key_len The length in bytes of SSH private key to authenticate with.
Expand All @@ -126,6 +129,7 @@ ssh_tunnel_t* ssh_tunnel_open_with_password(const char *ssh_host,
@return An open SSH tunnel to \p remote_host via \p ssh_host, listening on localhost.
*/
ssh_tunnel_t* ssh_tunnel_open_with_privkey(const char *ssh_host,
int ssh_port,
const char *ssh_user,
const char *ssh_priv_key,
int ssh_priv_key_len,
Expand Down
7 changes: 6 additions & 1 deletion src/libsshtunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ void ssh_tunnel_exit() {


static ssh_tunnel_t* ssh_tunnel_open(const char *ssh_host,
int ssh_port,
const char *ssh_user,
const char *ssh_password,
const char *ssh_priv_key,
Expand Down Expand Up @@ -321,7 +322,7 @@ static ssh_tunnel_t* ssh_tunnel_open(const char *ssh_host,
goto error;
}

sin.sin_port = htons(22);
sin.sin_port = htons(ssh_port);
if(connect(data->ssh_sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
if(data->signal_error_callback) {
data->signal_error_callback(data->client, LIBSSHTUNNEL_ERROR_SSH_CONNECT, "ssh_tunnel_open: failed to connect to SSH server!\n");
Expand Down Expand Up @@ -512,6 +513,7 @@ static ssh_tunnel_t* ssh_tunnel_open(const char *ssh_host,


ssh_tunnel_t *ssh_tunnel_open_with_password( const char *ssh_host,
int ssh_port,
const char *ssh_user,
const char *ssh_password,
const char *remote_host,
Expand All @@ -520,6 +522,7 @@ ssh_tunnel_t *ssh_tunnel_open_with_password( const char *ssh_host,
ssh_tunnel_fingerprint_check_func_t ssh_fingerprint_check_callback,
ssh_tunnel_signal_error_func_t signal_error_callback) {
return ssh_tunnel_open(ssh_host,
ssh_port,
ssh_user,
ssh_password,
NULL,
Expand All @@ -534,6 +537,7 @@ ssh_tunnel_t *ssh_tunnel_open_with_password( const char *ssh_host,


ssh_tunnel_t *ssh_tunnel_open_with_privkey(const char *ssh_host,
int ssh_port,
const char *ssh_user,
const char *ssh_priv_key,
int ssh_priv_key_len,
Expand All @@ -544,6 +548,7 @@ ssh_tunnel_t *ssh_tunnel_open_with_privkey(const char *ssh_host,
ssh_tunnel_fingerprint_check_func_t ssh_fingerprint_check_callback,
ssh_tunnel_signal_error_func_t signal_error_callback) {
return ssh_tunnel_open(ssh_host,
ssh_port,
ssh_user,
NULL,
ssh_priv_key,
Expand Down
1 change: 1 addition & 0 deletions test/close-of-unused-tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ int main() {
assert(ssh_tunnel_init() == 0);

ssh_tunnel_t *t = ssh_tunnel_open_with_password(getenv("LIBSSHTUNNEL_TEST_SSH_HOST"),
atoi(getenv("LIBSSHTUNNEL_TEST_SSH_PORT")),
getenv("LIBSSHTUNNEL_TEST_SSH_USER"),
getenv("LIBSSHTUNNEL_TEST_SSH_PASSWORD"),
getenv("LIBSSHTUNNEL_TEST_REMOTE_HOST"),
Expand Down

0 comments on commit 697cd52

Please sign in to comment.