mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 05:31:18 +08:00
27 lines
549 B
Go
27 lines
549 B
Go
|
package dialer
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
"syscall"
|
||
|
)
|
||
|
|
||
|
func bindIfaceToDialer(dialer *net.Dialer, ifaceName string) error {
|
||
|
dialer.Control = func(network, address string, c syscall.RawConn) error {
|
||
|
return c.Control(func(fd uintptr) {
|
||
|
syscall.BindToDevice(int(fd), ifaceName)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func bindIfaceToListenConfig(lc *net.ListenConfig, ifaceName string) error {
|
||
|
lc.Control = func(network, address string, c syscall.RawConn) error {
|
||
|
return c.Control(func(fd uintptr) {
|
||
|
syscall.BindToDevice(int(fd), ifaceName)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|