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