mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-07 21:03:11 +08:00
Compare commits
2 Commits
e70488287b
...
d5698333cd
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d5698333cd | ||
![]() |
ea5106e8ec |
@ -40,7 +40,10 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
|
||||
if err != nil {
|
||||
return errors.New("failed to find the interface").Base(err)
|
||||
}
|
||||
isV4 := (network == "tcp4" || network == "udp4")
|
||||
// easy way to check if the address is ipv4
|
||||
isV4 := strings.Contains(address, ".")
|
||||
// note: DO NOT trust the passed network variable, it can be udp6 even if the address is ipv4
|
||||
// because operating system might(always) use ipv6 socket to process ipv4
|
||||
if isV4 {
|
||||
var bytes [4]byte
|
||||
binary.BigEndian.PutUint32(bytes[:], uint32(inf.Index))
|
||||
|
@ -60,10 +60,14 @@ 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 {
|
||||
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")
|
||||
}
|
||||
}
|
||||
@ -73,10 +77,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…
x
Reference in New Issue
Block a user