Skip to content

Instantly share code, notes, and snippets.

@justnoise
Created September 6, 2018 02:05
Show Gist options
  • Select an option

  • Save justnoise/1b5d7b2f5458a51c5f11e96fe4acc550 to your computer and use it in GitHub Desktop.

Select an option

Save justnoise/1b5d7b2f5458a51c5f11e96fe4acc550 to your computer and use it in GitHub Desktop.
func NetworkSize(cidr string) int {
_, ipnet, err := net.ParseCIDR(cidr)
if err != nil {
return 0
}
ones, bits := ipnet.Mask.Size()
exp := uint(bits - ones)
size := 1 << exp
return size
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment