-
Notifications
You must be signed in to change notification settings - Fork 3
/
bsd.go
47 lines (37 loc) · 996 Bytes
/
bsd.go
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
//go:build freebsd || openbsd || netbsd || darwin
package main
import (
"fmt"
"net"
"syscall"
"time"
)
// TODO provide implementation based on BPF
type RawAddr struct {
HardwareAddr net.HardwareAddr
Addr net.IP
Port int
Device string
}
type RawConn struct {
Local *RawAddr
}
func NewRawConn(bind *RawAddr) (rc *RawConn, err error) {
return nil, fmt.Errorf("not implemented")
}
func (rc *RawConn) SetReadDeadline(deadline time.Time) error {
return fmt.Errorf("not implemented")
}
func (rc *RawConn) ReadFrom(data []byte) (read int, from *RawAddr, err error) {
return 0, nil, fmt.Errorf("not implemented")
}
func (rc *RawConn) WriteTo(from, to *RawAddr, data []byte) (written int, err error) {
return 0, fmt.Errorf("not implemented")
}
func BindToDevice(handle int, name string) error {
info, err := net.InterfaceByName(name)
if err != nil {
return err
}
return syscall.SetsockoptInt(handle, syscall.IPPROTO_IP, syscall.IP_BOUND_IF, info.Index)
}