// CIDRsDontOverlap ensures two given CIDRs don't overlap
// with one another. CIDR starting IPs are canonicalized
// before being compared.
CIDRsDontOverlap ensures two given CIDRs don't overlap
with one another. CIDR starting IPs are canonicalized
before being compared.
// CIDRsDontOverlap ensures two given CIDRs don ' t overlap // with one another . CIDR starting IPs are canonicalized // before being compared .
func CIDRsDontOverlap(acidr, bcidr string) error {
	_, a, err := net.ParseCIDR(acidr)
	if err != nil {
		return fmt.Errorf("invalid CIDR %q: %v", acidr, err)
	}
	if err := canonicalizeIP(&a.IP); err != nil {
		return fmt.Errorf("invalid CIDR %q: %v", acidr, err)
	}
	_, b, err := net.ParseCIDR(bcidr)
	if err != nil {
		return fmt.Errorf("invalid CIDR %q: %v", bcidr, err)
	}
	if err := canonicalizeIP(&b.IP); err != nil {
		return fmt.Errorf("invalid CIDR %q: %v", bcidr, err)
	}
	err = fmt.Errorf("%q and %q overlap", acidr, bcidr)
	if len(a.IP) != len(b.IP) {
		return nil
	}
	if a.Contains(b.IP) {
		return err
	}
	if a.Contains(lastIP(b)) {
		return err
	}
	if b.Contains(a.IP) {
		return err
	}
	if b.Contains(lastIP(a)) {
		return err
	}
	return nil
}
func CIDRsDontOverlap ( acidr , bcidr string ) error { _ , a , err := net . ParseCIDR ( acidr ) if err != nil { return fmt . Errorf ( " " , acidr , err ) } if err := canonicalizeIP ( & a . IP ) ; err != nil { return fmt . Errorf ( " " , acidr , err ) } _ , b , err := net . ParseCIDR ( bcidr ) if err != nil { return fmt . Errorf ( " " , bcidr , err ) } if err := canonicalizeIP ( & b . IP ) ; err != nil { return fmt . Errorf ( " " , bcidr , err ) } err = fmt . Errorf ( " " , acidr , bcidr ) if len ( a . IP ) != len ( b . IP ) { return nil } if a . Contains ( b . IP ) { return err } if a . Contains ( lastIP ( b ) ) { return err } if b . Contains ( a . IP ) { return err } if b . Contains ( lastIP ( a ) ) { return err } return nil }
CIDRsDontOverlap ensures two given CIDRs don't overlap
with one another.
CIDRsDontOverlap ensures two given CIDRs don ' t overlap with one another .
// IPs are of different families.