sys_bpf.go 594 B

123456789101112131415161718192021222324
  1. // Copyright 2017 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 linux
  5. package ipv4
  6. import (
  7. "unsafe"
  8. "golang.org/x/net/bpf"
  9. "golang.org/x/net/internal/socket"
  10. "golang.org/x/sys/unix"
  11. )
  12. func (so *sockOpt) setAttachFilter(c *socket.Conn, f []bpf.RawInstruction) error {
  13. prog := unix.SockFprog{
  14. Len: uint16(len(f)),
  15. Filter: (*unix.SockFilter)(unsafe.Pointer(&f[0])),
  16. }
  17. b := (*[unix.SizeofSockFprog]byte)(unsafe.Pointer(&prog))[:unix.SizeofSockFprog]
  18. return so.Set(c, b)
  19. }