-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
351 additions
and
203 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use core::fmt::Display; | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
#[repr(C, u8)] | ||
pub enum Protocol { | ||
Transport(TransportProtocol) = 0, | ||
Network(NetworkProtocol) = 1, | ||
Link(LinkProtocol) = 2, | ||
} | ||
|
||
// Transport Protocols | ||
|
||
pub const NB_TRANSPORT_PROTOCOL: u16 = 2; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
#[repr(C)] | ||
pub enum TransportProtocol { | ||
TCP = 0, | ||
UDP = 1, | ||
} | ||
|
||
impl TransportProtocol { | ||
pub fn all() -> [TransportProtocol; 2] { | ||
[TransportProtocol::TCP, TransportProtocol::UDP] | ||
} | ||
} | ||
|
||
impl Display for TransportProtocol { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
TransportProtocol::TCP => write!(f, "Tcp"), | ||
TransportProtocol::UDP => write!(f, "Udp"), | ||
} | ||
} | ||
} | ||
|
||
// Network Protocols | ||
|
||
pub const NB_NETWORK_PROTOCOL: u16 = 3; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
#[repr(C)] | ||
pub enum NetworkProtocol { | ||
Ipv4 = 0, | ||
Ipv6 = 1, | ||
Icmp = 2, | ||
} | ||
|
||
impl NetworkProtocol { | ||
pub fn all() -> [NetworkProtocol; 3] { | ||
[ | ||
NetworkProtocol::Ipv4, | ||
NetworkProtocol::Ipv6, | ||
NetworkProtocol::Icmp, | ||
] | ||
} | ||
} | ||
|
||
impl Display for NetworkProtocol { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
NetworkProtocol::Ipv4 => write!(f, "Ipv4"), | ||
NetworkProtocol::Ipv6 => write!(f, "Ipv6"), | ||
NetworkProtocol::Icmp => write!(f, "Icmp"), | ||
} | ||
} | ||
} | ||
|
||
// Link Protocols | ||
|
||
pub const NB_LINK_PROTOCOL: u16 = 1; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
#[repr(C)] | ||
pub enum LinkProtocol { | ||
Arp = 0, | ||
} | ||
|
||
impl LinkProtocol { | ||
pub fn all() -> [LinkProtocol; 1] { | ||
[LinkProtocol::Arp] | ||
} | ||
} | ||
|
||
impl Display for LinkProtocol { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
write!(f, "Arp") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.