diff --git a/internal/server/server.go b/internal/server/server.go index e5b5713..986da9d 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -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)) diff --git a/pkg/net/utils/helper.go b/pkg/net/utils/helper.go index 002dccc..715312f 100644 --- a/pkg/net/utils/helper.go +++ b/pkg/net/utils/helper.go @@ -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 "" + } +}