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