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.