Packet

Struct Packet 

Source
pub struct Packet {
    pub header: Header<Ipv4Address>,
    pub pdu: Vec<Segment>,
}
Expand description

Represents a Network Layer Packet. It contains one or more Segments.

Fields§

§header: Header<Ipv4Address>§pdu: Vec<Segment>

Implementations§

Source§

impl Packet

Source

pub fn new(header: Header<Ipv4Address>, pdu: Vec<Segment>) -> Self

Constructs a new instance of the layer.

Examples found in repository?
examples/main_tester.rs (lines 23-26)
6fn main() {
7    println!("--- DTP Simple Encapsulation Example ---");
8
9    // 1. The Payload: Start with the data you want to send.
10    let my_payload = Bytes::from_static(b"Hello, DTP!");
11    println!("\n[1] Application Data: '{}'", String::from_utf8_lossy(&my_payload));
12
13    // 2. Transport Layer: Encapsulate the data in a Segment.
14    //    This layer adds source and destination port numbers.
15    let transport_segment = Segment::new(
16        Header::new(54321, 443), // Source Port (dynamic) -> Destination Port (HTTPS)
17        my_payload,
18    );
19    println!("\n[2] Encapsulated into a Transport Segment...");
20
21    // 3. Network Layer: Place the Segment into a Packet.
22    //    This layer adds source and destination IP addresses.
23    let network_packet = Packet::new(
24        Header::new(0x7F000001, 0x08080808), // 127.0.0.1 -> 8.8.8.8 (Google DNS)
25        vec![transport_segment],
26    );
27    println!("\n[3] Encapsulated into a Network Packet...");
28
29    // 4. Data Link Layer: Place the Packet into a Frame.
30    //    This is the final layer, adding MAC addresses for the local network link.
31    let datalink_frame = Frame::new(
32        Header::new(
33            [0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF], // Your device's MAC Address
34            [0x11, 0x22, 0x33, 0x44, 0x55, 0x66], // The gateway/router's MAC Address
35        ),
36        vec![network_packet],
37    );
38    println!("\n[4] Encapsulated into a Data Link Frame...");
39
40    // 5. Final Result: Print the fully constructed frame.
41    //    The custom Display implementation shows the beautiful, nested structure.
42    println!("\n--- Final Frame Ready for Transmission ---\n");
43    println!("{}", datalink_frame);
44}

Trait Implementations§

Source§

impl Clone for Packet

Source§

fn clone(&self) -> Packet

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Packet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Packet

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Packet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> IntoIterator for &'a Packet

Source§

type Item = &'a <Vec<Segment> as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, <Vec<Segment> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Packet

Source§

type Item = <Vec<Segment> as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = <Vec<Segment> as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Packet

Source§

fn eq(&self, other: &Packet) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Packet

Auto Trait Implementations§

§

impl Freeze for Packet

§

impl RefUnwindSafe for Packet

§

impl Send for Packet

§

impl Sync for Packet

§

impl Unpin for Packet

§

impl UnwindSafe for Packet

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.