Feature: use native syscall to bind interface on Linux and macOS
This commit is contained in:
26
component/dialer/bind_linux.go
Normal file
26
component/dialer/bind_linux.go
Normal file
@ -0,0 +1,26 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user