diff --git a/sys/net/gnrc/sock/gnrc_sock.c b/sys/net/gnrc/sock/gnrc_sock.c index 3fb8a8dab2..60b7bd5948 100644 --- a/sys/net/gnrc/sock/gnrc_sock.c +++ b/sys/net/gnrc/sock/gnrc_sock.c @@ -224,6 +224,25 @@ ssize_t gnrc_sock_recv(gnrc_sock_reg_t *reg, gnrc_pktsnip_t **pkt_out, return 0; } +/* find the last extension header, if present */ +static gnrc_pktsnip_t *_last_ext_hdr(gnrc_pktsnip_t *ipv6) +{ +#ifdef MODULE_GNRC_IPV6_EXT_OPT + if (ipv6->next == NULL || ipv6->next->type != GNRC_NETTYPE_IPV6_EXT) { + return NULL; + } + + while (ipv6->next && ipv6->next->type == GNRC_NETTYPE_IPV6_EXT) { + ipv6 = ipv6->next; + } + + return ipv6; +#else + (void)ipv6; + return NULL; +#endif +} + ssize_t gnrc_sock_send(gnrc_pktsnip_t *payload, sock_ip_ep_t *local, const sock_ip_ep_t *remote, uint8_t nh) { @@ -266,8 +285,15 @@ ssize_t gnrc_sock_send(gnrc_pktsnip_t *payload, sock_ip_ep_t *local, else { type = payload->type; } - hdr = pkt->data; - hdr->nh = nh; + + gnrc_pktsnip_t *ext = _last_ext_hdr(pkt); + if (ext) { + ipv6_ext_t *ext_hdr = ext->data; + ext_hdr->nh = nh; + } else { + hdr = pkt->data; + hdr->nh = nh; + } break; } #endif