Just on a point of clarity. DefaultMask is returning the mask associates with the network class. RFC1918 specifies a bunch of class A,B and C networks for private use. E.g. 192.168/16 is a set of 256 class C networks. The correct netmask for one of those class Cs is 255.255.255.0 (/24). So the function returns the correct thing by the RFC.
On Sun, 3 Mar 2019, 15:57 John Dreystadt, <jdreyst...@gmail.com> wrote: > Looking at RFC 1918 (which defined the non-routeable address ranges), it > says that 10.0.0.0 has a 10/8 prefix which matches what DefaultMask() > returns as a mask. But 192.168.0.0 returns FFFFFF00 while the RFC says that > it should have a 192.168/16 prefix (FFFF0000) . And 17.16.0.0 returns > FFFF0000 while the RFC says that it should have a 17.16/12 prefix > (FFF00000). I also don't see the use case for this function. If this is an > IP address associated with the current machine, the code should be walking > the net interfaces and getting the mask from the OS. If this is an IP > address associated with some other machine, why do you need an IP mask? In > all of my years programming on the Internet, I never needed to know the > mask of a remote machine. > > On Saturday, March 2, 2019 at 6:07:22 PM UTC-5, Louki Sumirniy wrote: >> >> The function is really just looking up the IP prefixes of the >> non-routeable address ranges. It has nothing to do with CIDR, it is for >> generating a sane default mask when the user has not specified the mask. >> >> It most definitely should not be deprecated, as these nonrouteable >> addresses are definitely not deprecated, and CIDR is an extension, not a >> replacement, for IPv4 subnet specification, to give administrators more >> flexibliity when configuring multiple address ranges in a fairly large >> intranet. >> >> On Saturday, 2 March 2019 22:32:28 UTC+1, John Dreystadt wrote: >>> >>> I am new to Go so feel free to point out if I am breaking protocol but I >>> ran into the function DefaultMask() in the net package and did some >>> research. This function returns the IPMask by assuming that you are using >>> IP class A, B, and C addresses. But this concept is from the early days of >>> the Internet, and was superseded by CIDR in 1993. See >>> https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing for the >>> history here. I looked around both this group and on Stack Overflow to see >>> what people had posted about this function. The only reference in >>> golang-nuts was to someone using this call to decide if an address was IPv4 >>> or not. As the last posting on that thread pointed out, you can use To4() >>> for the same purpose (since DefaultMask actually calls To4). The only >>> reference on Stack Overflow was someone using it to get the "Next IP >>> address". Sorry but I don't understand what he was doing. If you want the >>> IPMask for 127.0.0.1, you can just get that interface and get the mask that >>> way. I even tried Google for "golang DefaultMask" and only found hits about >>> non network things. So I don't believe that this function is useful today >>> and should be deprecated, maybe with a message about using To4() if you >>> just want to see if an address is IPv4. >>> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.