Skip to content

Commit 5204a53

Browse files
authored
fix(common): improve error messages for nil address checks and simplify header sending
1 parent c377b59 commit 5204a53

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

internal/common.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,13 @@ func (c *Common) sendProxyV1Header(ip string, conn net.Conn) error {
324324

325325
header := fmt.Sprintf("PROXY %s %s %s %d %d\r\n",
326326
protocol,
327-
clientAddr.IP.String(), // 用户真实IP
328-
remoteAddr.IP.String(), // 目标服务IP
327+
clientAddr.IP.String(), // 用户真实地址
328+
remoteAddr.IP.String(), // 目标服务地址
329329
clientAddr.Port, // 用户真实端口
330330
remoteAddr.Port) // 目标服务端口
331331

332332
// 发送 header
333-
_, err = conn.Write([]byte(header))
334-
if err != nil {
333+
if _, err = conn.Write([]byte(header)); err != nil {
335334
return err
336335
}
337336

@@ -356,7 +355,7 @@ func (c *Common) initContext() {
356355
// initTunnelListener 初始化隧道监听器
357356
func (c *Common) initTunnelListener() error {
358357
if c.tunnelTCPAddr == nil || c.tunnelUDPAddr == nil {
359-
return &net.AddrError{Err: "tunnel address is nil"}
358+
return fmt.Errorf("nil tunnel address")
360359
}
361360

362361
// 初始化隧道TCP监听器
@@ -385,7 +384,7 @@ func (c *Common) initTunnelListener() error {
385384
// initTargetListener 初始化目标监听器
386385
func (c *Common) initTargetListener() error {
387386
if c.targetTCPAddr == nil || c.targetUDPAddr == nil {
388-
return &net.AddrError{Err: "target address is nil"}
387+
return fmt.Errorf("nil target address")
389388
}
390389

391390
// 初始化目标TCP监听器

0 commit comments

Comments
 (0)