Skip to content

Commit

Permalink
netreg: add multiplexer for header building
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Mar 28, 2015
1 parent 70c1e4d commit 69c593b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sys/include/net/ng_netreg.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "kernel_types.h"
#include "net/ng_nettype.h"
#include "net/ng_pkt.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -126,6 +127,25 @@ int ng_netreg_num(ng_nettype_t type, uint32_t demux_ctx);
*/
ng_netreg_entry_t *ng_netreg_getnext(ng_netreg_entry_t *entry);

/**
* @brief Builds a header for sending and adds it to the packet buffer.
*
* @param[in] type Type of the header.
* @param[in] payload Payload for the packet.
* @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] dst Destination address for the header. Can be NULL if not
* known or required.
* @param[in] dst_len Length of @p dst. Can be 0 if not known or required.
*
* @return The header for the protocol on success.
* @return NULL on error.
*/
ng_pktsnip_t *ng_netreg_hdr_build(ng_nettype_t type, ng_pktsnip_t *payload,
uint8_t *src, uint8_t src_len,
uint8_t *dst, uint8_t dst_len);

#ifdef __cplusplus
}
#endif
Expand Down
27 changes: 27 additions & 0 deletions sys/net/crosslayer/ng_netreg/ng_netreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "utlist.h"
#include "net/ng_netreg.h"
#include "net/ng_nettype.h"
#include "net/ng_ipv6.h"

#define _INVALID_TYPE(type) (((type) < NG_NETTYPE_UNDEF) || ((type) >= NG_NETTYPE_NUMOF))

Expand Down Expand Up @@ -101,4 +102,30 @@ ng_netreg_entry_t *ng_netreg_getnext(ng_netreg_entry_t *entry)
return entry;
}

ng_pktsnip_t *ng_netreg_hdr_build(ng_nettype_t type, ng_pktsnip_t *payload,
uint8_t *src, uint8_t src_len,
uint8_t *dst, uint8_t dst_len)
{
switch (type) {
#ifdef MODULE_NG_IPV6

case NG_NETTYPE_IPV6:
return ng_ipv6_hdr_build(payload, src, src_len, dst, dst_len);
#endif
#ifdef MODULE_NG_TCP

case NG_NETTYPE_TCP:
return ng_tcp_hdr_build(payload, src, src_len, dst, dst_len);
#endif
#ifdef MODULE_NG_UDP

case NG_NETTYPE_UDP:
return ng_udp_hdr_build(payload, src, src_len, dst, dst_len);
#endif

default:
return NULL;
}
}

/** @} */

0 comments on commit 69c593b

Please sign in to comment.