From e8d62af6c35b3327ca2a2cc80bd7374dea0dd4e2 Mon Sep 17 00:00:00 2001 From: junderw Date: Mon, 30 Oct 2023 20:13:21 -0700 Subject: [PATCH] Minor fixes --- .gitignore | 2 ++ examples/monitor.rs | 3 ++- examples/server.rs | 5 +---- src/lib.rs | 26 -------------------------- 4 files changed, 5 insertions(+), 31 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/examples/monitor.rs b/examples/monitor.rs index 36a4915..74bb21f 100644 --- a/examples/monitor.rs +++ b/examples/monitor.rs @@ -8,6 +8,7 @@ fn main() { server::Server::serve( UdpSocket::bind("0.0.0.0:67").unwrap(), Ipv4Addr::new(0, 0, 0, 0), + Ipv4Addr::new(0, 0, 0, 0), MyServer {}, ); } @@ -24,7 +25,7 @@ impl server::Handler for MyServer { }; println!( "{}\t{}\t{}\tOnline", - time::OffsetDateTime::now_local().format("%Y-%m-%dT%H:%M:%S"), + time::OffsetDateTime::try_now_local().unwrap().format("%Y-%m-%dT%H:%M:%S"), chaddr(&in_packet.chaddr), Ipv4Addr::from(req_ip) ); diff --git a/examples/server.rs b/examples/server.rs index f09cd41..60f33e3 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -1,6 +1,3 @@ -#[macro_use(u32_bytes, bytes_u32)] -extern crate dhcp4r; - use std::collections::HashMap; use std::net::{Ipv4Addr, UdpSocket}; use std::ops::Add; @@ -24,7 +21,7 @@ const LEASE_DURATION_SECS: u32 = 86400; const LEASE_NUM: u32 = 252; // Derived constants -const IP_START_NUM: u32 = bytes_u32!(IP_START); +const IP_START_NUM: u32 = u32::from_be_bytes(IP_START); const INFINITE_LEASE: Option = None; // Special value for infinite lease diff --git a/src/lib.rs b/src/lib.rs index f13167b..e239a0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,33 +1,7 @@ - - pub mod options; pub mod packet; pub mod server; -/// Converts a u32 to 4 bytes (Big endian) -#[macro_export] -macro_rules! u32_bytes { - ( $x:expr ) => { - [ - ($x >> 24) as u8, - ($x >> 16) as u8, - ($x >> 8) as u8, - $x as u8, - ] - }; -} - -/// Converts 4 bytes to a u32 (Big endian) -#[macro_export] -macro_rules! bytes_u32 { - ( $x:expr ) => { - ($x[0] as u32) * (1 << 24) - + ($x[1] as u32) * (1 << 16) - + ($x[2] as u32) * (1 << 8) - + ($x[3] as u32) - }; -} - #[cfg(test)] mod tests { #[test]