Skip to content

Commit

Permalink
src: struct dhcp
Browse files Browse the repository at this point in the history
  • Loading branch information
krishpranav committed Aug 29, 2021
1 parent 51a8765 commit 38e22b7
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/structs/dhcp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use serde::Serialize;
use std::net::Ipv4Addr;

#[derive(Debug, PartialEq, Serialize)]
pub enum DHCP {
ACK(Packet),
DECLINE(Packet),
DISCOVER(Packet),
INFORM(Packet),
NAK(Packet),
OFFER(Packet),
RELEASE(Packet),
REQUEST(Packet),
UNKNOWN(Packet),
}

#[derive(Debug, PartialEq, Serialize)]
pub struct Packet {
pub ciaddr: Ipv4Addr,
pub yiaddr: Ipv4Addr,
pub siaddr: Ipv4Addr,
pub chaddr: [u8; 6],

pub hostname: Option<String>,
pub requested_ip_address: Option<Ipv4Addr>,
pub router: Option<Vec<Ipv4Addr>>,
pub domain_name_server: Option<Vec<Ipv4Addr>>,
}

impl Packet {
pub fn new(ciaddr: Ipv4Addr, yiaddr: Ipv4Addr, siaddr: Ipv4Addr, chaddr: [u8; 6]) -> Packet {
Packet {
ciaddr,
yiaddr,
siaddr,
chaddr,

hostname: None,
requested_ip_address: None,
router: None,
domain_name_server: None,
}
}
}

0 comments on commit 38e22b7

Please sign in to comment.