pkg/net: add ParseCIDR to extract CIDR information
For example, net.ParseCIDR("10.20.30.40/24") returns:
{
prefix_mask: "255.255.255.0"
prefix_len: 24
prefix_addr: "10.20.30.0"
broadcast_addr: "10.20.30.255"
}
The names are chosen to loosely follow the API in Go's net/netip
as well as the basic terminology used on Wikipedia.
We might add more fields to this struct in the future,
as long as it's information that is useful and cheap to compute.
Fixes #4236.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I072c85e62976f7ce1041b00d406938b04638f779
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1229761
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>