MCPcopy Create free account
hub / github.com/containers/common / FirstIPInSubnet

Function FirstIPInSubnet

libnetwork/util/ip.go:36–48  ·  view source on GitHub ↗

FirstIPInSubnet gets the first IP in a subnet

(addr *net.IPNet)

Source from the content-addressed store, hash-verified

34
35// FirstIPInSubnet gets the first IP in a subnet
36func FirstIPInSubnet(addr *net.IPNet) (net.IP, error) { //nolint:interfacer
37 // re-parse to ensure clean network address
38 _, cidr, err := net.ParseCIDR(addr.String())
39 if err != nil {
40 return nil, err
41 }
42 ones, bits := cidr.Mask.Size()
43 if ones == bits {
44 return cidr.IP, nil
45 }
46 cidr.IP[len(cidr.IP)-1]++
47 return cidr.IP, nil
48}
49
50// NormalizeIP will transform the given ip to the 4 byte len ipv4 if possible
51func NormalizeIP(ip *net.IP) {

Callers 2

ValidateSubnetFunction · 0.92
TestFirstIPInSubnetFunction · 0.85

Calls 2

SizeMethod · 0.80
StringMethod · 0.45

Tested by 1

TestFirstIPInSubnetFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…