Skip to content

Commit b1c723d

Browse files
committed
test(ip_recverr): Fix the socket binding error from OS, now sends proper network error
1 parent 3d1ef20 commit b1c723d

File tree

1 file changed

+3
-73
lines changed

1 file changed

+3
-73
lines changed

quinn-udp/tests/tests.rs

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,10 @@ fn ip_to_v6_mapped(x: IpAddr) -> IpAddr {
372372

373373
#[cfg(target_os = "linux")]
374374
#[test]
375-
fn test_ip_recverr() {
375+
fn test_ipv4_recverr() {
376376
use std::time::Duration;
377377

378-
let socket = socket2::Socket::new(
379-
socket2::Domain::IPV4,
380-
socket2::Type::DGRAM,
381-
Some(socket2::Protocol::UDP),
382-
)
383-
.expect("failed to create socket");
384-
385-
// Bind to localhost
386-
let bind_addr = socket2::SockAddr::from(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0));
387-
socket.bind(&bind_addr).expect("failed to bind");
378+
let socket = UdpSocket::bind((Ipv4Addr::LOCALHOST, 0)).unwrap();
388379

389380
// Create UdpSocketState (this should enable IP_RECVERR)
390381
let state = UdpSocketState::new((&socket).into()).expect("failed to create UdpSocketState");
@@ -406,59 +397,6 @@ fn test_ip_recverr() {
406397

407398
std::thread::sleep(Duration::from_millis(200));
408399

409-
// for attempt in 0..5 {
410-
// match state.recv(
411-
// (&socket).into(),
412-
// &mut [IoSliceMut::new(&mut buf)],
413-
// std::slice::from_mut(&mut meta),
414-
// ) {
415-
// Ok(n) => {
416-
// println!("Attempt {}: Received {} messages", attempt, n);
417-
// }
418-
// Err(e) => {
419-
// println!(
420-
// "Attempt {}: Received error: {} (kind: {:?}, raw: {:?})",
421-
// attempt,
422-
// e,
423-
// e.kind(),
424-
// e.raw_os_error()
425-
// );
426-
427-
// // Check if this is an ICMP-related error
428-
// match e.raw_os_error() {
429-
// Some(libc::EHOSTUNREACH) => {
430-
// println!("Received EHOSTUNREACH (Host unreachable)");
431-
// received_icmp_error = true;
432-
// }
433-
// Some(libc::ENETUNREACH) => {
434-
// println!("Received ENETUNREACH (Network unreachable)");
435-
// received_icmp_error = true;
436-
// }
437-
// Some(libc::ECONNREFUSED) => {
438-
// println!("Received ECONNREFUSED (Connection refused)");
439-
// received_icmp_error = true;
440-
// }
441-
// Some(libc::ETIMEDOUT) => {
442-
// println!("Received ETIMEDOUT (Timeout)");
443-
// received_icmp_error = true;
444-
// }
445-
// _ if e.kind() == std::io::ErrorKind::WouldBlock => {
446-
// println!("No more errors in queue");
447-
// break;
448-
// }
449-
// _ => {}
450-
// }
451-
// }
452-
// }
453-
// std::thread::sleep(Duration::from_millis(10));
454-
// }
455-
456-
// if received_icmp_error {
457-
// println!("IP_RECVERR is working! Received ICMP error.");
458-
// } else {
459-
// println!("No ICMP error received (may be normal depending on network config)");
460-
// }
461-
462400
match state.recv_icmp_err((&socket).into()) {
463401
Ok(Some(icmp_err)) => {
464402
eprintln!("icmp packet recieved");
@@ -478,15 +416,7 @@ fn test_ip_recverr() {
478416
fn test_ipv6_recverr() {
479417
use std::time::Duration;
480418

481-
let socket = socket2::Socket::new(
482-
socket2::Domain::IPV6,
483-
socket2::Type::DGRAM,
484-
Some(socket2::Protocol::UDP),
485-
)
486-
.expect("failed to create IPv6 socket");
487-
488-
let bind_addr = socket2::SockAddr::from(SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0));
489-
socket.bind(&bind_addr).expect("failed to bind");
419+
let socket = UdpSocket::bind((Ipv6Addr::LOCALHOST, 0)).unwrap();
490420

491421
let state = UdpSocketState::new((&socket).into()).expect("failed to create UdpSocketState");
492422

0 commit comments

Comments
 (0)