Add support for IPv6 in NewIPNet

This commit is contained in:
Hubert Krauze 2015-11-26 12:02:35 +01:00
parent a57a12c1b1
commit 39cd2806f3
1 changed files with 5 additions and 2 deletions

View File

@ -33,7 +33,10 @@ func ParseIPNet(s string) (*net.IPNet, error) {
return &net.IPNet{IP: ip, Mask: ipNet.Mask}, nil return &net.IPNet{IP: ip, Mask: ipNet.Mask}, nil
} }
// NewIPNet generates an IPNet from an ip address using a netmask of 32. // NewIPNet generates an IPNet from an ip address using a netmask of 32 or 128.
func NewIPNet(ip net.IP) *net.IPNet { func NewIPNet(ip net.IP) *net.IPNet {
return &net.IPNet{IP: ip, Mask: net.CIDRMask(32, 32)} if ip.To4() != nil {
return &net.IPNet{IP: ip, Mask: net.CIDRMask(32, 32)}
}
return &net.IPNet{IP: ip, Mask: net.CIDRMask(128, 128)}
} }