PR target/82112
[official-gcc.git] / libgo / go / syscall / bpf_bsd.go
blob8b587559edbcba0ba9f2c564eb83d4c0b16ae1b9
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
9 package syscall
11 import (
12 "unsafe"
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) {
27 var l int
28 _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGBLEN, uintptr(unsafe.Pointer(&l)))
29 if err != 0 {
30 return 0, Errno(err)
32 return l, nil
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)))
38 if err != 0 {
39 return 0, Errno(err)
41 return l, nil
44 // Deprecated: Use golang.org/x/net/bpf instead.
45 func BpfDatalink(fd int) (int, error) {
46 var t int
47 _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGDLT, uintptr(unsafe.Pointer(&t)))
48 if err != 0 {
49 return 0, Errno(err)
51 return t, nil
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)))
57 if err != 0 {
58 return 0, Errno(err)
60 return t, nil
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)))
66 if err != 0 {
67 return Errno(err)
69 return nil
72 // Deprecated: Use golang.org/x/net/bpf instead.
73 func FlushBpf(fd int) error {
74 _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCFLUSH, 0)
75 if err != 0 {
76 return Errno(err)
78 return nil
81 type ivalue struct {
82 name [IFNAMSIZ]byte
83 value int16
86 // Deprecated: Use golang.org/x/net/bpf instead.
87 func BpfInterface(fd int, name string) (string, error) {
88 var iv ivalue
89 _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGETIF, uintptr(unsafe.Pointer(&iv)))
90 if err != 0 {
91 return "", Errno(err)
93 return name, nil
96 // Deprecated: Use golang.org/x/net/bpf instead.
97 func SetBpfInterface(fd int, name string) error {
98 var iv ivalue
99 copy(iv.name[:], []byte(name))
100 _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSETIF, uintptr(unsafe.Pointer(&iv)))
101 if err != 0 {
102 return Errno(err)
104 return nil
107 // Deprecated: Use golang.org/x/net/bpf instead.
108 func BpfTimeout(fd int) (*Timeval, error) {
109 var tv Timeval
110 _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGRTIMEOUT, uintptr(unsafe.Pointer(&tv)))
111 if err != 0 {
112 return nil, Errno(err)
114 return &tv, nil
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)))
120 if err != 0 {
121 return Errno(err)
123 return nil
126 // Deprecated: Use golang.org/x/net/bpf instead.
127 func BpfStats(fd int) (*BpfStat, error) {
128 var s BpfStat
129 _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGSTATS, uintptr(unsafe.Pointer(&s)))
130 if err != 0 {
131 return nil, Errno(err)
133 return &s, nil
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)))
139 if err != 0 {
140 return Errno(err)
142 return nil
145 // Deprecated: Use golang.org/x/net/bpf instead.
146 func SetBpf(fd int, i []BpfInsn) error {
147 var p BpfProgram
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)))
151 if err != 0 {
152 return Errno(err)
154 return nil
157 // Deprecated: Use golang.org/x/net/bpf instead.
158 func CheckBpfVersion(fd int) error {
159 var v BpfVersion
160 _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCVERSION, uintptr(unsafe.Pointer(&v)))
161 if err != 0 {
162 return Errno(err)
164 if v.Major != BPF_MAJOR_VERSION || v.Minor != BPF_MINOR_VERSION {
165 return EINVAL
167 return nil
170 // Deprecated: Use golang.org/x/net/bpf instead.
171 func BpfHeadercmpl(fd int) (int, error) {
172 var f int
173 _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGHDRCMPLT, uintptr(unsafe.Pointer(&f)))
174 if err != 0 {
175 return 0, Errno(err)
177 return f, nil
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)))
183 if err != 0 {
184 return Errno(err)
186 return nil