From a2b9defc8ba96e1d4cf92a1f2b6c594764b74ad9 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Fri, 1 Apr 2016 21:47:06 +0200 Subject: [PATCH] gnrc ipv6: convenient function to get the header --- sys/include/net/gnrc/ipv6.h | 13 +++++++++++++ sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/sys/include/net/gnrc/ipv6.h b/sys/include/net/gnrc/ipv6.h index 03b89cb8aa..e736808e37 100644 --- a/sys/include/net/gnrc/ipv6.h +++ b/sys/include/net/gnrc/ipv6.h @@ -137,6 +137,19 @@ kernel_pid_t gnrc_ipv6_init(void); */ void gnrc_ipv6_demux(kernel_pid_t iface, gnrc_pktsnip_t *current, gnrc_pktsnip_t *pkt, uint8_t nh); +/** + * @brief Get the IPv6 header from a given list of @ref gnrc_pktsnip_t + * + * This function may be used with e.g. a pointer to a (full) UDP datagram. + * + * @param[in] pkt The pointer to the first @ref gnrc_pktsnip_t of the + * packet. + * + * @return A pointer to the @ref ipv6_hdr_t of the packet. + * @return NULL if the packet does not contain an IPv6 header. + */ +ipv6_hdr_t *gnrc_ipv6_get_header(gnrc_pktsnip_t *pkt); + #ifdef __cplusplus } #endif diff --git a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c index d608dcd3e8..8dcef2dbab 100644 --- a/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c +++ b/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c @@ -208,6 +208,17 @@ void gnrc_ipv6_demux(kernel_pid_t iface, gnrc_pktsnip_t *current, gnrc_pktsnip_t gnrc_pktbuf_release(pkt); } +ipv6_hdr_t *gnrc_ipv6_get_header(gnrc_pktsnip_t *pkt) +{ + ipv6_hdr_t *hdr = NULL; + gnrc_pktsnip_t *tmp = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_IPV6); + if ((tmp) && ipv6_hdr_is(tmp->data)) { + hdr = ((ipv6_hdr_t*) tmp->data); + } + + return hdr; +} + /* internal functions */ static void *_event_loop(void *args) {