FirstIPInSubnet gets the first IP in a subnet
(addr *net.IPNet)
| 34 | |
| 35 | // FirstIPInSubnet gets the first IP in a subnet |
| 36 | func 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 |
| 51 | func NormalizeIP(ip *net.IP) { |
searching dependent graphs…