MutArpPacket

Struct MutArpPacket 

Source
pub struct MutArpPacket<'a>(/* private fields */);

Implementations§

Source§

impl<'a> MutArpPacket<'a>

Source

pub const MIN_LEN: usize = 28usize

The minimum number of bytes in this type of packet. Usually equal to the header size of the protocol.

Source

pub fn new(data: &'a mut [u8]) -> Option<MutArpPacket<'a>>

Creates a new mutable packet based on the given backing slice. Returns None if the buffer is shorter than the minimal length of this packet.

Examples found in repository?
examples/arp_request.rs (line 41)
30fn format_arp_request_frame(
31    buffer: &mut [u8],
32    src_mac: MacAddr,
33    src_ip: Ipv4Addr,
34    target_ip: Ipv4Addr,
35) -> Result<(), &'static str> {
36    static ERR_MSG: &str = "Too short buffer";
37
38    let mut ethernet_packet = MutEthernetPacket::new(buffer).ok_or(ERR_MSG)?;
39    format_broadcast_ethernet_arp(&mut ethernet_packet, src_mac);
40
41    let mut arp_packet = MutArpPacket::new(ethernet_packet.payload()).ok_or(ERR_MSG)?;
42    format_arp_request(&mut arp_packet, src_mac, src_ip, target_ip);
43    Ok(())
44}
Source

pub unsafe fn new_unchecked(data: &'a mut [u8]) -> MutArpPacket<'a>

Creates a new mutable packet based on the given backing slice without checking its length first. If the slice is too short, a subsequent read from a field might result in invalid memory access.

Source

pub fn as_immutable(&'a self) -> ArpPacket<'a>

Returns an immutable version of the same packet and backed by the same byte slice. Used to access the getters.

Source

pub fn data(&mut self) -> &mut [u8]

Returns a mutable reference to the slice backing this packet.

Source

pub fn header(&mut self) -> &mut [u8]

Returns a mutable slice to the part of the backing data that represents the header. This is simply everything up until min_len().

Source

pub fn payload(&mut self) -> &mut [u8]

Returns a mutable slice to the payload part of the backing data. This is simply everything after the header.

Source§

impl<'a> MutArpPacket<'a>

Source

pub fn set_ipv4_over_ethernet_values(&mut self)

Sets the hardware_type, hardware_length, protocol_type and protocol_length fields to correct values for an IPv4 over Ethernet packet.

Examples found in repository?
examples/arp_request.rs (line 58)
52fn format_arp_request<'a>(
53    packet: &mut MutArpPacket<'a>,
54    src_mac: MacAddr,
55    src_ip: Ipv4Addr,
56    target_ip: Ipv4Addr,
57) {
58    packet.set_ipv4_over_ethernet_values();
59    packet.set_operation(Operation::REQUEST);
60    packet.set_sender_mac_addr(src_mac);
61    packet.set_sender_ip_addr(src_ip);
62    // packet.set_target_mac_addr(); // Is ignored in a request anyway
63    packet.set_target_ip_addr(target_ip);
64}
Source§

impl<'a> MutArpPacket<'a>

Source

pub fn set_hardware_type(&mut self, hardware_type: HardwareType)

Source

pub fn set_protocol_type(&mut self, protocol_type: EtherType)

Source

pub fn set_hardware_length(&mut self, hardware_length: u8)

Source

pub fn set_protocol_length(&mut self, protocol_length: u8)

Source

pub fn set_operation(&mut self, operation: Operation)

Examples found in repository?
examples/arp_request.rs (line 59)
52fn format_arp_request<'a>(
53    packet: &mut MutArpPacket<'a>,
54    src_mac: MacAddr,
55    src_ip: Ipv4Addr,
56    target_ip: Ipv4Addr,
57) {
58    packet.set_ipv4_over_ethernet_values();
59    packet.set_operation(Operation::REQUEST);
60    packet.set_sender_mac_addr(src_mac);
61    packet.set_sender_ip_addr(src_ip);
62    // packet.set_target_mac_addr(); // Is ignored in a request anyway
63    packet.set_target_ip_addr(target_ip);
64}
Source

pub fn set_sender_mac_addr(&mut self, sender_mac: MacAddr)

Examples found in repository?
examples/arp_request.rs (line 60)
52fn format_arp_request<'a>(
53    packet: &mut MutArpPacket<'a>,
54    src_mac: MacAddr,
55    src_ip: Ipv4Addr,
56    target_ip: Ipv4Addr,
57) {
58    packet.set_ipv4_over_ethernet_values();
59    packet.set_operation(Operation::REQUEST);
60    packet.set_sender_mac_addr(src_mac);
61    packet.set_sender_ip_addr(src_ip);
62    // packet.set_target_mac_addr(); // Is ignored in a request anyway
63    packet.set_target_ip_addr(target_ip);
64}
Source

pub fn set_sender_ip_addr(&mut self, sender_ip: Ipv4Addr)

Examples found in repository?
examples/arp_request.rs (line 61)
52fn format_arp_request<'a>(
53    packet: &mut MutArpPacket<'a>,
54    src_mac: MacAddr,
55    src_ip: Ipv4Addr,
56    target_ip: Ipv4Addr,
57) {
58    packet.set_ipv4_over_ethernet_values();
59    packet.set_operation(Operation::REQUEST);
60    packet.set_sender_mac_addr(src_mac);
61    packet.set_sender_ip_addr(src_ip);
62    // packet.set_target_mac_addr(); // Is ignored in a request anyway
63    packet.set_target_ip_addr(target_ip);
64}
Source

pub fn set_target_mac_addr(&mut self, target_mac: MacAddr)

Source

pub fn set_target_ip_addr(&mut self, target_ip: Ipv4Addr)

Examples found in repository?
examples/arp_request.rs (line 63)
52fn format_arp_request<'a>(
53    packet: &mut MutArpPacket<'a>,
54    src_mac: MacAddr,
55    src_ip: Ipv4Addr,
56    target_ip: Ipv4Addr,
57) {
58    packet.set_ipv4_over_ethernet_values();
59    packet.set_operation(Operation::REQUEST);
60    packet.set_sender_mac_addr(src_mac);
61    packet.set_sender_ip_addr(src_ip);
62    // packet.set_target_mac_addr(); // Is ignored in a request anyway
63    packet.set_target_ip_addr(target_ip);
64}

Auto Trait Implementations§

§

impl<'a> Freeze for MutArpPacket<'a>

§

impl<'a> RefUnwindSafe for MutArpPacket<'a>

§

impl<'a> Send for MutArpPacket<'a>

§

impl<'a> Sync for MutArpPacket<'a>

§

impl<'a> Unpin for MutArpPacket<'a>

§

impl<'a> !UnwindSafe for MutArpPacket<'a>

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> 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, 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.