mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-07 09:41:09 +08:00
Fix(fd): compile error
This commit is contained in:
@@ -1,41 +1,3 @@
|
||||
package fd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/core/device"
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
)
|
||||
|
||||
const Driver = "fd"
|
||||
|
||||
type FD struct {
|
||||
stack.LinkEndpoint
|
||||
|
||||
fd int
|
||||
mtu uint32
|
||||
}
|
||||
|
||||
func Open(name string, mtu uint32) (device.Device, error) {
|
||||
fd, err := strconv.Atoi(name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot open fd: %s", name)
|
||||
}
|
||||
return open(fd, mtu)
|
||||
}
|
||||
|
||||
func (f *FD) Type() string {
|
||||
return Driver
|
||||
}
|
||||
|
||||
func (f *FD) Name() string {
|
||||
return strconv.Itoa(f.fd)
|
||||
}
|
||||
|
||||
func (f *FD) Close() error {
|
||||
return unix.Close(f.fd)
|
||||
}
|
||||
|
||||
var _ device.Device = (*FD)(nil)
|
||||
|
41
core/device/fd/fd_unix.go
Normal file
41
core/device/fd/fd_unix.go
Normal file
@@ -0,0 +1,41 @@
|
||||
//go:build !windows
|
||||
|
||||
package fd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/core/device"
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
)
|
||||
|
||||
type FD struct {
|
||||
stack.LinkEndpoint
|
||||
|
||||
fd int
|
||||
mtu uint32
|
||||
}
|
||||
|
||||
func Open(name string, mtu uint32) (device.Device, error) {
|
||||
fd, err := strconv.Atoi(name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot open fd: %s", name)
|
||||
}
|
||||
return open(fd, mtu)
|
||||
}
|
||||
|
||||
func (f *FD) Type() string {
|
||||
return Driver
|
||||
}
|
||||
|
||||
func (f *FD) Name() string {
|
||||
return strconv.Itoa(f.fd)
|
||||
}
|
||||
|
||||
func (f *FD) Close() error {
|
||||
return unix.Close(f.fd)
|
||||
}
|
||||
|
||||
var _ device.Device = (*FD)(nil)
|
11
core/device/fd/fd_windows.go
Normal file
11
core/device/fd/fd_windows.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package fd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/core/device"
|
||||
)
|
||||
|
||||
func Open(name string, mtu uint32) (device.Device, error) {
|
||||
return nil, errors.New("not supported")
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
//go:build !linux
|
||||
//go:build !linux && !windows
|
||||
|
||||
package fd
|
||||
|
||||
|
Reference in New Issue
Block a user