WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit df9e65a

Browse files
author
tianchang
committed
添加了直连情况下的ip目的地址显示,能显示是否使用了ipv6
1 parent db7a6d5 commit df9e65a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tcp_handle.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ import (
1212
"github.com/sirupsen/logrus"
1313
)
1414

15+
func logConnectionType(upstreamHost string, conn net.Conn) {
16+
if tcpAddr, ok := conn.LocalAddr().(*net.TCPAddr); ok {
17+
ip_type := "ipv4"
18+
if tcpAddr.IP.To4() == nil {
19+
ip_type = "ipv6"
20+
}
21+
logrus.Debugf("%s Connected to %s : %s", upstreamHost, ip_type, conn.RemoteAddr().String())
22+
}
23+
}
24+
1525
func readRequestHeaderAndBody(conn net.Conn) (string, []byte, error) {
1626
reader := bufio.NewReader(conn)
1727
var requestBuilder strings.Builder
@@ -103,6 +113,7 @@ func forward(upstreamHost, forward_method, reqLine string, conn net.Conn) {
103113
logrus.Errorln("Error connecting to target:", err)
104114
return
105115
}
116+
logConnectionType(upstreamHost, targetConn)
106117
_, err = conn.Write([]byte("HTTP/1.1 200 Connection Established\r\n\r\n"))
107118
if err != nil {
108119
logrus.Errorln("Error writing to client:", err)

0 commit comments

Comments
 (0)