This commit is contained in:
bluepython508 committed 2026-10-22 12:27:19 +01:00
1 parent 3530afb854
commit 6903fcff27
2146 files changed
+112256 -190703

No files matched your search

+9 -4
View File
@@ -98,7 +98,7 @@ func (tun *NativeTun) routineRouteListener(tunIfindex int) {
}
}
func CreateTUN(name string, mtu int) (Device, error) {
func CreateTUN(name string, mtu int, _ ...Option) (Device, error) {
ifIndex := -1
if name != "utun" {
_, err := fmt.Sscanf(name, "utun%d", &ifIndex)
@@ -148,6 +148,10 @@ func CreateTUN(name string, mtu int) (Device, error) {
return tun, err
}
func CreateTUNFromFiles(files []*os.File, mtu int) (Device, error) {
return createTUNFromFilesNoMQ(files, mtu)
}
func CreateTUNFromFile(file *os.File, mtu int) (Device, error) {
tun := &NativeTun{
tunFile: file,
@@ -217,7 +221,7 @@ func (tun *NativeTun) Events() <-chan Event {
return tun.events
}
func (tun *NativeTun) Read(bufs [][]byte, sizes []int, offset int) (int, error) {
func (tun *NativeTun) Read(slab []byte, packets []ReadPacket) (int, error) {
// TODO: the BSDs look very similar in Read() and Write(). They should be
// collapsed, with platform-specific files containing the varying parts of
// their implementations.
@@ -225,12 +229,13 @@ func (tun *NativeTun) Read(bufs [][]byte, sizes []int, offset int) (int, error)
case err := <-tun.errors:
return 0, err
default:
buf := bufs[0][offset-4:]
buf := slab[ReadPacketSpacing-4 : len(slab)-ReadPacketSpacing]
n, err := tun.tunFile.Read(buf[:])
if n < 4 {
return 0, err
}
sizes[0] = n - 4
packets[0].Offset = ReadPacketSpacing
packets[0].Size = n - 4
return 1, err
}
}