From 31850ed38414fea3b01b2e054fe4dbb9c1404952 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Fri, 20 Jan 2017 17:37:37 +0800 Subject: [PATCH] use net.JoinHostPort --- obfssh_client/proxy.go | 8 ++++---- server.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/obfssh_client/proxy.go b/obfssh_client/proxy.go index adb5a80..9fc47d3 100644 --- a/obfssh_client/proxy.go +++ b/obfssh_client/proxy.go @@ -106,7 +106,7 @@ func httpProxyHandshake(c net.Conn, host string, port int) error { } func dialHTTPProxy(host string, port int, p proxy) (net.Conn, error) { - c, err := net.Dial("tcp", fmt.Sprintf("%s:%d", p.Host, p.Port)) + c, err := net.Dial("tcp", net.JoinHostPort(p.Host, fmt.Sprintf("%d", p.Port))) if err != nil { return nil, err } @@ -129,7 +129,7 @@ func dialHTTPSProxy(host string, port int, p proxy) (net.Conn, error) { InsecureSkipVerify: p.Insecure, } - c, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", p.Host, p.Port), tlsconfig) + c, err := tls.Dial("tcp", net.JoinHostPort(p.Host, fmt.Sprintf("%d", p.Port)), tlsconfig) if err != nil { return nil, err } @@ -147,13 +147,13 @@ func dialHTTPSProxy(host string, port int, p proxy) (net.Conn, error) { } func dialSocks5Proxy(host string, port int, p proxy) (net.Conn, error) { - c, err := net.Dial("tcp", fmt.Sprintf("%s:%d", p.Host, p.Port)) + c, err := net.Dial("tcp", net.JoinHostPort(p.Host, fmt.Sprintf("%d", p.Port))) if err != nil { return nil, err } c1 := &socks.Client{Conn: c} - c2, err := c1.Dial("tcp", fmt.Sprintf("%s:%d", host, port)) + c2, err := c1.Dial("tcp", net.JoinHostPort(host, fmt.Sprintf("%d", port))) if err != nil { c1.Close() return nil, err diff --git a/server.go b/server.go index 4c20212..8f0d45f 100644 --- a/server.go +++ b/server.go @@ -194,7 +194,7 @@ func handleDirectTcpip(newch ssh.NewChannel) { Log(DEBUG, "create connection to %s:%d", r.Raddr, r.Rport) - rconn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", r.Raddr, r.Rport)) + rconn, err := net.Dial("tcp", net.JoinHostPort(r.Raddr, fmt.Sprintf("%d", r.Rport))) if err != nil { Log(ERROR, "%s", err.Error()) newch.Reject(ssh.ConnectionFailed, "invalid argument")