pub struct UdpLayer {
pub index: LayerIndex,
}Expand description
UDP layer representation.
UDP is a simple, connectionless transport protocol defined in RFC 768. The header is 8 bytes:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+Fields§
§index: LayerIndexImplementations§
Source§impl UdpLayer
impl UdpLayer
Sourcepub fn new(index: LayerIndex) -> Self
pub fn new(index: LayerIndex) -> Self
Create a new UDP layer from a layer index.
Sourcepub fn length(&self, buf: &[u8]) -> Result<u16, FieldError>
pub fn length(&self, buf: &[u8]) -> Result<u16, FieldError>
Get the length field (header + data length in bytes).
Sourcepub fn set_src_port(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
pub fn set_src_port(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
Set the source port.
Sourcepub fn set_dst_port(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
pub fn set_dst_port(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
Set the destination port.
Sourcepub fn set_length(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
pub fn set_length(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
Set the length field.
Sourcepub fn set_checksum(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
pub fn set_checksum(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
Set the checksum.
Sourcepub fn header_len(&self, _buf: &[u8]) -> usize
pub fn header_len(&self, _buf: &[u8]) -> usize
Get the UDP header length (always 8 bytes).
Sourcepub fn field_names(&self) -> &'static [&'static str]
pub fn field_names(&self) -> &'static [&'static str]
Get field names for this layer.
Sourcepub fn get_field(
&self,
buf: &[u8],
name: &str,
) -> Option<Result<FieldValue, FieldError>>
pub fn get_field( &self, buf: &[u8], name: &str, ) -> Option<Result<FieldValue, FieldError>>
Get a field value by name.
Sourcepub fn set_field(
&self,
buf: &mut [u8],
name: &str,
value: FieldValue,
) -> Option<Result<(), FieldError>>
pub fn set_field( &self, buf: &mut [u8], name: &str, value: FieldValue, ) -> Option<Result<(), FieldError>>
Set a field value by name.
Trait Implementations§
Source§impl Layer for UdpLayer
impl Layer for UdpLayer
Source§fn header_len(&self, data: &[u8]) -> usize
fn header_len(&self, data: &[u8]) -> usize
Get the header length for this layer
Source§fn answers(&self, data: &[u8], other: &Self, other_data: &[u8]) -> bool
fn answers(&self, data: &[u8], other: &Self, other_data: &[u8]) -> bool
Check if this packet answers another packet.
Source§fn extract_padding<'a>(&self, data: &'a [u8]) -> (&'a [u8], &'a [u8])
fn extract_padding<'a>(&self, data: &'a [u8]) -> (&'a [u8], &'a [u8])
Extract padding from the packet.
Source§fn field_names(&self) -> &'static [&'static str]
fn field_names(&self) -> &'static [&'static str]
Get the list of field names for this layer
Auto Trait Implementations§
impl Freeze for UdpLayer
impl RefUnwindSafe for UdpLayer
impl Send for UdpLayer
impl Sync for UdpLayer
impl Unpin for UdpLayer
impl UnsafeUnpin for UdpLayer
impl UnwindSafe for UdpLayer
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