From 5d9300c1e9ce6c6afec15b98c9195f41f15be442 Mon Sep 17 00:00:00 2001 From: fatedier Date: Fri, 12 Aug 2016 00:32:33 +0800 Subject: [PATCH] utils/conn: support ipv6, fix #62 --- Makefile | 6 ++---- conf/frpc.ini | 2 ++ conf/frps.ini | 2 ++ src/utils/conn/conn.go | 7 +++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index af62747b..729ca51f 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,13 @@ export PATH := $(GOPATH)/bin:$(PATH) export GO15VENDOREXPERIMENT := 1 -all: fmt dep build +all: fmt build build: frps frpc build_test build_test: echo_server http_server -dep: statik - -statik: +assets: go get -d github.com/rakyll/statik @go install github.com/rakyll/statik @rm -rf ./src/assets/statik diff --git a/conf/frpc.ini b/conf/frpc.ini index 4c6167b8..9e2030ac 100644 --- a/conf/frpc.ini +++ b/conf/frpc.ini @@ -1,5 +1,7 @@ # [common] is integral section [common] +# A literal address or host name for IPv6 must be enclosed +# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80" server_addr = 0.0.0.0 server_port = 7000 # console or real logFile path like ./frpc.log diff --git a/conf/frps.ini b/conf/frps.ini index fd117220..e1e90418 100644 --- a/conf/frps.ini +++ b/conf/frps.ini @@ -1,5 +1,7 @@ # [common] is integral section [common] +# A literal address or host name for IPv6 must be enclosed +# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80" bind_addr = 0.0.0.0 bind_port = 7000 # if you want to support virtual host, you must set the http port for listening (optional) diff --git a/src/utils/conn/conn.go b/src/utils/conn/conn.go index 336f6183..9922758c 100644 --- a/src/utils/conn/conn.go +++ b/src/utils/conn/conn.go @@ -32,7 +32,10 @@ type Listener struct { } func Listen(bindAddr string, bindPort int64) (l *Listener, err error) { - tcpAddr, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf("%s:%d", bindAddr, bindPort)) + tcpAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", bindAddr, bindPort)) + if err != nil { + return l, err + } listener, err := net.ListenTCP("tcp", tcpAddr) if err != nil { return l, err @@ -103,7 +106,7 @@ func NewConn(conn net.Conn) (c *Conn) { func ConnectServer(host string, port int64) (c *Conn, err error) { c = &Conn{} - servertAddr, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf("%s:%d", host, port)) + servertAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", host, port)) if err != nil { return }