mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-05-28 23:34:49 -05:00
Factor out ssh_hostport_setup().
This is the part of ssh.c's connect_to_host() which figures out the host name and port number that logically identify the connection - i.e. not necessarily where we physically connected to, but what we'll use to look up the saved session cache, put in the window title bar, and give to the connection sharing code to identify other connections to share with. I'm about to want to use it for another purpose, so it needs to be moved out into a separate function.
This commit is contained in:
parent
5a9711a1e5
commit
e0252a4a60
67
ssh.c
67
ssh.c
@ -3549,6 +3549,43 @@ static void ssh_sent(Plug plug, int bufsize)
|
||||
ssh_throttle_all(ssh, 0, bufsize);
|
||||
}
|
||||
|
||||
static void ssh_hostport_setup(const char *host, int port, Conf *conf,
|
||||
char **savedhost, int *savedport,
|
||||
char **loghost_ret)
|
||||
{
|
||||
char *loghost = conf_get_str(conf, CONF_loghost);
|
||||
if (loghost_ret)
|
||||
*loghost_ret = loghost;
|
||||
|
||||
if (*loghost) {
|
||||
char *tmphost;
|
||||
char *colon;
|
||||
|
||||
tmphost = dupstr(loghost);
|
||||
*savedport = 22; /* default ssh port */
|
||||
|
||||
/*
|
||||
* A colon suffix on the hostname string also lets us affect
|
||||
* savedport. (Unless there are multiple colons, in which case
|
||||
* we assume this is an unbracketed IPv6 literal.)
|
||||
*/
|
||||
colon = host_strrchr(tmphost, ':');
|
||||
if (colon && colon == host_strchr(tmphost, ':')) {
|
||||
*colon++ = '\0';
|
||||
if (*colon)
|
||||
*savedport = atoi(colon);
|
||||
}
|
||||
|
||||
*savedhost = host_strduptrim(tmphost);
|
||||
sfree(tmphost);
|
||||
} else {
|
||||
*savedhost = host_strduptrim(host);
|
||||
if (port < 0)
|
||||
port = 22; /* default ssh port */
|
||||
*savedport = port;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Connect to specified host and port.
|
||||
* Returns an error message, or NULL on success.
|
||||
@ -3570,35 +3607,9 @@ static const char *connect_to_host(Ssh ssh, const char *host, int port,
|
||||
const char *err;
|
||||
char *loghost;
|
||||
int addressfamily, sshprot;
|
||||
|
||||
loghost = conf_get_str(ssh->conf, CONF_loghost);
|
||||
if (*loghost) {
|
||||
char *tmphost;
|
||||
char *colon;
|
||||
|
||||
tmphost = dupstr(loghost);
|
||||
ssh->savedport = 22; /* default ssh port */
|
||||
|
||||
/*
|
||||
* A colon suffix on the hostname string also lets us affect
|
||||
* savedport. (Unless there are multiple colons, in which case
|
||||
* we assume this is an unbracketed IPv6 literal.)
|
||||
*/
|
||||
colon = host_strrchr(tmphost, ':');
|
||||
if (colon && colon == host_strchr(tmphost, ':')) {
|
||||
*colon++ = '\0';
|
||||
if (*colon)
|
||||
ssh->savedport = atoi(colon);
|
||||
}
|
||||
|
||||
ssh->savedhost = host_strduptrim(tmphost);
|
||||
sfree(tmphost);
|
||||
} else {
|
||||
ssh->savedhost = host_strduptrim(host);
|
||||
if (port < 0)
|
||||
port = 22; /* default ssh port */
|
||||
ssh->savedport = port;
|
||||
}
|
||||
ssh_hostport_setup(host, port, ssh->conf,
|
||||
&ssh->savedhost, &ssh->savedport, &loghost);
|
||||
|
||||
ssh->fn = &fn_table; /* make 'ssh' usable as a Plug */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user