MCPcopy Index your code
hub / github.com/docker/cli / toPrefix

Function toPrefix

cli/command/network/connect.go:122–138  ·  view source on GitHub ↗

toPrefix converts n into a netip.Prefix. If n is not a valid IPv4 or IPV6 address, ToPrefix returns netip.Prefix{}, false. TODO(thaJeztah): create internal package similar to https://github.com/moby/moby/blob/0769fe708773892d6ac399ee137e71a777b35de7/daemon/internal/netiputil/netiputil.go#L21-L42

(n net.IPNet)

Source from the content-addressed store, hash-verified

120//
121// TODO(thaJeztah): create internal package similar to https://github.com/moby/moby/blob/0769fe708773892d6ac399ee137e71a777b35de7/daemon/internal/netiputil/netiputil.go#L21-L42
122func toPrefix(n net.IPNet) (netip.Prefix, bool) {
123 if ll := len(n.Mask); ll != net.IPv4len && ll != net.IPv6len {
124 return netip.Prefix{}, false
125 }
126
127 addr, ok := netip.AddrFromSlice(n.IP)
128 if !ok {
129 return netip.Prefix{}, false
130 }
131
132 ones, bits := n.Mask.Size()
133 if ones == 0 && bits == 0 {
134 return netip.Prefix{}, false
135 }
136
137 return netip.PrefixFrom(addr.Unmap(), ones), true
138}

Callers 1

createIPAMConfigFunction · 0.85

Calls 1

SizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…