Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

29 lignes
750 B

  1. // Copyright 2016 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. package ipv4
  5. import (
  6. "os"
  7. "unsafe"
  8. "golang.org/x/net/bpf"
  9. "golang.org/x/net/internal/netreflect"
  10. )
  11. // SetBPF attaches a BPF program to the connection.
  12. //
  13. // Only supported on Linux.
  14. func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
  15. s, err := netreflect.PacketSocketOf(c.PacketConn)
  16. if err != nil {
  17. return err
  18. }
  19. prog := sockFProg{
  20. Len: uint16(len(filter)),
  21. Filter: (*sockFilter)(unsafe.Pointer(&filter[0])),
  22. }
  23. return os.NewSyscallError("setsockopt", setsockopt(s, sysSOL_SOCKET, sysSO_ATTACH_FILTER, unsafe.Pointer(&prog), uint32(unsafe.Sizeof(prog))))
  24. }