mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-05 08:47:00 +08:00
27 lines
467 B
Go
27 lines
467 B
Go
package fdbased
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
|
|
|
|
"github.com/xjasonlyu/tun2socks/v2/core/device"
|
|
)
|
|
|
|
func open(fd int, mtu uint32) (device.Device, error) {
|
|
f := &FD{fd: fd, mtu: mtu}
|
|
|
|
ep, err := fdbased.New(&fdbased.Options{
|
|
FDs: []int{fd},
|
|
MTU: mtu,
|
|
// TUN only, ignore ethernet header.
|
|
EthernetHeader: false,
|
|
})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("create endpoint: %w", err)
|
|
}
|
|
f.LinkEndpoint = ep
|
|
|
|
return f, nil
|
|
}
|