Wait for DHCP response with a matching transaction id

This commit is contained in:
clerie 2024-08-24 13:19:31 +02:00
parent c613f7bc48
commit 5950058c76

View File

@ -45,10 +45,16 @@ async fn main() {
sock.send_to(&msg_buf, remote_addr).await.unwrap(); sock.send_to(&msg_buf, remote_addr).await.unwrap();
let mut recv_buf = [0; 1024]; loop {
let (len, recv_addr) = sock.recv_from(&mut recv_buf).await.unwrap(); let mut recv_buf = [0; 1024];
println!("{:?} bytes received from {:?}", len, recv_addr); let (len, recv_addr) = sock.recv_from(&mut recv_buf).await.unwrap();
println!("{}", &recv_buf[..len].escape_ascii().to_string()); let recv_msg = Message::decode(&mut Decoder::new(&recv_buf)).unwrap();
let recv_msg = Message::decode(&mut Decoder::new(&recv_buf)).unwrap();
println!("{}", &recv_msg); 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;
}
}
} }