2015-11-18 07:26:44 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "net/gnrc/netif/hdr.h"
|
|
|
|
|
2019-02-21 12:41:14 +01:00
|
|
|
gnrc_pktsnip_t *gnrc_netif_hdr_build(const uint8_t *src, uint8_t src_len,
|
|
|
|
const uint8_t *dst, uint8_t dst_len)
|
2015-11-18 07:26:44 +01:00
|
|
|
{
|
|
|
|
gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, NULL,
|
|
|
|
sizeof(gnrc_netif_hdr_t) + src_len + dst_len,
|
|
|
|
GNRC_NETTYPE_NETIF);
|
|
|
|
|
|
|
|
if (pkt == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gnrc_netif_hdr_init(pkt->data, src_len, dst_len);
|
|
|
|
|
|
|
|
if (src != NULL && src_len > 0) {
|
|
|
|
gnrc_netif_hdr_set_src_addr(pkt->data, src, src_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dst != NULL && dst_len > 0) {
|
|
|
|
gnrc_netif_hdr_set_dst_addr(pkt->data, dst, dst_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pkt;
|
|
|
|
}
|
|
|
|
|
2016-11-07 18:18:19 +01:00
|
|
|
uint8_t gnrc_netif_hdr_get_flag(gnrc_pktsnip_t* pkt)
|
|
|
|
{
|
|
|
|
assert(pkt != NULL);
|
2016-12-20 16:34:10 +01:00
|
|
|
|
2016-11-07 18:18:19 +01:00
|
|
|
pkt = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_NETIF);
|
2016-12-20 16:34:10 +01:00
|
|
|
if (pkt && pkt->data) {
|
|
|
|
gnrc_netif_hdr_t *netif_hdr = pkt->data;
|
|
|
|
return netif_hdr->flags;
|
2016-11-07 18:18:19 +01:00
|
|
|
}
|
|
|
|
return 0U;
|
|
|
|
}
|
|
|
|
|
|
|
|
int gnrc_netif_hdr_get_dstaddr(gnrc_pktsnip_t* pkt, uint8_t** pointer_to_addr)
|
|
|
|
{
|
|
|
|
assert(pkt != NULL);
|
2016-12-20 16:34:10 +01:00
|
|
|
|
2016-11-07 18:18:19 +01:00
|
|
|
pkt = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_NETIF);
|
2016-12-20 16:34:10 +01:00
|
|
|
if (pkt && pkt->data) {
|
|
|
|
gnrc_netif_hdr_t *netif_hdr = pkt->data;
|
|
|
|
if (netif_hdr->dst_l2addr_len > 0) {
|
2016-11-07 18:18:19 +01:00
|
|
|
*pointer_to_addr = gnrc_netif_hdr_get_dst_addr(netif_hdr);
|
2016-12-20 16:34:10 +01:00
|
|
|
return netif_hdr->dst_l2addr_len;
|
2016-11-07 18:18:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
int gnrc_netif_hdr_get_srcaddr(gnrc_pktsnip_t* pkt, uint8_t** pointer_to_addr)
|
|
|
|
{
|
|
|
|
assert(pkt != NULL);
|
2016-12-20 16:34:10 +01:00
|
|
|
|
2016-11-07 18:18:19 +01:00
|
|
|
pkt = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_NETIF);
|
2016-12-20 16:34:10 +01:00
|
|
|
if (pkt && pkt->data) {
|
|
|
|
gnrc_netif_hdr_t *netif_hdr = pkt->data;
|
|
|
|
if (netif_hdr->src_l2addr_len > 0) {
|
2016-11-07 18:18:19 +01:00
|
|
|
*pointer_to_addr = gnrc_netif_hdr_get_src_addr(netif_hdr);
|
2016-12-20 16:34:10 +01:00
|
|
|
return netif_hdr->src_l2addr_len;
|
2016-11-07 18:18:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2015-11-18 07:26:44 +01:00
|
|
|
/** @} */
|