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