ping: Fix missing bind for unix socket
This commit is contained in:
parent
144683d882
commit
ce55929883
1 changed files with 11 additions and 1 deletions
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"github.com/sagernet/sing/common/control"
|
"github.com/sagernet/sing/common/control"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
M "github.com/sagernet/sing/common/metadata"
|
M "github.com/sagernet/sing/common/metadata"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -74,6 +73,17 @@ func connect(privileged bool, controlFunc control.Func, destination netip.Addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bindAddress netip.Addr
|
||||||
|
if !destination.Is6() {
|
||||||
|
bindAddress = netip.AddrFrom4([4]byte{0, 0, 0, 0})
|
||||||
|
} else {
|
||||||
|
bindAddress = netip.AddrFrom16([16]byte{})
|
||||||
|
}
|
||||||
|
err = unix.Bind(fd, M.AddrPortToSockaddr(netip.AddrPortFrom(bindAddress, 0)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
err = unix.Connect(fd, M.AddrPortToSockaddr(netip.AddrPortFrom(destination, 0)))
|
err = unix.Connect(fd, M.AddrPortToSockaddr(netip.AddrPortFrom(destination, 0)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, E.Cause(err, "connect()")
|
return nil, E.Cause(err, "connect()")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue