heiher / hev-socks5-tunnel

A high-performance tun2socks for Linux/Android/FreeBSD/macOS/iOS/WSL2 (IPv4/IPv6/TCP/UDP)
MIT License
636 stars 130 forks source link

iOS networkextension hev_socks5_tunnel_main always returns -1 #81

Closed 800sea closed 5 months ago

800sea commented 5 months ago

xcode 15.0.1 我在ios 的networkextension 中使用hev-socks5-tunnel 永远返回: -1 在mac端使用同样的配置能正常启动

func srart(){
        let localConfigFileURL = Bundle.main.url(forResource: "Config", withExtension: "yml")
        let a = try? String(contentsOf: localConfigFileURL!)
        printLog("VPN的值-\(a!)")

        let fb = tunnelFileDescriptor()
        printLog("VPN的值文件描述-\(localConfigFileURL!.relativePath)")  // fb is 5

        let cStringPointer = localConfigFileURL!.relativePath.utf8CString.withUnsafeBufferPointer {
            // $0.baseAddress 是指向 C 字符串数组的 UnsafePointer<CChar>
            return $0.baseAddress
        }

        let code = hev_socks5_tunnel_main(cStringPointer, fb!)
        printLog("VPN的tun2socks返回状态-  \(code)")
}

Config.yml :

tunnel:
  name: tun0
  mtu: 8500
  multi-queue: false
  ipv4: 198.18.0.1
  ipv6: 'fc00::1'

socks5:
  port: 7890
  address: 127.0.0.1
  udp: 'udp'
heiher commented 5 months ago

hev_socks5_tunnel_main返回-1是加载配置文件失败了,如果yaml格式检查没有问题的话,会不会是没有访问配置文件的权限?

800sea commented 5 months ago

谢谢 我想办法把配置文件放在其他地方试试,我现在是直接放在iOS代码里面的。 有可能没有访问权限

800sea commented 5 months ago

我最后的方案是 使用OC做一次桥接来调用hev_socks5_tunnel_main。 配置文件的位置和权限都没有问题.使用swift 转C的文件地址可能有问题 .. 使用OC调用就没有问题