Compare commits

..

No commits in common. "559869c2b891038783c6311807e2c2dd6847e733" and "36a5fe61cc9dd91b8fda0ad96672064356ee02c5" have entirely different histories.

3 changed files with 16 additions and 99 deletions

55
Cargo.lock generated
View File

@ -219,8 +219,6 @@ dependencies = [
"ipnetwork",
"log",
"pnet",
"serde",
"serde_yaml",
"tokio",
]
@ -259,12 +257,6 @@ dependencies = [
"log",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "form_urlencoded"
version = "1.2.1"
@ -337,12 +329,6 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "heck"
version = "0.4.1"
@ -394,16 +380,6 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "indexmap"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "ipnet"
version = "2.9.0"
@ -425,12 +401,6 @@ version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itoa"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "lazy_static"
version = "1.5.0"
@ -704,12 +674,6 @@ version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "ryu"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "serde"
version = "1.0.209"
@ -730,19 +694,6 @@ dependencies = [
"syn 2.0.72",
]
[[package]]
name = "serde_yaml"
version = "0.9.34+deprecated"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
dependencies = [
"indexmap",
"itoa",
"ryu",
"serde",
"unsafe-libyaml",
]
[[package]]
name = "shlex"
version = "1.3.0"
@ -939,12 +890,6 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
[[package]]
name = "url"
version = "2.5.2"

View File

@ -12,6 +12,4 @@ hex = "0.4.3"
ipnetwork = "0.20.0"
log = "0.4.22"
pnet = "0.35.0"
serde = { version = "1.0.209", features = ["derive"] }
serde_yaml = "0.9.34"
tokio = { version = "1.39.3", features = ["macros", "net", "rt-multi-thread"] }

View File

@ -24,7 +24,6 @@ use log::{
Level,
};
use pnet;
use serde::Serialize;
use std::net::SocketAddrV6;
use tokio::net::UdpSocket;
@ -40,43 +39,6 @@ struct Cli {
interface: String,
}
#[derive(Serialize)]
struct MessageMap {
#[serde(skip_serializing_if = "Option::is_none")]
server_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
domain_name_servers: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
domain_search_list: Option<Vec<String>>,
}
impl MessageMap {
fn new() -> Self {
Self {
server_id: None,
domain_name_servers: None,
domain_search_list: None,
}
}
}
fn message_to_map(msg: &Message) -> MessageMap {
let mut map = MessageMap::new();
if let Some(DhcpOption::ServerId(server_id)) = &msg.opts().get(OptionCode::ServerId) {
map.server_id = Some(hex::encode(&server_id));
}
if let Some(DhcpOption::DomainNameServers(domain_name_servers)) = &msg.opts().get(OptionCode::DomainNameServers) {
map.domain_name_servers = Some(domain_name_servers.iter().map(|a| a.to_string()).collect());
}
if let Some(DhcpOption::DomainSearchList(domain_search_list)) = &msg.opts().get(OptionCode::DomainSearchList) {
map.domain_search_list = Some(domain_search_list.iter().map(|n| n.to_string()).collect());
}
return map;
}
#[tokio::main]
async fn main() -> Result<()>{
env_logger::init();
@ -153,10 +115,22 @@ async fn main() -> Result<()>{
}
};
let message_map = message_to_map(&response_msg);
let message_map_yaml = serde_yaml::to_string(&message_map)
.context("Unable to format message to yaml")?;
println!("{}", message_map_yaml);
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);
}
}
Ok(())
}