Skip to content

Instantly share code, notes, and snippets.

@b4nst
Created July 11, 2024 16:42
Show Gist options
  • Save b4nst/9e9eff0e622982a82a672a20beb08e66 to your computer and use it in GitHub Desktop.
Save b4nst/9e9eff0e622982a82a672a20beb08e66 to your computer and use it in GitHub Desktop.
Go net foo
import (
"net"
"net/netip"
)
func PrefixToIPNet(p netip.Prefix) net.IPNet {
ip := p.Masked().Addr().AsSlice()
return net.IPNet{
IP: ip,
Mask: net.CIDRMask(p.Bits(), len(ip)*8),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment