Skip to content

Commit

Permalink
Fix IP parsing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Iam54r1n4 committed Nov 29, 2024
1 parent a5067dd commit c280b4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (s *Server) handleConnection(gc *gordafarid.Conn) {
}

// Extract target server information from the handshake result
dstAddr := string(handshakeResult.DstAddr)
dstAddr := utils.IPBytesToString(handshakeResult.Atyp, handshakeResult.DstAddr)
dstPort := binary.BigEndian.Uint16(handshakeResult.DstPort[:])
targetAddr := net.JoinHostPort(dstAddr, fmt.Sprint(dstPort))

Expand Down
12 changes: 12 additions & 0 deletions pkg/net/utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,15 @@ func ReadPort(ctx context.Context, conn net.Conn) ([2]byte, error) {
}
return port, nil
}

// IPBytesToString converts IP bytes to a string based on the address type
func IPBytesToString(atyp byte, ip []byte) string {
switch atyp {
case protocol.AtypIPv4, protocol.AtypIPv6:
return net.IP(ip).String()
case protocol.AtypDomain:
return string(ip)
default:
return ""
}
}

0 comments on commit c280b4c

Please sign in to comment.