github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/core/ping/ping_linux.go (about)

     1  // Copyright 2009 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.
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"net"
     9  
    10  	"golang.org/x/sys/unix"
    11  )
    12  
    13  func setupICMPv6Socket(c *net.IPConn) error {
    14  	file, err := c.File()
    15  	if err != nil {
    16  		return fmt.Errorf("net.IPConn.File failed: %w", err)
    17  	}
    18  	// we want the stack to return us the network error if any occurred
    19  	if err := unix.SetsockoptInt(int(file.Fd()), unix.SOL_IPV6, unix.IPV6_RECVERR, 1); err != nil {
    20  		return fmt.Errorf("Failed to set sock opt IPV6_RECVERR: %w", err)
    21  	}
    22  	return nil
    23  }