From: Kevin Burke Date: Thu, 3 Nov 2016 22:34:05 +0000 (-0700) Subject: net: add example for CIDRMask X-Git-Tag: go1.8beta1~130 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0df762ed7b2ac9484a4f64450424529ecee8aa7f;p=gostls13.git net: add example for CIDRMask I had trouble translating the documentation language into a subnet - e.g. whether /31 was CIDRMask(1, 31) or CIDRMask(1, 32) or CIDRMask(31, 32) so I thought I'd add a short example showing how to create the right masks. Change-Id: Ia6a6de08c5c30b6d2249b3194cced2d3c383e317 Reviewed-on: https://go-review.googlesource.com/32677 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- diff --git a/src/net/example_test.go b/src/net/example_test.go index 6f2f9074c1..d52e7f196d 100644 --- a/src/net/example_test.go +++ b/src/net/example_test.go @@ -5,6 +5,7 @@ package net_test import ( + "fmt" "io" "log" "net" @@ -34,3 +35,13 @@ func ExampleListener() { }(conn) } } + +func ExampleCIDRMask() { + // This mask corresponds to a /31 subnet + fmt.Println(net.CIDRMask(31, 32)) + + // This mask corresponds to a /64 subnet for a IPv6 mask + fmt.Println(net.CIDRMask(64, 128)) + // Output: fffffffe + // ffffffffffffffff0000000000000000 +}