Skip to content

Commit

Permalink
Merge pull request #117 from swordqiu/hotfix/qj-parse-ipv6-string-error
Browse files Browse the repository at this point in the history
fix: fail to parse ipv6 address of fc00::1:1004:ffff:ffff:ffff:ffff
  • Loading branch information
swordqiu authored Mar 24, 2024
2 parents 73685b1 + df43b8f commit 11d9be9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion util/netutils/ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ func normalizeIpv6Addr(addrStr string) ([8]uint16, error) {
}
} else {
for i := 0; i < len(parts); i++ {
partStr := strings.TrimSpace(parts[i])
if len(partStr) == 0 {
continue
}
var err error
addr[i], err = hex2Number(strings.TrimSpace(parts[i]))
addr[i], err = hex2Number(partStr)
if err != nil {
return addr, errors.Wrapf(err, "hex2Number %s", addrStr)
}
Expand Down
17 changes: 17 additions & 0 deletions util/netutils/ipv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,19 @@ func TestNewIPV6Addr(t *testing.T) {
netAddr: "::1200:0:0:0",
broadcastAddr: "::12ff:ffff:ffff:ffff",
},
{
in: "fc00:0:1:1004::10",
wantAddr: IPV6Addr{
0xfc00, 0, 1, 0x1004, 0, 0, 0, 0x10,
},
want: "fc00:0:1:1004::10",
stepUp: "fc00:0:1:1004::11",
stepDown: "fc00:0:1:1004::f",

preflen: 64,
netAddr: "fc00:0:1:1004::",
broadcastAddr: "fc00::1:1004:ffff:ffff:ffff:ffff",
},
}
for _, c := range cases {
addr6, err := NewIPV6Addr(c.in)
Expand Down Expand Up @@ -391,6 +404,10 @@ func TestRandomAddress(t *testing.T) {
addr1: "::1234:1",
addr2: "::1238:ffff",
},
{
addr1: "fc00:0:1:1004::10",
addr2: "fc00::1:1004:ffff:ffff:ffff:ffff",
},
}
for _, c := range cases {
addr1, err := NewIPV6Addr(c.addr1)
Expand Down

0 comments on commit 11d9be9

Please # to comment.