Compare commits
No commits in common. "36a5fe61cc9dd91b8fda0ad96672064356ee02c5" and "1ea4715b59723cb077357249c02ffaa504b1f3ed" have entirely different histories.
36a5fe61cc
...
1ea4715b59
37
src/main.rs
37
src/main.rs
@ -92,43 +92,20 @@ 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")?;
|
||||||
|
|
||||||
let response_msg = loop {
|
loop {
|
||||||
let mut recv_buf = [0; 1024];
|
let mut recv_buf = [0; 1024];
|
||||||
let (recv_len, recv_addr) = sock.recv_from(&mut recv_buf).await
|
let (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 log_enabled!(Level::Debug) {
|
|
||||||
debug!("Packet contains transaction id: 0x{}", hex::encode(&msg.xid()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if recv_msg.xid() == msg.xid() {
|
if recv_msg.xid() == msg.xid() {
|
||||||
info!("Found reponse with matching transaction id");
|
info!("{:?} bytes received from {:?}", len, recv_addr);
|
||||||
break recv_msg;
|
if log_enabled!(Level::Debug) {
|
||||||
|
debug!("Received packet: {}", hex::encode(&recv_buf[..len]));
|
||||||
}
|
}
|
||||||
};
|
println!("{}", &recv_msg);
|
||||||
|
break;
|
||||||
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