From 4bd26896f8645f2387006e7bff879d323076faca Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Fri, 1 Nov 2013 13:43:40 -0400 Subject: [PATCH] Add port argument in the connection command --- tmate-decoder.c | 12 ++++++++---- tmate-slave.c | 6 +++--- tmate.h | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tmate-decoder.c b/tmate-decoder.c index 1d2e70ad..0451d72c 100644 --- a/tmate-decoder.c +++ b/tmate-decoder.c @@ -100,6 +100,7 @@ static void tmate_header(struct tmate_decoder *decoder, struct tmate_unpacker *uk) { char hostname[128]; + char port_arg[16] = {0}; char *client_version = xstrdup("< 1.8.6"); decoder->protocol = unpack_int(uk); @@ -119,11 +120,14 @@ static void tmate_header(struct tmate_decoder *decoder, if (gethostname(hostname, sizeof(hostname)) < 0) tmate_fatal("cannot get hostname"); - tmate_notify("Remote session read only: ssh ro-%s@%s.%s (clear your screen if you share this)", - tmate_session_token_ro, hostname, TMATE_DOMAIN); + if (tmate_port != 22) + sprintf(port_arg, " -p%d", tmate_port); - tmate_notify("Remote session: ssh %s@%s.%s", - tmate_session_token, hostname, TMATE_DOMAIN); + tmate_notify("Remote session read only: ssh%s ro-%s@%s.%s (clear your screen if you share this)", + port_arg, tmate_session_token_ro, hostname, TMATE_DOMAIN); + + tmate_notify("Remote session: ssh%s %s@%s.%s", + port_arg, tmate_session_token, hostname, TMATE_DOMAIN); } extern u_int next_window_pane_id; diff --git a/tmate-slave.c b/tmate-slave.c index 43c00169..c82f2278 100644 --- a/tmate-slave.c +++ b/tmate-slave.c @@ -17,6 +17,7 @@ #include #include "tmate.h" +int tmate_port = TMATE_DEFAULT_PORT; struct tmate_encoder *tmate_encoder; int tmux_socket_fd; const char *tmate_session_token = "main"; @@ -62,7 +63,6 @@ long tmate_get_random_long(void) int main(int argc, char **argv, char **envp) { int opt; - int port = TMATE_DEFAULT_PORT; const char *keys_dir = "keys"; #ifdef TMATE_RECORD_REPLAY const char *replay_file = NULL; @@ -71,7 +71,7 @@ int main(int argc, char **argv, char **envp) while ((opt = getopt(argc, argv, "p:l:vk:r:")) != -1) { switch (opt) { case 'p': - port = atoi(optarg); + tmate_port = atoi(optarg); break; case 'l': log_path = optarg; @@ -117,7 +117,7 @@ int main(int argc, char **argv, char **envp) (mkdir(TMATE_WORKDIR "/jail", 0700) < 0 && errno != EEXIST)) tmate_fatal("Cannot prepare session in " TMATE_WORKDIR); - tmate_ssh_server_main(keys_dir, port); + tmate_ssh_server_main(keys_dir, tmate_port); return 0; } diff --git a/tmate.h b/tmate.h index 446e44f1..a576a30b 100644 --- a/tmate.h +++ b/tmate.h @@ -160,6 +160,7 @@ extern void tmate_ssh_server_main(const char *keys_dir, int port); #define TMATE_WORKDIR "/tmp/tmate" #define TMATE_JAIL_USER "nobody" +extern int tmate_port; extern struct tmate_encoder *tmate_encoder; extern int tmux_socket_fd; extern const char *tmate_session_token;