Improve: use interface index for macos

This commit is contained in:
xjasonlyu
2022-04-02 16:08:55 +08:00
parent 289ea82829
commit 992e716216
6 changed files with 34 additions and 166 deletions

View File

@@ -3,6 +3,7 @@ package engine
import (
"errors"
"fmt"
"net"
"sync"
"github.com/xjasonlyu/tun2socks/v2/component/dialer"
@@ -97,7 +98,12 @@ func general(k *Key) error {
log.SetLevel(level)
if k.Interface != "" {
dialer.DefaultInterfaceName.Store(k.Interface)
iface, err := net.InterfaceByName(k.Interface)
if err != nil {
return err
}
dialer.DefaultInterfaceName.Store(iface.Name)
dialer.DefaultInterfaceIndex.Store(int32(iface.Index))
log.Infof("[DIALER] bind to interface: %s", k.Interface)
}