From 5950058c76d6b7a97bd9694c95380a3b8075464d Mon Sep 17 00:00:00 2001 From: clerie Date: Sat, 24 Aug 2024 13:19:31 +0200 Subject: [PATCH] Wait for DHCP response with a matching transaction id --- src/main.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index fb5456f..43140b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,10 +45,16 @@ async fn main() { sock.send_to(&msg_buf, remote_addr).await.unwrap(); - let mut recv_buf = [0; 1024]; - let (len, recv_addr) = sock.recv_from(&mut recv_buf).await.unwrap(); - println!("{:?} bytes received from {:?}", len, recv_addr); - println!("{}", &recv_buf[..len].escape_ascii().to_string()); - let recv_msg = Message::decode(&mut Decoder::new(&recv_buf)).unwrap(); - println!("{}", &recv_msg); + loop { + let mut recv_buf = [0; 1024]; + let (len, recv_addr) = sock.recv_from(&mut recv_buf).await.unwrap(); + let recv_msg = Message::decode(&mut Decoder::new(&recv_buf)).unwrap(); + + if recv_msg.xid() == msg.xid() { + println!("{:?} bytes received from {:?}", len, recv_addr); + println!("{}", &recv_buf[..len].escape_ascii().to_string()); + println!("{}", &recv_msg); + break; + } + } }