raw_direction_bsd.go 651 B

123456789101112131415161718192021222324252627
  1. // +build darwin dragonfly freebsd netbsd
  2. package raw
  3. import (
  4. "syscall"
  5. "unsafe"
  6. )
  7. // setBPFDirection enables filtering traffic traveling in a specific direction
  8. // using BPF, so that traffic sent by this package is not captured when reading
  9. // using this package.
  10. func setBPFDirection(fd int, direction int) error {
  11. _, _, err := syscall.Syscall(
  12. syscall.SYS_IOCTL,
  13. uintptr(fd),
  14. // Even though BIOCSDIRECTION is preferred on FreeBSD, BIOCSSEESENT continues
  15. // to work, and is required for other BSD platforms
  16. syscall.BIOCSSEESENT,
  17. uintptr(unsafe.Pointer(&direction)),
  18. )
  19. if err != 0 {
  20. return syscall.Errno(err)
  21. }
  22. return nil
  23. }