Skip to content

Commit

Permalink
gnrc_netif_hdr: provide wrappers for gnrc_netif_ipv6_iid_from_addr()
Browse files Browse the repository at this point in the history
For convenience ;-).
  • Loading branch information
miri64 committed Nov 30, 2018
1 parent 3eabe3e commit aafb936
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions sys/include/net/gnrc/netif/hdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string.h>
#include <stdint.h>

#include "net/gnrc/netif.h"
#include "net/gnrc/pkt.h"
#include "net/gnrc/pktbuf.h"

Expand Down Expand Up @@ -196,6 +197,58 @@ static inline void gnrc_netif_hdr_set_dst_addr(gnrc_netif_hdr_t *hdr, uint8_t *a
memcpy(((uint8_t *)(hdr + 1)) + hdr->src_l2addr_len, addr, addr_len);
}

/**
* @brief Converts the source address of a given @ref net_gnrc_netif_hdr to
* an IPv6 IID
*
* @note @p netif is intentionally required to be provided so that the caller
* needs to retrieve it from gnrc_netif_hdr_t::if_pid of @p hdr only
* once instead of this function retrieving it at every call.
*
* @pre `netif->pid == hdr->if_pid`
*
* @param[in] netif A network interface. gnrc_netif_t::pid must be equal to
* gnrc_netif_hdr_t::if_pid of @p hdr.
* @param[in] hdr Header to convert source address from.
* @param[out] iid The IID based on gnrc_netif_t::device_type.
*
* @return same as @ref gnrc_netif_ipv6_iid_from_addr().
*/
static inline int gnrc_netif_hdr_ipv6_iid_from_src(const gnrc_netif_t *netif,
const gnrc_netif_hdr_t *hdr,
eui64_t *iid)
{
return gnrc_netif_ipv6_iid_from_addr(
netif,gnrc_netif_hdr_get_src_addr(hdr), hdr->src_l2addr_len, iid
);
}

/**
* @brief Converts the destination address of a given @ref net_gnrc_netif_hdr
* to an IPv6 IID
*
* @note @p netif is intentionally required to be provided so that the caller
* needs to retrieve it from gnrc_netif_hdr_t::if_pid of @p hdr only
* once instead of this function retrieving it at every call.
*
* @pre `netif->pid == hdr->if_pid`
*
* @param[in] netif A network interface. gnrc_netif_t::pid must be equal to
* gnrc_netif_hdr_t::if_pid of @p hdr.
* @param[in] hdr Header to convert destination address from.
* @param[out] iid The IID based on gnrc_netif_t::device_type.
*
* @return same as @ref gnrc_netif_ipv6_iid_from_addr().
*/
static inline int gnrc_netif_hdr_ipv6_iid_from_dst(const gnrc_netif_t *netif,
const gnrc_netif_hdr_t *hdr,
eui64_t *iid)
{
return gnrc_netif_ipv6_iid_from_addr(
netif,gnrc_netif_hdr_get_dst_addr(hdr), hdr->dst_l2addr_len, iid
);
}

/**
* @brief Builds a generic network interface header for sending and
* adds it to the packet buffer.
Expand Down

0 comments on commit aafb936

Please sign in to comment.