mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
listen system only when bind addr not specified
This commit is contained in:
parent
40796b9f9c
commit
ef739c2127
@ -39,8 +39,12 @@ func resolveSrcAddr(network net.Network, src net.Address) net.Addr {
|
||||
}
|
||||
}
|
||||
|
||||
func hasBindAddr(sockopt *SocketConfig) bool {
|
||||
return len(sockopt.BindAddress) > 0 && sockopt.BindPort > 0
|
||||
}
|
||||
|
||||
func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest net.Destination, sockopt *SocketConfig) (net.Conn, error) {
|
||||
if dest.Network == net.Network_UDP {
|
||||
if dest.Network == net.Network_UDP && !hasBindAddr(sockopt) {
|
||||
srcAddr := resolveSrcAddr(net.Network_UDP, src)
|
||||
if srcAddr == nil {
|
||||
srcAddr = &net.UDPAddr{
|
||||
@ -75,7 +79,7 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
||||
if err := applyOutboundSocketOptions(network, address, fd, sockopt); err != nil {
|
||||
newError("failed to apply socket options").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
}
|
||||
if dest.Network == net.Network_UDP && len(sockopt.BindAddress) > 0 && sockopt.BindPort > 0 {
|
||||
if dest.Network == net.Network_UDP && hasBindAddr(sockopt) {
|
||||
if err := bindAddr(fd, sockopt.BindAddress, sockopt.BindPort); err != nil {
|
||||
newError("failed to bind source address to ", sockopt.BindAddress).Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user