Compare commits
2 Commits
1ea4715b59
...
36a5fe61cc
Author | SHA1 | Date | |
---|---|---|---|
36a5fe61cc | |||
a6d6936499 |
37
src/main.rs
37
src/main.rs
@ -92,20 +92,43 @@ async fn main() -> Result<()>{
|
|||||||
sock.send_to(&msg_buf, remote_addr).await
|
sock.send_to(&msg_buf, remote_addr).await
|
||||||
.context("Failed to send DHCPv6 INFORMATION-REQUEST message")?;
|
.context("Failed to send DHCPv6 INFORMATION-REQUEST message")?;
|
||||||
|
|
||||||
loop {
|
let response_msg = loop {
|
||||||
let mut recv_buf = [0; 1024];
|
let mut recv_buf = [0; 1024];
|
||||||
let (len, recv_addr) = sock.recv_from(&mut recv_buf).await
|
let (recv_len, recv_addr) = sock.recv_from(&mut recv_buf).await
|
||||||
.context("Failed to receive DHCPv6 response")?;
|
.context("Failed to receive DHCPv6 response")?;
|
||||||
|
|
||||||
|
if log_enabled!(Level::Debug) {
|
||||||
|
debug!("{:?} bytes received from {:?}", recv_len, recv_addr);
|
||||||
|
debug!("Received packet: {}", hex::encode(&recv_buf[..recv_len]));
|
||||||
|
}
|
||||||
|
|
||||||
let recv_msg = Message::decode(&mut Decoder::new(&recv_buf))
|
let recv_msg = Message::decode(&mut Decoder::new(&recv_buf))
|
||||||
.context("Unable to parse DHCPv6 response message")?;
|
.context("Unable to parse DHCPv6 response message")?;
|
||||||
|
|
||||||
if recv_msg.xid() == msg.xid() {
|
|
||||||
info!("{:?} bytes received from {:?}", len, recv_addr);
|
|
||||||
if log_enabled!(Level::Debug) {
|
if log_enabled!(Level::Debug) {
|
||||||
debug!("Received packet: {}", hex::encode(&recv_buf[..len]));
|
debug!("Packet contains transaction id: 0x{}", hex::encode(&msg.xid()));
|
||||||
}
|
}
|
||||||
println!("{}", &recv_msg);
|
|
||||||
break;
|
if recv_msg.xid() == msg.xid() {
|
||||||
|
info!("Found reponse with matching transaction id");
|
||||||
|
break recv_msg;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(DhcpOption::ServerId(server_id)) = &response_msg.opts().get(OptionCode::ServerId) {
|
||||||
|
println!("server_id: {}", hex::encode(&server_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(DhcpOption::DomainNameServers(domain_name_servers)) = &response_msg.opts().get(OptionCode::DomainNameServers) {
|
||||||
|
println!("domain_name_servers:");
|
||||||
|
for domain_name_server in domain_name_servers {
|
||||||
|
println!(" - {}", domain_name_server);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(DhcpOption::DomainSearchList(domain_search_list)) = &response_msg.opts().get(OptionCode::DomainSearchList) {
|
||||||
|
println!("domain_search_list:");
|
||||||
|
for search_domain_name in domain_search_list {
|
||||||
|
println!(" - {}", search_domain_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user