Skip to content
Snippets Groups Projects
Commit f07308b0 authored by chrysn's avatar chrysn
Browse files

gnrc: Extend gnrc_ipv6_get_header checks, use in sock recv

gnrc_sock_recv used to duplicate functionality of gnrc_ipv6_get_header,
but additionally checked whether the IPv6 snip is large enough.

All checks are now included in gnrc_ipv6_get_header, but as most of them
stem from programming / user errors, they were moved into asserts; this
constitutes an API change.
parent b4664a5b
No related branches found
No related tags found
No related merge requests found
......@@ -158,6 +158,8 @@ void gnrc_ipv6_demux(gnrc_netif_t *netif, gnrc_pktsnip_t *current,
*
* This function may be used with e.g. a pointer to a (full) UDP datagram.
*
* @pre Any @ref GNRC_NETTYPE_IPV6 snip in pkt is contains a full IPv6 header.
*
* @param[in] pkt The pointer to the first @ref gnrc_pktsnip_t of the
* packet.
*
......
......@@ -195,13 +195,16 @@ void gnrc_ipv6_demux(gnrc_netif_t *netif, gnrc_pktsnip_t *current,
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 != NULL) && (tmp->data != NULL) && ipv6_hdr_is(tmp->data)) {
hdr = ((ipv6_hdr_t*) tmp->data);
if (tmp == NULL) {
return NULL;
}
return hdr;
assert(tmp->data != NULL);
assert(tmp->size >= sizeof(ipv6_hdr_t));
assert(ipv6_hdr_is(tmp->data));
return ((ipv6_hdr_t*) tmp->data);
}
/* internal functions */
......
......@@ -17,6 +17,7 @@
#include "net/af.h"
#include "net/ipv6/hdr.h"
#include "net/gnrc/ipv6.h"
#include "net/gnrc/ipv6/hdr.h"
#include "net/gnrc/netreg.h"
#include "net/udp.h"
......@@ -53,7 +54,7 @@ void gnrc_sock_create(gnrc_sock_reg_t *reg, gnrc_nettype_t type, uint32_t demux_
ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt_out,
uint32_t timeout, sock_ip_ep_t *remote)
{
gnrc_pktsnip_t *pkt, *ip, *netif;
gnrc_pktsnip_t *pkt, *netif;
msg_t msg;
if (reg->mbox.cib.mask != (SOCK_MBOX_SIZE - 1)) {
......@@ -95,10 +96,8 @@ ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt_out,
}
/* TODO: discern NETTYPE from remote->family (set in caller), when IPv4
* was implemented */
ipv6_hdr_t *ipv6_hdr;
ip = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_IPV6);
assert((ip != NULL) && (ip->size >= 40));
ipv6_hdr = ip->data;
ipv6_hdr_t *ipv6_hdr = gnrc_ipv6_get_header(pkt);
assert(ipv6_hdr != NULL);
memcpy(&remote->addr, &ipv6_hdr->src, sizeof(ipv6_addr_t));
remote->family = AF_INET6;
netif = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_NETIF);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment