Skip to content

Commit

Permalink
udp: tolerate true IPv4 dest addrs when dual-stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Dec 31, 2023
1 parent fe75d8b commit 1238562
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions quinn-udp/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
io::IoSliceMut,
net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, UdpSocket},
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, UdpSocket},
slice,
};

Expand Down Expand Up @@ -125,7 +125,9 @@ fn test_send_recv(send: &Socket, recv: &Socket, transmit: Transmit) {
let dst = meta.dst_ip.unwrap();
match (send_v6, recv_v6) {
(_, false) => assert_eq!(dst, Ipv4Addr::LOCALHOST),
(false, true) => assert_eq!(dst, Ipv4Addr::LOCALHOST.to_ipv6_mapped()),
// Windows gives us real IPv4 addrs, whereas *nix use IPv6-mapped IPv4
// addrs. Canonicalize to IPv6-mapped for robustness.
(false, true) => assert_eq!(ip_to_v6_mapped(dst), Ipv4Addr::LOCALHOST.to_ipv6_mapped()),
(true, true) => assert_eq!(dst, Ipv6Addr::LOCALHOST),
}
}
Expand All @@ -136,3 +138,10 @@ fn to_v6_mapped(x: SocketAddr) -> SocketAddr {
SocketAddr::V6(_) => x,
}
}

fn ip_to_v6_mapped(x: IpAddr) -> IpAddr {
match x {
IpAddr::V4(x) => IpAddr::V6(x.to_ipv6_mapped()),
IpAddr::V6(_) => x,
}
}

0 comments on commit 1238562

Please sign in to comment.