async fn reply(
    msg_type: options::MessageType,
    additional_options: Vec<DhcpOption<'_>>,
    req_packet: packet::Packet<'_>,
    offer_ip: [u8; 4],
    sender: &mut Sender,
    socket: &mut tokio::net::UdpSocket,
) -> std::io::Result<usize> {
    let ciaddr = match msg_type {
        MessageType::Nak => [0, 0, 0, 0],
        _ => req_packet.ciaddr,
    };

    let mt = &[msg_type as u8];

    let mut opts: Vec<DhcpOption> = Vec::with_capacity(additional_options.len() + 2);
    opts.push(DhcpOption {
        code: options::DHCP_MESSAGE_TYPE,
        data: mt,
    });
    opts.push(DhcpOption {
        code: options::SERVER_IDENTIFIER,
        data: &sender.server_ip,
    });
    opts.extend(additional_options);

    // Encodes and sends DHCP packet back to the client.
    let p = Packet {
        reply: true,
        hops: 0,
        xid: req_packet.xid,
        secs: 0,
        broadcast: req_packet.broadcast,
        ciaddr,
        yiaddr: offer_ip,
        siaddr: [0, 0, 0, 0],
        giaddr: req_packet.giaddr,
        chaddr: req_packet.chaddr,
        options: opts,
    };
    let mut addr = sender.src;
    if p.broadcast || addr.ip() == IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)) {
        addr.set_ip(IpAddr::V4(Ipv4Addr::new(255, 255, 255, 255)));
    }
    socket.send_to(p.encode(sender.out_buf.as_mut()), &addr).await
}
/// Constructs and sends reply packet back to the client.
///
/// # Arguments
///
/// additional_options should not include DHCP_MESSAGE_TYPE nor SERVER_IDENTIFIER as these
/// are added automatically.
Constructs and sends reply packet back to the client.
Constructs and sends reply packet back to the client .
async fn reply(
    msg_type: options::MessageType,
    additional_options: Vec<DhcpOption<'_>>,
    req_packet: packet::Packet<'_>,
    offer_ip: [u8; 4],
    sender: &mut Sender,
    socket: &mut tokio::net::UdpSocket,
) -> std::io::Result<usize> {
    let ciaddr = match msg_type {
        MessageType::Nak => [0, 0, 0, 0],
        _ => req_packet.ciaddr,
    };
    let mt = &[msg_type as u8];
    let mut opts: Vec<DhcpOption> = Vec::with_capacity(additional_options.len() + 2);
    opts.push(DhcpOption {
        code: options::DHCP_MESSAGE_TYPE,
        data: mt,
    });
    opts.push(DhcpOption {
        code: options::SERVER_IDENTIFIER,
        data: &sender.server_ip,
    });
    opts.extend(additional_options);
    // Encodes and sends DHCP packet back to the client.
    let p = Packet {
        reply: true,
        hops: 0,
        xid: req_packet.xid,
        secs: 0,
        broadcast: req_packet.broadcast,
        ciaddr,
        yiaddr: offer_ip,
        siaddr: [0, 0, 0, 0],
        giaddr: req_packet.giaddr,
        chaddr: req_packet.chaddr,
        options: opts,
    };
    let mut addr = sender.src;
    if p.broadcast || addr.ip() == IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)) {
        addr.set_ip(IpAddr::V4(Ipv4Addr::new(255, 255, 255, 255)));
    }
    socket.send_to(p.encode(sender.out_buf.as_mut()), &addr).await
}
async fn reply ( msg_type : options :: MessageType , additional_options : Vec < DhcpOption < ' _ > > , req_packet : packet :: Packet < ' _ > , offer_ip : [ u8 ; 4 ] , sender : & mut Sender , socket : & mut tokio :: net :: UdpSocket , ) -> std :: io :: Result < usize > { let ciaddr = match msg_type { MessageType :: Nak => [ 0 , 0 , 0 , 0 ] , _ => req_packet . ciaddr , } ; let mt = & [ msg_type as u8 ] ; let mut opts : Vec < DhcpOption > = Vec :: with_capacity ( additional_options . len ( ) + 2 ) ; opts . push ( DhcpOption { code : options :: DHCP_MESSAGE_TYPE , data : mt , } ) ; opts . push ( DhcpOption { code : options :: SERVER_IDENTIFIER , data : & sender . server_ip , } ) ; opts . extend ( additional_options ) ; // Encodes and sends DHCP packet back to the client. let p = Packet { reply : true , hops : 0 , xid : req_packet . xid , secs : 0 , broadcast : req_packet . broadcast , ciaddr , yiaddr : offer_ip , siaddr : [ 0 , 0 , 0 , 0 ] , giaddr : req_packet . giaddr , chaddr : req_packet . chaddr , options : opts , } ; let mut addr = sender . src ; if p . broadcast || addr . ip ( ) == IpAddr :: V4 ( Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) ) { addr . set_ip ( IpAddr :: V4 ( Ipv4Addr :: new ( 255 , 255 , 255 , 255 ) ) ) ; } socket . send_to ( p . encode ( sender . out_buf . as_mut ( ) ) , & addr ) . await }
Constructs and sends reply packet back to the client.
Constructs and sends reply packet back to the client .
msg_type
options::MessageType
additional_options
Vec<DhcpOption<'_>>
req_packet
packet::Packet<'_>
offer_ip
[u8; 4]
sender
&mut Sender
socket
&mut tokio::net::UdpSocket
msg_type
options::MessageType
additional_options
Vec<DhcpOption<'_>>
req_packet
packet::Packet<'_>
offer_ip
[u8; 4]
sender
&mut Sender
socket
&mut tokio::net::UdpSocket