1 // Copyright 2018 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.
5 //go:build darwin || dragonfly || freebsd || netbsd || openbsd
7 // Berkeley packet filter for BSD variants
15 // Deprecated: Use golang.org/x/net/bpf instead.
16 func BpfStmt(code, k int) *BpfInsn {
17 return &BpfInsn{Code: uint16(code), K: uint32(k)}
20 // Deprecated: Use golang.org/x/net/bpf instead.
21 func BpfJump(code, k, jt, jf int) *BpfInsn {
22 return &BpfInsn{Code: uint16(code), Jt: uint8(jt), Jf: uint8(jf), K: uint32(k)}
25 // Deprecated: Use golang.org/x/net/bpf instead.
26 func BpfBuflen(fd int) (int, error) {
28 err := ioctlPtr(fd, BIOCGBLEN, unsafe.Pointer(&l))
35 // Deprecated: Use golang.org/x/net/bpf instead.
36 func SetBpfBuflen(fd, l int) (int, error) {
37 err := ioctlPtr(fd, BIOCSBLEN, unsafe.Pointer(&l))
44 // Deprecated: Use golang.org/x/net/bpf instead.
45 func BpfDatalink(fd int) (int, error) {
47 err := ioctlPtr(fd, BIOCGDLT, unsafe.Pointer(&t))
54 // Deprecated: Use golang.org/x/net/bpf instead.
55 func SetBpfDatalink(fd, t int) (int, error) {
56 err := ioctlPtr(fd, BIOCSDLT, unsafe.Pointer(&t))
63 // Deprecated: Use golang.org/x/net/bpf instead.
64 func SetBpfPromisc(fd, m int) error {
65 err := ioctlPtr(fd, BIOCPROMISC, unsafe.Pointer(&m))
72 // Deprecated: Use golang.org/x/net/bpf instead.
73 func FlushBpf(fd int) error {
74 err := ioctlPtr(fd, BIOCFLUSH, nil)
86 // Deprecated: Use golang.org/x/net/bpf instead.
87 func BpfInterface(fd int, name string) (string, error) {
89 err := ioctlPtr(fd, BIOCGETIF, unsafe.Pointer(&iv))
96 // Deprecated: Use golang.org/x/net/bpf instead.
97 func SetBpfInterface(fd int, name string) error {
99 copy(iv.name[:], []byte(name))
100 err := ioctlPtr(fd, BIOCSETIF, unsafe.Pointer(&iv))
107 // Deprecated: Use golang.org/x/net/bpf instead.
108 func BpfTimeout(fd int) (*Timeval, error) {
110 err := ioctlPtr(fd, BIOCGRTIMEOUT, unsafe.Pointer(&tv))
117 // Deprecated: Use golang.org/x/net/bpf instead.
118 func SetBpfTimeout(fd int, tv *Timeval) error {
119 err := ioctlPtr(fd, BIOCSRTIMEOUT, unsafe.Pointer(tv))
126 // Deprecated: Use golang.org/x/net/bpf instead.
127 func BpfStats(fd int) (*BpfStat, error) {
129 err := ioctlPtr(fd, BIOCGSTATS, unsafe.Pointer(&s))
136 // Deprecated: Use golang.org/x/net/bpf instead.
137 func SetBpfImmediate(fd, m int) error {
138 err := ioctlPtr(fd, BIOCIMMEDIATE, unsafe.Pointer(&m))
145 // Deprecated: Use golang.org/x/net/bpf instead.
146 func SetBpf(fd int, i []BpfInsn) error {
148 p.Len = uint32(len(i))
149 p.Insns = (*BpfInsn)(unsafe.Pointer(&i[0]))
150 err := ioctlPtr(fd, BIOCSETF, unsafe.Pointer(&p))
157 // Deprecated: Use golang.org/x/net/bpf instead.
158 func CheckBpfVersion(fd int) error {
160 err := ioctlPtr(fd, BIOCVERSION, unsafe.Pointer(&v))
164 if v.Major != BPF_MAJOR_VERSION || v.Minor != BPF_MINOR_VERSION {
170 // Deprecated: Use golang.org/x/net/bpf instead.
171 func BpfHeadercmpl(fd int) (int, error) {
173 err := ioctlPtr(fd, BIOCGHDRCMPLT, unsafe.Pointer(&f))
180 // Deprecated: Use golang.org/x/net/bpf instead.
181 func SetBpfHeadercmpl(fd, f int) error {
182 err := ioctlPtr(fd, BIOCSHDRCMPLT, unsafe.Pointer(&f))