riot_sys

Struct gnrc_pktsnip

Source
#[repr(C)]
pub struct gnrc_pktsnip { pub next: *mut gnrc_pktsnip, pub data: *mut c_void, pub size: size_t, pub type_: gnrc_nettype_t, pub users: u8, }
Expand description

@brief Type to represent parts (either headers or payload) of a packet, called snips. @details The idea behind the packet snips is that they either can represent protocol-specific headers or payload. A packet can be comprised of multiple pktsnip_t elements.

     Example:

                                                             buffer
         +---------------------------+                      +------+
         | size = 14                 | data +-------------->|      |
         | type = NETTYPE_ETHERNET   |------+               +------+
         +---------------------------+                      .      .
               | next                                       .      .
               v                                            +------+
         +---------------------------+         +----------->|      |
         | size = 40                 | data    |            |      |
         | type = NETTYPE_IPV6       |---------+            +------+
         +---------------------------+                      .      .
               | next                                       .      .
               v                                            +------+
         +---------------------------+            +-------->|      |
         | size = 8                  | data       |         +------+
         | type = NETTYPE_UDP        |------------+         .      .
         +---------------------------+                      .      .
               | next                                       +------+
               v                                     +----->|      |
         +---------------------------+               |      |      |
         | size = 59                 | data          |      .      .
         | type = NETTYPE_UNDEF      |---------------+      .      .
         +---------------------------+                      .      .

To keep data duplication as low as possible the order of the snips in a packet will be reversed depending on if you send the packet or if you received it. For sending the order is from (in the network stack) lowest protocol snip to the highest, for receiving the order is from highest snip to the lowest. This way, if a layer needs to duplicate the packet a tree is created rather than a duplication of the whole package.

A very extreme example for this (we only expect one or two duplications at maximum per package) can be seen here:

 Sending                          Receiving
 =======                          =========

 * Payload                        * L2 header
 ^                                ^
 |                                |
 |\                               |\
 | * L4 header 1                  | * L2.5 header 1
 | * L3 header 1                  | * L3 header 1
 | * netif header 1               | * L4 header 1
 * L4 header 2                    | * Payload 1
 ^                                * L3 header 2
 |                                ^
 |\                               |
 | * L3 header 2                  |\
 | * L2 header 2                  | * L4 header 2
 * L2 header 3                    | * Payload 2
 |\                               * Payload 3
 | * L2 header 3
 * L2 header 4

The first three fields (next, data, size) match iolist_t (named iol_next, iol_base and iol_len there). That means that any pktsnip can be casted to iolist_t for direct passing to e.g., netdev send() functions.

@note This type has no initializer on purpose. Please use @ref net_gnrc_pktbuf as factory.

Fields§

§next: *mut gnrc_pktsnip

< next snip in the packet

§data: *mut c_void

< pointer to the data of the snip

§size: size_t

< the length of the snip in byte

§type_: gnrc_nettype_t

< protocol of the packet snip

§users: u8

@brief Counter of threads currently having control over this packet.

@internal

Trait Implementations§

Source§

impl Clone for gnrc_pktsnip

Source§

fn clone(&self) -> gnrc_pktsnip

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for gnrc_pktsnip

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for gnrc_pktsnip

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for gnrc_pktsnip

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 16 bytes