diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2024-01-17 10:51:23 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2024-01-17 10:51:23 +0100 |
commit | 00d865d82ec3e35532af74cc3daa78d16e9de2d0 (patch) | |
tree | 3525577412c15525cfefe405339bd5cea34ffe6c /src/util.rs | |
parent | b278ff9010c60f8f9d7cdf5e9d0c42a78effbaf0 (diff) |
support clients that don't send a client identifier0.2.6
Uses the chaddr field to generate a client id based on the MAC address preceeded by 0x01. Increases compatibility with IoT devices.
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/util.rs b/src/util.rs index 26ac950..cd595dd 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,6 +4,7 @@ use std::ffi::{c_char, c_int}; use std::io; use std::net::{IpAddr, Ipv4Addr}; +use dhcproto::v4::DhcpOption; use rsdsl_netlinklib::blocking::Connection; /// Helper macro to execute a system call that returns an `io::Result`. @@ -19,12 +20,19 @@ macro_rules! syscall { }}; } -pub fn format_client_id(client_id: &[u8]) -> Result<String> { +pub fn gen_client_id(hwaddr: &[u8]) -> DhcpOption { + let mut client_id = vec![0x01]; + client_id.extend_from_slice(hwaddr); + + DhcpOption::ClientIdentifier(client_id) +} + +pub fn format_client_id(client_id: &[u8]) -> String { client_id .iter() .map(|octet| format!("{:02x}", octet)) .reduce(|acc, octet| acc + ":" + &octet) - .ok_or(Error::EmptyClientId) + .unwrap_or(String::new()) } pub fn local_ip(conn: &Connection, link: String) -> Result<Ipv4Addr> { |