-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
netif: add convinience function for header building
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
#include <stdint.h> | ||
|
||
#include "kernel.h" | ||
#include "net/ng_pkt.h" | ||
#include "net/ng_pktbuf.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
@@ -134,6 +136,46 @@ static inline void ng_netif_hdr_set_dst_addr(ng_netif_hdr_t *hdr, uint8_t *addr, | |
memcpy(((uint8_t *)(hdr + 1)) + hdr->src_l2addr_len, addr, addr_len); | ||
} | ||
|
||
/** | ||
* @brief Builds a generic network interface header for sending and | ||
* adds it to the packet buffer. | ||
* | ||
* @author Martine Lenders <[email protected]> | ||
* | ||
* @param[in] src Source address for the header. Can be NULL if not | ||
* known or required. | ||
* @param[in] src_len Length of @p src. Can be 0 if not known or required. | ||
* @param[in] dest Destination address for the header. Can be NULL if not | ||
* known or required. | ||
* @param[in] dest_len Length of @p dest. Can be 0 if not known or required. | ||
* | ||
* @return The generic network layer header on success. | ||
* @return NULL on error. | ||
*/ | ||
static inline ng_pktsnip_t *ng_netif_hdr_build(uint8_t *src, uint8_t src_len, | ||
uint8_t *dest, uint8_t dest_len) | ||
{ | ||
ng_pktsnip_t *pkt = ng_pktbuf_add(NULL, NULL, | ||
sizeof(ng_netif_hdr_t) + src_len + dest_len, | ||
NG_NETTYPE_UNDEF); | ||
|
||
if (pkt == NULL) { | ||
return NULL; | ||
} | ||
|
||
ng_netif_hdr_init(pkt->data, src_len, dest_len); | ||
|
||
if (src != NULL && src_len > 0) { | ||
ng_netif_hdr_set_src_addr(pkt->data, src, src_len); | ||
} | ||
|
||
if (dest != NULL && dest_len > 0) { | ||
ng_netif_hdr_set_dst_addr(pkt->data, dest, dest_len); | ||
} | ||
|
||
return pkt; | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|