Skip to content

Commit

Permalink
add newTUNDevice to windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpalide committed Mar 16, 2024
1 parent 177c854 commit 239cff8
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions internal/vpn/tun_device_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//go:build windows
// +build windows

package vpn

import (
"fmt"

"golang.zx2c4.com/wireguard/tun"
)

type tunDevice struct {
tun tun.Device
name string
}

func newTUNDevice() (TUNDevice, error) {
const tunName = "tun0"

dev, err := tun.CreateTUN(tunName, TUNMTU)
if err != nil {
return nil, fmt.Errorf("error allocating TUN interface: %w", err)
}

name, err := dev.Name()
if err != nil {
return nil, fmt.Errorf("error getting interface name: %w", err)
}

return &tunDevice{
tun: dev,
name: name,
}, nil
}

func (t *tunDevice) Read(buf []byte) (int, error) {
return t.tun.Read(buf, 0)
}

func (t *tunDevice) Write(buf []byte) (int, error) {
return t.tun.Write(buf, 0)
}

func (t *tunDevice) Close() error {
return t.tun.Close()
}

func (t *tunDevice) Name() string {
return t.name
}

0 comments on commit 239cff8

Please sign in to comment.