diff options
author | Mikio Hara <mikioh.mikioh@gmail.com> | 2015-08-17 12:13:58 +0900 |
---|---|---|
committer | Mikio Hara <mikioh.mikioh@gmail.com> | 2015-08-17 04:08:19 +0000 |
commit | ea66ef9485b181bd424997ad0cc24d99d99e3f23 (patch) | |
tree | b955db3329416fdbd2e8948d5bfa251288a245e2 | |
parent | b026840ad5cb594d38a2b783be1b6644fe5325fb (diff) | |
download | net-ea66ef9485b181bd424997ad0cc24d99d99e3f23.tar.gz |
icmp: don't refer internal packages in examples
Also fixes ping tests. Latest Linux kernels prohibit to access ICMPv6
properties with non-privileged sockets.
Fixes golang/go#12163.
Change-Id: I439b41556e8d4c2f3a9f725131267469e08c9599
Reviewed-on: https://go-review.googlesource.com/13653
Reviewed-by: Ian Lance Taylor <iant@golang.org>
-rw-r--r-- | icmp/example_test.go | 13 | ||||
-rw-r--r-- | icmp/ping_test.go | 2 |
2 files changed, 12 insertions, 3 deletions
diff --git a/icmp/example_test.go b/icmp/example_test.go index fce7595..1df4cec 100644 --- a/icmp/example_test.go +++ b/icmp/example_test.go @@ -8,13 +8,22 @@ import ( "log" "net" "os" + "runtime" "golang.org/x/net/icmp" - "golang.org/x/net/internal/iana" "golang.org/x/net/ipv6" ) func ExamplePacketConn_nonPrivilegedPing() { + switch runtime.GOOS { + case "darwin": + case "linux": + log.Println("you may need to adjust the net.ipv4.ping_group_range kernel state") + default: + log.Println("not supported on", runtime.GOOS) + return + } + c, err := icmp.ListenPacket("udp6", "fe80::1%en0") if err != nil { log.Fatal(err) @@ -41,7 +50,7 @@ func ExamplePacketConn_nonPrivilegedPing() { if err != nil { log.Fatal(err) } - rm, err := icmp.ParseMessage(iana.ProtocolIPv6ICMP, rb[:n]) + rm, err := icmp.ParseMessage(58, rb[:n]) if err != nil { log.Fatal(err) } diff --git a/icmp/ping_test.go b/icmp/ping_test.go index be7d537..4ec2692 100644 --- a/icmp/ping_test.go +++ b/icmp/ping_test.go @@ -115,7 +115,7 @@ func doPing(tt pingTest, seq int) error { return err } - if tt.protocol == iana.ProtocolIPv6ICMP { + if tt.network != "udp6" && tt.protocol == iana.ProtocolIPv6ICMP { var f ipv6.ICMPFilter f.SetAll(true) f.Accept(ipv6.ICMPTypeDestinationUnreachable) |