mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-05 21:07:41 +03:00
Improve control options
This commit is contained in:
parent
f8c0f71a89
commit
09b55ce4b6
7 changed files with 197 additions and 5 deletions
|
@ -6,7 +6,11 @@ import (
|
|||
E "github.com/sagernet/sing/common/exceptions"
|
||||
)
|
||||
|
||||
func BindToInterface(interfaceName string) Func {
|
||||
func NewBindManager() BindManager {
|
||||
return nil
|
||||
}
|
||||
|
||||
func BindToInterface(manager BindManager, interfaceName string) Func {
|
||||
return func(network, address string, conn syscall.RawConn) error {
|
||||
var innerErr error
|
||||
err := conn.Control(func(fd uintptr) {
|
||||
|
@ -15,3 +19,21 @@ func BindToInterface(interfaceName string) Func {
|
|||
return E.Errors(innerErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func BindToInterfaceFunc(manager BindManager, interfaceNameFunc func() string) Func {
|
||||
return func(network, address string, conn syscall.RawConn) error {
|
||||
interfaceName := interfaceNameFunc()
|
||||
if interfaceName == "" {
|
||||
return nil
|
||||
}
|
||||
var innerErr error
|
||||
err := conn.Control(func(fd uintptr) {
|
||||
innerErr = syscall.BindToDevice(int(fd), interfaceName)
|
||||
})
|
||||
return E.Errors(innerErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func BindToInterfaceIndexFunc(interfaceIndexFunc func() int) Func {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue