mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-26 18:41:31 +00:00
24 lines
556 B
Go
24 lines
556 B
Go
|
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 {
|
||
|
interfaceName := router.DefaultInterfaceName()
|
||
|
if interfaceName == "" {
|
||
|
return nil
|
||
|
}
|
||
|
var innerErr error
|
||
|
err := conn.Control(func(fd uintptr) {
|
||
|
innerErr = syscall.BindToDevice(int(fd), interfaceName)
|
||
|
})
|
||
|
return E.Errors(innerErr, err)
|
||
|
}
|
||
|
}
|