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)
| 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 |
| 124 | func 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 | } |