Commit 0df762ed authored by Kevin Burke's avatar Kevin Burke Committed by Brad Fitzpatrick

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/32677Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent fe057c14
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package net_test package net_test
import ( import (
"fmt"
"io" "io"
"log" "log"
"net" "net"
...@@ -34,3 +35,13 @@ func ExampleListener() { ...@@ -34,3 +35,13 @@ func ExampleListener() {
}(conn) }(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
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment