Skip to content

Commit

Permalink
improve condition
Browse files Browse the repository at this point in the history
  • Loading branch information
hossinasaadi committed Oct 12, 2024
1 parent f55f367 commit b126e96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 0 additions & 6 deletions core/device/fdbased/open_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ package fdbased
import (
"fmt"
"os"
"runtime"

"github.com/xjasonlyu/tun2socks/v2/core/device"
"github.com/xjasonlyu/tun2socks/v2/core/device/iobased"
)

func open(fd int, mtu uint32, offset int) (device.Device, error) {
f := &FD{fd: fd, mtu: mtu}
// fd offset in ios
// https://stackoverflow.com/questions/69260852/ios-network-extension-packet-parsing/69487795#69487795
if offset == 0 && runtime.GOOS == "ios" {
offset = 4
}
ep, err := iobased.New(os.NewFile(uintptr(fd), f.Name()), mtu, offset)
if err != nil {
return nil, fmt.Errorf("create endpoint: %w", err)
Expand Down
7 changes: 7 additions & 0 deletions engine/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"net/netip"
"net/url"
"runtime"
"strings"

"github.com/gorilla/schema"
Expand Down Expand Up @@ -67,6 +68,12 @@ func parseDevice(s string, mtu uint32) (device.Device, error) {
}

func parseFD(u *url.URL, mtu uint32) (device.Device, error) {

// fd offset in ios
// https://stackoverflow.com/questions/69260852/ios-network-extension-packet-parsing/69487795#69487795
if runtime.GOOS == "ios" {
return fdbased.Open(u.Host, mtu, 4)
}
return fdbased.Open(u.Host, mtu, 0)
}

Expand Down

0 comments on commit b126e96

Please sign in to comment.