1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 "golang.org/x/net/icmp"
14 "golang.org/x/net/ipv6"
17 func ExamplePacketConn_nonPrivilegedPing() {
21 log.Println("you may need to adjust the net.ipv4.ping_group_range kernel state")
23 log.Println("not supported on", runtime.GOOS)
27 c, err := icmp.ListenPacket("udp6", "fe80::1%en0")
34 Type: ipv6.ICMPTypeEchoRequest, Code: 0,
36 ID: os.Getpid() & 0xffff, Seq: 1,
37 Data: []byte("HELLO-R-U-THERE"),
40 wb, err := wm.Marshal(nil)
44 if _, err := c.WriteTo(wb, &net.UDPAddr{IP: net.ParseIP("ff02::1"), Zone: "en0"}); err != nil {
48 rb := make([]byte, 1500)
49 n, peer, err := c.ReadFrom(rb)
53 rm, err := icmp.ParseMessage(58, rb[:n])
58 case ipv6.ICMPTypeEchoReply:
59 log.Printf("got reflection from %v", peer)
61 log.Printf("got %+v; want echo reply", rm)