Skip to content
Permalink
Browse files

net: pkt: Add net_pkt_read_le16() helper

We had a big endian helper but little endian one was missing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed Apr 3, 2019
1 parent ddac835 commit 19a09bf553efdad941fb8408b819d1bcb964b471
Showing with 26 additions and 0 deletions.
  1. +14 −0 include/net/net_pkt.h
  2. +12 −0 subsys/net/ip/net_pkt.c
@@ -1580,6 +1580,20 @@ static inline int net_pkt_read_u8(struct net_pkt *pkt, u8_t *data)
*/
int net_pkt_read_be16(struct net_pkt *pkt, u16_t *data);

/**
* @brief Read u16_t little endian data from a net_pkt
*
* @details net_pkt's cursor should be properly initialized and,
* if needed, positioned using net_pkt_skip.
* Cursor position will be updated after the operation.
*
* @param pkt The network packet from where to read
* @param data The destination u16_t where to copy the data
*
* @return 0 on success, negative errno code otherwise.
*/
int net_pkt_read_le16(struct net_pkt *pkt, u16_t *data);

/**
* @brief Read u32_t big endian data from a net_pkt
*
@@ -1584,6 +1584,18 @@ int net_pkt_read_be16(struct net_pkt *pkt, u16_t *data)
return ret;
}

int net_pkt_read_le16(struct net_pkt *pkt, u16_t *data)
{
u8_t d16[2];
int ret;

ret = net_pkt_read(pkt, d16, sizeof(u16_t));

*data = d16[1] << 8 | d16[0];

return ret;
}

int net_pkt_read_be32(struct net_pkt *pkt, u32_t *data)
{
u8_t d32[4];

0 comments on commit 19a09bf

Please sign in to comment.
You can’t perform that action at this time.