helper_unix.go 623 B

1234567891011121314151617181920212223242526272829
  1. // Copyright 2015 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. // +build darwin dragonfly freebsd linux netbsd openbsd solaris
  5. package nettest
  6. import (
  7. "fmt"
  8. "os"
  9. "runtime"
  10. "syscall"
  11. )
  12. func maxOpenFiles() int {
  13. var rlim syscall.Rlimit
  14. if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim); err != nil {
  15. return defaultMaxOpenFiles
  16. }
  17. return int(rlim.Cur)
  18. }
  19. func supportsRawIPSocket() (string, bool) {
  20. if os.Getuid() != 0 {
  21. return fmt.Sprintf("must be root on %s", runtime.GOOS), false
  22. }
  23. return "", true
  24. }