Skip to content

Commit 0fabf41

Browse files
committed
Add missing files
1 parent c6c8852 commit 0fabf41

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

readwritecloser_darwin.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package can
2+
3+
import (
4+
"fmt"
5+
"net"
6+
)
7+
8+
func NewReadWriteCloserForInterface(i *net.Interface) (ReadWriteCloser, error) {
9+
return nil, fmt.Errorf("Binding to can interface no supported on Darwin")
10+
}

readwritecloser_linux.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package can
2+
3+
import (
4+
"fmt"
5+
"golang.org/x/sys/unix"
6+
"net"
7+
"os"
8+
"syscall"
9+
)
10+
11+
func NewReadWriteCloserForInterface(i *net.Interface) (ReadWriteCloser, error) {
12+
s, _ := syscall.Socket(syscall.AF_CAN, syscall.SOCK_RAW, unix.CAN_RAW)
13+
addr := &unix.SockaddrCAN{Ifindex: i.Index}
14+
if err := unix.Bind(s, addr); err != nil {
15+
return nil, err
16+
}
17+
18+
f := os.NewFile(uintptr(s), fmt.Sprintf("fd %d", s))
19+
20+
return &readWriteCloser{f}, nil
21+
}

0 commit comments

Comments
 (0)