mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00:00
Sockopt: Allow customSockopt
work for Windows & Darwin (#4576)
* Sockopt: Add custom sockopt on Windows & Darwin * fix windows udp by the way * use resolved addr https://github.com/XTLS/Xray-core/pull/4504#issuecomment-2769153797
This commit is contained in:
parent
7a2f42f8d5
commit
5f3ae64f0c
7 changed files with 306 additions and 118 deletions
|
@ -60,6 +60,10 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
|||
}
|
||||
}
|
||||
var lc net.ListenConfig
|
||||
destAddr, err := net.ResolveUDPAddr("udp", dest.NetAddr())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lc.Control = func(network, address string, c syscall.RawConn) error {
|
||||
for _, ctl := range d.controllers {
|
||||
if err := ctl(network, address, c); err != nil {
|
||||
|
@ -68,7 +72,7 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
|||
}
|
||||
return c.Control(func(fd uintptr) {
|
||||
if sockopt != nil {
|
||||
if err := applyOutboundSocketOptions(network, "", fd, sockopt); err != nil {
|
||||
if err := applyOutboundSocketOptions(network, destAddr.String(), fd, sockopt); err != nil {
|
||||
errors.LogInfo(ctx, err, "failed to apply socket options")
|
||||
}
|
||||
}
|
||||
|
@ -78,10 +82,6 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
destAddr, err := net.ResolveUDPAddr("udp", dest.NetAddr())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &PacketConnWrapper{
|
||||
Conn: packetConn,
|
||||
Dest: destAddr,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue