github.com/Andyfoo/golang/x/net@v0.0.0-20190901054642-57c1bf301704/nettest/nettest_unix.go (about)

     1  // Copyright 2019 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  
     5  // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
     6  
     7  package nettest
     8  
     9  import "syscall"
    10  
    11  func supportsRawSocket() bool {
    12  	for _, af := range []int{syscall.AF_INET, syscall.AF_INET6} {
    13  		s, err := syscall.Socket(af, syscall.SOCK_RAW, 0)
    14  		if err != nil {
    15  			continue
    16  		}
    17  		syscall.Close(s)
    18  		return true
    19  	}
    20  	return false
    21  }