mirror of
https://github.com/golang/net.git
synced 2026-03-31 18:37:08 +09:00
To match up with other packages that work with IP protocol stack. Change-Id: I1f4eb76051964766113914c9698233022e73d5eb Reviewed-on: https://go-review.googlesource.com/30575 Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
29 lines
750 B
Go
29 lines
750 B
Go
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ipv6
|
|
|
|
import (
|
|
"os"
|
|
"unsafe"
|
|
|
|
"golang.org/x/net/bpf"
|
|
"golang.org/x/net/internal/netreflect"
|
|
)
|
|
|
|
// SetBPF attaches a BPF program to the connection.
|
|
//
|
|
// Only supported on Linux.
|
|
func (c *dgramOpt) SetBPF(filter []bpf.RawInstruction) error {
|
|
s, err := netreflect.PacketSocketOf(c.PacketConn)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
prog := sockFProg{
|
|
Len: uint16(len(filter)),
|
|
Filter: (*sockFilter)(unsafe.Pointer(&filter[0])),
|
|
}
|
|
return os.NewSyscallError("setsockopt", setsockopt(s, sysSOL_SOCKET, sysSO_ATTACH_FILTER, unsafe.Pointer(&prog), uint32(unsafe.Sizeof(prog))))
|
|
}
|