mirror of
https://github.com/daeuniverse/dae.git
synced 2025-01-05 13:08:57 +07:00
24 lines
575 B
Go
24 lines
575 B
Go
// Copied from https://github.com/cilium/ebpf/blob/v0.10.0/example_sock_elf_test.go
|
|
|
|
package internal
|
|
|
|
import (
|
|
"github.com/v2rayA/dae/common"
|
|
"syscall"
|
|
)
|
|
|
|
func OpenRawSock(index int) (int, error) {
|
|
sock, err := syscall.Socket(syscall.AF_PACKET, syscall.SOCK_RAW|syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC, int(common.Htons(syscall.ETH_P_ALL)))
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
sll := syscall.SockaddrLinklayer{
|
|
Ifindex: index,
|
|
Protocol: common.Htons(syscall.ETH_P_ALL),
|
|
}
|
|
if err := syscall.Bind(sock, &sll); err != nil {
|
|
return 0, err
|
|
}
|
|
return sock, nil
|
|
}
|