2022-07-10 00:18:52 +00:00
|
|
|
package dialer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
|
|
"github.com/sagernet/sing/common/control"
|
|
|
|
E "github.com/sagernet/sing/common/exceptions"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BindToInterface(router adapter.Router) control.Func {
|
|
|
|
return func(network, address string, conn syscall.RawConn) error {
|
2022-07-15 03:51:51 +00:00
|
|
|
interfaceName := router.AutoDetectInterfaceName()
|
2022-07-10 00:18:52 +00:00
|
|
|
if interfaceName == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var innerErr error
|
|
|
|
err := conn.Control(func(fd uintptr) {
|
|
|
|
innerErr = syscall.BindToDevice(int(fd), interfaceName)
|
|
|
|
})
|
|
|
|
return E.Errors(innerErr, err)
|
|
|
|
}
|
|
|
|
}
|