diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2021-10-19 20:33:59 +0300 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2021-10-19 20:33:59 +0300 |
| commit | 3c16894e997bdb235f1c0ce1291cc85a7b56118c (patch) | |
| tree | 1f56f816a549c58847103fafe7d2f28d43af4987 | |
| parent | ddfdb8e01aea4f8b6127834a14b74c5c534820d1 (diff) | |
Bugfix: Use correct hostname when no port specified
| -rw-r--r-- | internal/clients/connectors/serverconnection.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/internal/clients/connectors/serverconnection.go b/internal/clients/connectors/serverconnection.go index 1df4d73..aeb2a41 100644 --- a/internal/clients/connectors/serverconnection.go +++ b/internal/clients/connectors/serverconnection.go @@ -63,17 +63,20 @@ func (c *ServerConnection) Handler() handlers.Handler { return c.handler } // Attempt to parse the server port address from the provided server FQDN. func (c *ServerConnection) initServerPort() { - c.port = config.Common.SSHPort parts := strings.Split(c.server, ":") - if len(parts) == 2 { - dlog.Client.Debug("Parsing port from hostname", parts) - port, err := strconv.Atoi(parts[1]) - if err != nil { - dlog.Client.FatalPanic("Unable to parse client port", c.server, parts, err) - } - c.hostname = parts[0] - c.port = port + if len(parts) == 1 { + c.hostname = c.server + c.port = config.Common.SSHPort + return + } + + dlog.Client.Debug("Parsing port from hostname", parts) + port, err := strconv.Atoi(parts[1]) + if err != nil { + dlog.Client.FatalPanic("Unable to parse client port", c.server, parts, err) } + c.hostname = parts[0] + c.port = port } // Start the connection to the server. @@ -127,8 +130,8 @@ func (c *ServerConnection) dial(ctx context.Context, cancel context.CancelFunc, <-statsCh }() - dlog.Client.Debug(c.server, "Dialing into the connection") address := fmt.Sprintf("%s:%d", c.hostname, c.port) + dlog.Client.Debug(c.server, "Dialing into the connection", address) client, err := ssh.Dial("tcp", address, c.config) if err != nil { |
