mirror of
https://github.com/pj1234678/RustyDHCP.git
synced 2025-10-26 00:15:41 +08:00
Fix clippy lints
This commit is contained in:
@@ -133,7 +133,7 @@ fn custom_tag<'a>(tag: &'static [u8]) -> impl Fn(&'a [u8]) -> IResult<&'a [u8],
|
||||
}
|
||||
}
|
||||
fn custom_be_u8(input: &[u8]) -> IResult<&[u8], u8> {
|
||||
if input.len() < 1 {
|
||||
if input.is_empty() {
|
||||
return Err(CustomErr::InvalidHlen);
|
||||
}
|
||||
|
||||
@@ -184,18 +184,13 @@ fn decode(input: &[u8]) -> IResult<&[u8], Packet> {
|
||||
let mut options = Vec::new();
|
||||
let mut rest = input;
|
||||
|
||||
loop {
|
||||
match decode_option(rest) {
|
||||
Ok((new_rest, option)) => {
|
||||
while let Ok((new_rest, option)) = decode_option(rest) {
|
||||
rest = new_rest;
|
||||
options.push(option);
|
||||
if rest.starts_with(&[END]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
|
||||
let input = rest.split_at(1).1; // Skip the END tag byte
|
||||
|
||||
@@ -226,12 +221,7 @@ impl Packet {
|
||||
|
||||
/// Extracts requested option payload from packet if available
|
||||
pub fn option(&self, code: u8) -> Option<&DhcpOption> {
|
||||
for option in &self.options {
|
||||
if option.code() == code {
|
||||
return Some(&option);
|
||||
}
|
||||
}
|
||||
None
|
||||
self.options.iter().find(|&option| option.code() == code)
|
||||
}
|
||||
|
||||
/// Convenience function for extracting a packet's message type.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//! This is a convenience module that simplifies the writing of a DHCP server service.
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
|
||||
|
||||
@@ -5,8 +7,6 @@ use crate::options;
|
||||
use crate::options::{DhcpOption, MessageType};
|
||||
use crate::packet::*;
|
||||
|
||||
///! This is a convenience module that simplifies the writing of a DHCP server service.
|
||||
|
||||
pub struct Server {
|
||||
out_buf: Cell<[u8; 1500]>,
|
||||
socket: UdpSocket,
|
||||
@@ -22,12 +22,12 @@ pub trait Handler {
|
||||
pub fn filter_options_by_req(opts: &mut Vec<DhcpOption>, req_params: &[u8]) {
|
||||
let mut pos = 0;
|
||||
let h = &[
|
||||
options::DHCP_MESSAGE_TYPE as u8,
|
||||
options::SERVER_IDENTIFIER as u8,
|
||||
options::SUBNET_MASK as u8,
|
||||
options::IP_ADDRESS_LEASE_TIME as u8,
|
||||
options::DOMAIN_NAME_SERVER as u8,
|
||||
options::ROUTER as u8,
|
||||
options::DHCP_MESSAGE_TYPE,
|
||||
options::SERVER_IDENTIFIER,
|
||||
options::SUBNET_MASK,
|
||||
options::IP_ADDRESS_LEASE_TIME,
|
||||
options::DOMAIN_NAME_SERVER,
|
||||
options::ROUTER,
|
||||
] as &[u8];
|
||||
|
||||
// Process options from req_params
|
||||
@@ -132,7 +132,7 @@ impl Server {
|
||||
if let Some(DhcpOption::ParameterRequestList(prl)) =
|
||||
req_packet.option(options::PARAMETER_REQUEST_LIST)
|
||||
{
|
||||
filter_options_by_req(&mut opts, &prl);
|
||||
filter_options_by_req(&mut opts, prl);
|
||||
}
|
||||
|
||||
self.send(Packet {
|
||||
|
||||
Reference in New Issue
Block a user