about summary refs log tree commit diff
path: root/src/ethertype.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ethertype.rs')
-rw-r--r--src/ethertype.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/ethertype.rs b/src/ethertype.rs
new file mode 100644
index 0000000..0d728f3
--- /dev/null
+++ b/src/ethertype.rs
@@ -0,0 +1,20 @@
+#[derive(Copy, Clone, Debug, PartialEq)]
+pub enum EtherType {
+	/// The frame type is IEEE 802.3 and this is it's length
+	Length(u16),
+	IPv4,
+	IPv6,
+	Unknown(u16),
+}
+
+impl EtherType {
+	//TODO: check ethertype is correct
+	pub fn new(n: u16) -> Self {
+		match n {
+			n if n <= 1500 => Self::Length(n),
+			0x0800 => Self::IPv4,
+			0x86DD => Self::IPv6,
+			n => Self::Unknown(n),
+		}
+	}
+}