pub struct MutArpPacket<'a>(/* private fields */);Implementations§
Source§impl<'a> MutArpPacket<'a>
impl<'a> MutArpPacket<'a>
Sourcepub const MIN_LEN: usize = 28usize
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.
Sourcepub fn new(data: &'a mut [u8]) -> Option<MutArpPacket<'a>>
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}Sourcepub unsafe fn new_unchecked(data: &'a mut [u8]) -> MutArpPacket<'a>
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.
Sourcepub fn as_immutable(&'a self) -> ArpPacket<'a>
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.
Sourcepub fn data(&mut self) -> &mut [u8] ⓘ
pub fn data(&mut self) -> &mut [u8] ⓘ
Returns a mutable reference to the slice backing this packet.
Source§impl<'a> MutArpPacket<'a>
impl<'a> MutArpPacket<'a>
Sourcepub fn set_ipv4_over_ethernet_values(&mut self)
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>
impl<'a> MutArpPacket<'a>
pub fn set_hardware_type(&mut self, hardware_type: HardwareType)
pub fn set_protocol_type(&mut self, protocol_type: EtherType)
pub fn set_hardware_length(&mut self, hardware_length: u8)
pub fn set_protocol_length(&mut self, protocol_length: u8)
Sourcepub fn set_operation(&mut self, operation: Operation)
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}Sourcepub fn set_sender_mac_addr(&mut self, sender_mac: MacAddr)
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}Sourcepub fn set_sender_ip_addr(&mut self, sender_ip: Ipv4Addr)
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}pub fn set_target_mac_addr(&mut self, target_mac: MacAddr)
Sourcepub fn set_target_ip_addr(&mut self, target_ip: Ipv4Addr)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more