raw_direction_openbsd.go 627 B

1234567891011121314151617181920212223242526272829303132333435
  1. // +build openbsd
  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. var dirfilt uint
  12. switch direction {
  13. case 0:
  14. // filter outbound
  15. dirfilt = syscall.BPF_DIRECTION_OUT
  16. default:
  17. // no filter
  18. }
  19. _, _, err := syscall.Syscall(
  20. syscall.SYS_IOCTL,
  21. uintptr(fd),
  22. syscall.BIOCSDIRFILT,
  23. uintptr(unsafe.Pointer(&dirfilt)),
  24. )
  25. if err != 0 {
  26. return syscall.Errno(err)
  27. }
  28. return nil
  29. }