mirror of
https://github.com/tmate-io/tmate-ssh-server.git
synced 2020-11-18 19:53:51 -08:00
Use full qualified hostname
This commit is contained in:
parent
1fa1a9aca4
commit
fa4ae885ea
@ -104,6 +104,33 @@ static void usage(void)
|
|||||||
fprintf(stderr, "usage: tmate-slave [-h hostname] [-k keys_dir] [-p port] [-x proxy_hostname] [-q proxy_port] [-s] [-v]\n");
|
fprintf(stderr, "usage: tmate-slave [-h hostname] [-k keys_dir] [-p port] [-x proxy_hostname] [-q proxy_port] [-s] [-v]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char* get_full_hostname(void)
|
||||||
|
{
|
||||||
|
struct addrinfo hints, *info;
|
||||||
|
char hostname[1024];
|
||||||
|
int gai_result;
|
||||||
|
char *ret;
|
||||||
|
|
||||||
|
if (gethostname(hostname, sizeof(hostname)) < 0)
|
||||||
|
tmate_fatal("cannot get hostname");
|
||||||
|
hostname[1023] = '\0';
|
||||||
|
|
||||||
|
memset(&hints, 0, sizeof hints);
|
||||||
|
hints.ai_family = AF_UNSPEC; /*either IPV4 or IPV6*/
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
hints.ai_flags = AI_CANONNAME;
|
||||||
|
|
||||||
|
if ((gai_result = getaddrinfo(hostname, NULL, &hints, &info)) != 0) {
|
||||||
|
tmate_warn("cannot lookup hostname: %s", gai_strerror(gai_result));
|
||||||
|
return xstrdup(hostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = xstrdup(info->ai_canonname);
|
||||||
|
|
||||||
|
freeaddrinfo(info);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv, char **envp)
|
int main(int argc, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
@ -137,12 +164,8 @@ int main(int argc, char **argv, char **envp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tmate_settings->tmate_host) {
|
if (!tmate_settings->tmate_host)
|
||||||
char hostname[255];
|
tmate_settings->tmate_host = get_full_hostname();
|
||||||
if (gethostname(hostname, sizeof(hostname)) < 0)
|
|
||||||
tmate_fatal("cannot get hostname");
|
|
||||||
tmate_settings->tmate_host = xstrdup(hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdline = *argv;
|
cmdline = *argv;
|
||||||
cmdline_end = *envp;
|
cmdline_end = *envp;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user