mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-07 17:51:16 +08:00
20 lines
366 B
Go
Executable File
20 lines
366 B
Go
Executable File
package dialer
|
|
|
|
import (
|
|
"net"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func bindToInterface(network, address string, c syscall.RawConn) error {
|
|
ipStr, _, _ := net.SplitHostPort(address)
|
|
if ip := net.ParseIP(ipStr); ip != nil && !ip.IsGlobalUnicast() {
|
|
return nil
|
|
}
|
|
|
|
return c.Control(func(fd uintptr) {
|
|
unix.BindToDevice(int(fd), _boundInterface.Name)
|
|
})
|
|
}
|