Skip to content

Commit

Permalink
Merge pull request #3929 from manuelbuil/dual-stack-funcitons_engine
Browse files Browse the repository at this point in the history
[engine-1.21] Add functions to separate ipv4 from ipv6 functions
  • Loading branch information
manuelbuil authored Aug 27, 2021
2 parents ed5991f + 75d3e27 commit a4c8810
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,25 @@ func GetFirst4String(elems []string) (string, error) {
}
return ip.String(), nil
}

// JoinIP4Nets stringifies and joins a list of IPv4 networks with commas.
func JoinIP4Nets(elems []*net.IPNet) string {
var strs []string
for _, elem := range elems {
if elem != nil && elem.IP.To4() != nil {
strs = append(strs, elem.String())
}
}
return strings.Join(strs, ",")
}

// JoinIP6Nets stringifies and joins a list of IPv6 networks with commas.
func JoinIP6Nets(elems []*net.IPNet) string {
var strs []string
for _, elem := range elems {
if elem != nil && elem.IP.To4() == nil {
strs = append(strs, elem.String())
}
}
return strings.Join(strs, ",")
}

0 comments on commit a4c8810

Please sign in to comment.