From f853cd9ec923cb66aba3504f5b75bd528ecc2d40 Mon Sep 17 00:00:00 2001 From: UUBulb <35923940+uubulb@users.noreply.github.com> Date: Mon, 25 Nov 2024 21:20:08 +0800 Subject: [PATCH] fix netip parsing (#20) --- pkg/utils/utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 4c04e95..7300c69 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -58,14 +58,14 @@ func BinaryToIPString(b []byte) string { func GetIPFromHeader(headerValue string) (string, error) { a := strings.Split(headerValue, ",") h := strings.TrimSpace(a[len(a)-1]) - ip, err := netip.ParseAddrPort(h) + ip, err := netip.ParseAddr(h) if err != nil { return "", err } if !ip.IsValid() { return "", errors.New("invalid ip") } - return ip.Addr().String(), nil + return ip.String(), nil } // SplitIPAddr 传入/分割的v4v6混合地址,返回v4和v6地址与有效地址