1 // Copyright 2011 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 // +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
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCGBLEN
, uintptr(unsafe
.Pointer(&l
)))
35 // Deprecated: Use golang.org/x/net/bpf instead.
36 func SetBpfBuflen(fd
, l
int) (int, error
) {
37 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCSBLEN
, uintptr(unsafe
.Pointer(&l
)))
44 // Deprecated: Use golang.org/x/net/bpf instead.
45 func BpfDatalink(fd
int) (int, error
) {
47 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCGDLT
, uintptr(unsafe
.Pointer(&t
)))
54 // Deprecated: Use golang.org/x/net/bpf instead.
55 func SetBpfDatalink(fd
, t
int) (int, error
) {
56 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCSDLT
, uintptr(unsafe
.Pointer(&t
)))
63 // Deprecated: Use golang.org/x/net/bpf instead.
64 func SetBpfPromisc(fd
, m
int) error
{
65 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCPROMISC
, uintptr(unsafe
.Pointer(&m
)))
72 // Deprecated: Use golang.org/x/net/bpf instead.
73 func FlushBpf(fd
int) error
{
74 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCFLUSH
, 0)
86 // Deprecated: Use golang.org/x/net/bpf instead.
87 func BpfInterface(fd
int, name
string) (string, error
) {
89 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCGETIF
, uintptr(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
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCSETIF
, uintptr(unsafe
.Pointer(&iv
)))
107 // Deprecated: Use golang.org/x/net/bpf instead.
108 func BpfTimeout(fd
int) (*Timeval
, error
) {
110 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCGRTIMEOUT
, uintptr(unsafe
.Pointer(&tv
)))
112 return nil, Errno(err
)
117 // Deprecated: Use golang.org/x/net/bpf instead.
118 func SetBpfTimeout(fd
int, tv
*Timeval
) error
{
119 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCSRTIMEOUT
, uintptr(unsafe
.Pointer(tv
)))
126 // Deprecated: Use golang.org/x/net/bpf instead.
127 func BpfStats(fd
int) (*BpfStat
, error
) {
129 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCGSTATS
, uintptr(unsafe
.Pointer(&s
)))
131 return nil, Errno(err
)
136 // Deprecated: Use golang.org/x/net/bpf instead.
137 func SetBpfImmediate(fd
, m
int) error
{
138 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCIMMEDIATE
, uintptr(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
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCSETF
, uintptr(unsafe
.Pointer(&p
)))
157 // Deprecated: Use golang.org/x/net/bpf instead.
158 func CheckBpfVersion(fd
int) error
{
160 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCVERSION
, uintptr(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
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCGHDRCMPLT
, uintptr(unsafe
.Pointer(&f
)))
180 // Deprecated: Use golang.org/x/net/bpf instead.
181 func SetBpfHeadercmpl(fd
, f
int) error
{
182 _
, _
, err
:= Syscall(SYS_IOCTL
, uintptr(fd
), BIOCSHDRCMPLT
, uintptr(unsafe
.Pointer(&f
)))