mirror of
https://github.com/pj1234678/RustyDHCP.git
synced 2025-10-26 00:15:41 +08:00
Minor fixes
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
Cargo.lock
|
||||||
@@ -8,6 +8,7 @@ fn main() {
|
|||||||
server::Server::serve(
|
server::Server::serve(
|
||||||
UdpSocket::bind("0.0.0.0:67").unwrap(),
|
UdpSocket::bind("0.0.0.0:67").unwrap(),
|
||||||
Ipv4Addr::new(0, 0, 0, 0),
|
Ipv4Addr::new(0, 0, 0, 0),
|
||||||
|
Ipv4Addr::new(0, 0, 0, 0),
|
||||||
MyServer {},
|
MyServer {},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -24,7 +25,7 @@ impl server::Handler for MyServer {
|
|||||||
};
|
};
|
||||||
println!(
|
println!(
|
||||||
"{}\t{}\t{}\tOnline",
|
"{}\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),
|
chaddr(&in_packet.chaddr),
|
||||||
Ipv4Addr::from(req_ip)
|
Ipv4Addr::from(req_ip)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
#[macro_use(u32_bytes, bytes_u32)]
|
|
||||||
extern crate dhcp4r;
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::{Ipv4Addr, UdpSocket};
|
use std::net::{Ipv4Addr, UdpSocket};
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
@@ -24,7 +21,7 @@ const LEASE_DURATION_SECS: u32 = 86400;
|
|||||||
const LEASE_NUM: u32 = 252;
|
const LEASE_NUM: u32 = 252;
|
||||||
|
|
||||||
// Derived constants
|
// 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<Instant> = None; // Special value for infinite lease
|
const INFINITE_LEASE: Option<Instant> = None; // Special value for infinite lease
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
26
src/lib.rs
26
src/lib.rs
@@ -1,33 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
pub mod options;
|
pub mod options;
|
||||||
pub mod packet;
|
pub mod packet;
|
||||||
pub mod server;
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user