From c613f7bc48ee59a381f7c8b772427bd04e9b3357 Mon Sep 17 00:00:00 2001 From: clerie Date: Sat, 24 Aug 2024 13:15:56 +0200 Subject: [PATCH] Display parsed response --- src/main.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index afa251c..fb5456f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ use dhcproto::{ + Decodable, + Decoder, Encodable, Encoder, v6::{ @@ -21,7 +23,7 @@ const DHCP_Relay_Agent_and_Server_port: u16 = 547; #[tokio::main] async fn main() { - let socket_addr = SocketAddrV6::new("::".parse().unwrap(), DHCP_Client_port, 0, scope_id); + let socket_addr = SocketAddrV6::new("fe80::e3cf:4290:9165:505d".parse().unwrap(), DHCP_Client_port, 0, scope_id); let sock = UdpSocket::bind(socket_addr).await.unwrap(); let remote_addr = SocketAddrV6::new(All_DHCP_Relay_Agents_and_Servers.parse().unwrap(), DHCP_Relay_Agent_and_Server_port, 0, scope_id); @@ -43,8 +45,10 @@ async fn main() { sock.send_to(&msg_buf, remote_addr).await.unwrap(); - let mut buf = [0; 1024]; - let (len, recv_addr) = sock.recv_from(&mut buf).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!("{}", &buf[..len].escape_ascii().to_string()); + println!("{}", &recv_buf[..len].escape_ascii().to_string()); + let recv_msg = Message::decode(&mut Decoder::new(&recv_buf)).unwrap(); + println!("{}", &recv_msg); }