aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/bpf_darwin.go
blob: fb86049ae92de4d4cce3a818fb4ae76c8498b0da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Copyright 2018 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.

// Berkeley packet filter for Darwin

package syscall

import (
	"unsafe"
)

// Deprecated: Use golang.org/x/net/bpf instead.
func BpfStmt(code, k int) *BpfInsn {
	return &BpfInsn{Code: uint16(code), K: uint32(k)}
}

// Deprecated: Use golang.org/x/net/bpf instead.
func BpfJump(code, k, jt, jf int) *BpfInsn {
	return &BpfInsn{Code: uint16(code), Jt: uint8(jt), Jf: uint8(jf), K: uint32(k)}
}

// Deprecated: Use golang.org/x/net/bpf instead.
func BpfBuflen(fd int) (int, error) {
	var l int
	err := ioctlPtr(fd, BIOCGBLEN, unsafe.Pointer(&l))
	if err != nil {
		return 0, err
	}
	return l, nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func SetBpfBuflen(fd, l int) (int, error) {
	err := ioctlPtr(fd, BIOCSBLEN, unsafe.Pointer(&l))
	if err != nil {
		return 0, err
	}
	return l, nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func BpfDatalink(fd int) (int, error) {
	var t int
	err := ioctlPtr(fd, BIOCGDLT, unsafe.Pointer(&t))
	if err != nil {
		return 0, err
	}
	return t, nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func SetBpfDatalink(fd, t int) (int, error) {
	err := ioctlPtr(fd, BIOCSDLT, unsafe.Pointer(&t))
	if err != nil {
		return 0, err
	}
	return t, nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func SetBpfPromisc(fd, m int) error {
	err := ioctlPtr(fd, BIOCPROMISC, unsafe.Pointer(&m))
	if err != nil {
		return err
	}
	return nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func FlushBpf(fd int) error {
	err := ioctlPtr(fd, BIOCFLUSH, nil)
	if err != nil {
		return err
	}
	return nil
}

type ivalue struct {
	name  [IFNAMSIZ]byte
	value int16
}

// Deprecated: Use golang.org/x/net/bpf instead.
func BpfInterface(fd int, name string) (string, error) {
	var iv ivalue
	err := ioctlPtr(fd, BIOCGETIF, unsafe.Pointer(&iv))
	if err != nil {
		return "", err
	}
	return name, nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func SetBpfInterface(fd int, name string) error {
	var iv ivalue
	copy(iv.name[:], []byte(name))
	err := ioctlPtr(fd, BIOCSETIF, unsafe.Pointer(&iv))
	if err != nil {
		return err
	}
	return nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func BpfTimeout(fd int) (*Timeval, error) {
	var tv Timeval
	err := ioctlPtr(fd, BIOCGRTIMEOUT, unsafe.Pointer(&tv))
	if err != nil {
		return nil, err
	}
	return &tv, nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func SetBpfTimeout(fd int, tv *Timeval) error {
	err := ioctlPtr(fd, BIOCSRTIMEOUT, unsafe.Pointer(tv))
	if err != nil {
		return err
	}
	return nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func BpfStats(fd int) (*BpfStat, error) {
	var s BpfStat
	err := ioctlPtr(fd, BIOCGSTATS, unsafe.Pointer(&s))
	if err != nil {
		return nil, err
	}
	return &s, nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func SetBpfImmediate(fd, m int) error {
	err := ioctlPtr(fd, BIOCIMMEDIATE, unsafe.Pointer(&m))
	if err != nil {
		return err
	}
	return nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func SetBpf(fd int, i []BpfInsn) error {
	var p BpfProgram
	p.Len = uint32(len(i))
	p.Insns = (*BpfInsn)(unsafe.Pointer(&i[0]))
	err := ioctlPtr(fd, BIOCSETF, unsafe.Pointer(&p))
	if err != nil {
		return err
	}
	return nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func CheckBpfVersion(fd int) error {
	var v BpfVersion
	err := ioctlPtr(fd, BIOCVERSION, unsafe.Pointer(&v))
	if err != nil {
		return err
	}
	if v.Major != BPF_MAJOR_VERSION || v.Minor != BPF_MINOR_VERSION {
		return EINVAL
	}
	return nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func BpfHeadercmpl(fd int) (int, error) {
	var f int
	err := ioctlPtr(fd, BIOCGHDRCMPLT, unsafe.Pointer(&f))
	if err != nil {
		return 0, err
	}
	return f, nil
}

// Deprecated: Use golang.org/x/net/bpf instead.
func SetBpfHeadercmpl(fd, f int) error {
	err := ioctlPtr(fd, BIOCSHDRCMPLT, unsafe.Pointer(&f))
	if err != nil {
		return err
	}
	return nil
}