Sockopt: Fix Windows UDP interface bind; Allow customSockopt work for UDP (#4504)

This commit is contained in:
风扇滑翔翼 2025-03-21 18:48:46 +08:00 committed by GitHub
parent 1067171e6a
commit b585b26f29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 169 additions and 137 deletions

View file

@ -73,7 +73,13 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
return nil, err
}
sys.Control(func(fd uintptr) {
if err := applyOutboundSocketOptions("udp", dest.NetAddr(), fd, sockopt); err != nil {
var network string
if destAddr.IP.To4() != nil {
network = "udp4"
} else {
network = "udp6"
}
if err := applyOutboundSocketOptions(network, dest.NetAddr(), fd, sockopt); err != nil {
errors.LogInfo(ctx, err, "failed to apply socket options")
}
})