MCPcopy Create free account
hub / github.com/containerd/nerdctl / FirstIPInSubnet

Function FirstIPInSubnet

pkg/netutil/subnet/subnet.go:124–136  ·  view source on GitHub ↗

firstIPInSubnet gets the first IP in a subnet https://github.com/containers/podman/blob/v4.0.0-rc1/libpod/network/util/ip.go#L36

(addr *net.IPNet)

Source from the content-addressed store, hash-verified

122// firstIPInSubnet gets the first IP in a subnet
123// https://github.com/containers/podman/blob/v4.0.0-rc1/libpod/network/util/ip.go#L36
124func FirstIPInSubnet(addr *net.IPNet) (net.IP, error) {
125 // re-parse to ensure clean network address
126 _, cidr, err := net.ParseCIDR(addr.String())
127 if err != nil {
128 return nil, err
129 }
130 ones, bits := cidr.Mask.Size()
131 if ones == bits {
132 return cidr.IP, nil
133 }
134 cidr.IP[len(cidr.IP)-1]++
135 return cidr.IP, nil
136}

Callers

nothing calls this directly

Calls 2

SizeMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…