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
Source§impl LayerDispatch for UdpLayer
impl LayerDispatch for UdpLayer
Source§fn dispatch_kind(&self) -> LayerKind
fn dispatch_kind(&self) -> LayerKind
Get the kind of this layer.
Source§fn dispatch_index(&self) -> &LayerIndex
fn dispatch_index(&self) -> &LayerIndex
Get the layer index (start/end offsets).
Source§fn dispatch_summary(&self, buf: &[u8]) -> String
fn dispatch_summary(&self, buf: &[u8]) -> String
Get a human-readable summary.
Source§fn dispatch_header_len(&self, buf: &[u8]) -> usize
fn dispatch_header_len(&self, buf: &[u8]) -> usize
Get the header length in bytes.
Source§fn dispatch_field_names(&self) -> &'static [&'static str]
fn dispatch_field_names(&self) -> &'static [&'static str]
Get field names for this layer type.
Source§fn dispatch_get_field(
&self,
buf: &[u8],
name: &str,
) -> Option<Result<FieldValue, FieldError>>
fn dispatch_get_field( &self, buf: &[u8], name: &str, ) -> Option<Result<FieldValue, FieldError>>
Get a field value by name.
Source§fn dispatch_set_field(
&self,
buf: &mut [u8],
name: &str,
value: FieldValue,
) -> Option<Result<(), FieldError>>
fn dispatch_set_field( &self, buf: &mut [u8], name: &str, value: FieldValue, ) -> Option<Result<(), FieldError>>
Set a field value by name.
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more