Coder Social home page Coder Social logo

IPv6 defaults to 64 Cidr about ipnetwork HOT 3 CLOSED

lduchosal avatar lduchosal commented on August 29, 2024
IPv6 defaults to 64 Cidr

from ipnetwork.

Comments (3)

lduchosal avatar lduchosal commented on August 29, 2024

At first sight, it looks like you found a bug. Thanks for reporting it, I'll investigate this case further.

from ipnetwork.

Deantwo avatar Deantwo commented on August 29, 2024

This done in the TryGuessCidr(string ip, out byte cidr) method, which attempts to find classful netmasks for IPv4 addresses. But since IPv6 was never classful this makes no sense for it. So someone seem to have picked /64 as the default CIDR for IPv6.
The exact line is here: System.Net.IPNetwork/IPNetwork.cs#L1778.

I see no reference to there being a default CIDR for IPv6, but /64 seem to be mentioned a lot in documention and preferred by most. So this does make sense as a default CIDR.

I think the real issue here is that most network engineers would assume that an IP address with no network mask or CIDR is always a single IP address and not an IP network, so therefore defaulting to /32 for IPv4 and /128 for IPv6 makes more sense.

The code in the opening post should have been written as:

IPNetwork rangeToCheck = IPNetwork.Parse("2001:db8:abcd:0012:0000:0000:0000:0000/112");
IPAddress ipToCheck = IPAddress.Parse("2001:db8:abcd:0012:0000:0000:0000:0001");

rangeToCheck.Contains(ipToCheck); // returns true

As shown in Example 2 (IPv6) of the ReadMe.

from ipnetwork.

lduchosal avatar lduchosal commented on August 29, 2024

This seem like a default behaviour in standard tools.

Have a look at af_inet6.c for IPV6.

static void
in6_postproc(int s, const struct afswtch *afp)
{
	if (explicit_prefix == 0) {
		/* Aggregatable address architecture defines all prefixes
		   are 64. So, it is convenient to set prefixlen to 64 if
		   it is not specified. */
		setifprefixlen("64", 0, s, afp);
		/* in6_getprefix("64", MASK) if MASK is available here... */
	}
}

from ipnetwork.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.