pub struct TftpLayer {
pub index: LayerIndex,
}Expand description
A zero-copy view into a TFTP layer within a packet buffer.
Fields§
§index: LayerIndexImplementations§
Source§impl TftpLayer
impl TftpLayer
pub fn new(index: LayerIndex) -> Self
pub fn at_start(len: usize) -> Self
Sourcepub fn opcode(&self, buf: &[u8]) -> Result<u16, FieldError>
pub fn opcode(&self, buf: &[u8]) -> Result<u16, FieldError>
Returns the 2-byte opcode.
§Errors
Returns FieldError::BufferTooShort if fewer than 2 bytes are available.
Sourcepub fn op_name(&self, buf: &[u8]) -> Result<String, FieldError>
pub fn op_name(&self, buf: &[u8]) -> Result<String, FieldError>
Returns the opcode name.
§Errors
Returns FieldError::BufferTooShort if fewer than 2 bytes are available.
Sourcepub fn filename(&self, buf: &[u8]) -> Result<String, FieldError>
pub fn filename(&self, buf: &[u8]) -> Result<String, FieldError>
Returns the filename from a RRQ or WRQ packet.
The filename is a null-terminated string starting at byte 2.
§Errors
Returns FieldError::InvalidValue if the opcode is not RRQ/WRQ or the
filename bytes are not valid UTF-8, or FieldError::BufferTooShort if
the buffer is too small.
Sourcepub fn mode(&self, buf: &[u8]) -> Result<String, FieldError>
pub fn mode(&self, buf: &[u8]) -> Result<String, FieldError>
Returns the mode string from a RRQ or WRQ packet (“netascii”, “octet”, “mail”).
§Errors
Returns FieldError::InvalidValue if the opcode is not RRQ/WRQ or the
mode bytes are not valid UTF-8.
Sourcepub fn block_num(&self, buf: &[u8]) -> Result<u16, FieldError>
pub fn block_num(&self, buf: &[u8]) -> Result<u16, FieldError>
Returns the block number from a DATA or ACK packet.
§Errors
Returns FieldError::InvalidValue if the opcode is not DATA/ACK, or
FieldError::BufferTooShort if fewer than 4 bytes are available.
Sourcepub fn data(&self, buf: &[u8]) -> Result<Vec<u8>, FieldError>
pub fn data(&self, buf: &[u8]) -> Result<Vec<u8>, FieldError>
Returns the data payload from a DATA packet.
§Errors
Returns FieldError::InvalidValue if the opcode is not DATA, or
FieldError::BufferTooShort if fewer than 4 bytes are available.
Sourcepub fn error_code(&self, buf: &[u8]) -> Result<u16, FieldError>
pub fn error_code(&self, buf: &[u8]) -> Result<u16, FieldError>
Returns the error code from an ERROR packet.
§Errors
Returns FieldError::InvalidValue if the opcode is not ERROR, or
FieldError::BufferTooShort if fewer than 4 bytes are available.
Sourcepub fn error_msg(&self, buf: &[u8]) -> Result<String, FieldError>
pub fn error_msg(&self, buf: &[u8]) -> Result<String, FieldError>
Returns the error message from an ERROR packet.
§Errors
Returns FieldError::InvalidValue if the opcode is not ERROR or the
message is not valid UTF-8, or FieldError::BufferTooShort if fewer
than 5 bytes are available.
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 by name.
Trait Implementations§
Source§impl Layer for TftpLayer
impl Layer for TftpLayer
Source§fn header_len(&self, buf: &[u8]) -> usize
fn header_len(&self, buf: &[u8]) -> usize
Source§fn field_names(&self) -> &'static [&'static str]
fn field_names(&self) -> &'static [&'static str]
Source§impl LayerDispatch for TftpLayer
impl LayerDispatch for TftpLayer
Source§fn dispatch_kind(&self) -> LayerKind
fn dispatch_kind(&self) -> LayerKind
Source§fn dispatch_index(&self) -> &LayerIndex
fn dispatch_index(&self) -> &LayerIndex
Source§fn dispatch_summary(&self, buf: &[u8]) -> String
fn dispatch_summary(&self, buf: &[u8]) -> String
Source§fn dispatch_header_len(&self, buf: &[u8]) -> usize
fn dispatch_header_len(&self, buf: &[u8]) -> usize
Source§fn dispatch_field_names(&self) -> &'static [&'static str]
fn dispatch_field_names(&self) -> &'static [&'static str]
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>>
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>>
Auto Trait Implementations§
impl Freeze for TftpLayer
impl RefUnwindSafe for TftpLayer
impl Send for TftpLayer
impl Sync for TftpLayer
impl Unpin for TftpLayer
impl UnsafeUnpin for TftpLayer
impl UnwindSafe for TftpLayer
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
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>
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>
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