Skip to content

Commit

Permalink
Merge pull request #10071 from chrysn-pull-requests/deduplicate-ipv6-…
Browse files Browse the repository at this point in the history
…address-extraction

gnrc: Use existing utility function to extract IPv6 header
  • Loading branch information
miri64 authored Sep 28, 2018
2 parents b4664a5 + f07308b commit a6cf9db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions sys/include/net/gnrc/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
11 changes: 7 additions & 4 deletions sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
9 changes: 4 additions & 5 deletions sys/net/gnrc/sock/gnrc_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a6cf9db

Please sign in to comment.