diff --git a/examples/gnrc_networking/udp.c b/examples/gnrc_networking/udp.c index ada54e569e..c22a26a202 100644 --- a/examples/gnrc_networking/udp.c +++ b/examples/gnrc_networking/udp.c @@ -39,6 +39,7 @@ static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX static void send(char *addr_str, char *port_str, char *data, unsigned int num, unsigned int delay) { + gnrc_netif_t *netif; int iface; uint16_t port; ipv6_addr_t addr; @@ -46,7 +47,10 @@ static void send(char *addr_str, char *port_str, char *data, unsigned int num, /* get interface, if available */ iface = ipv6_addr_split_iface(addr_str); if ((iface < 0) && (gnrc_netif_numof() == 1)) { - iface = gnrc_netif_iter(NULL)->pid; + netif = gnrc_netif_iter(NULL); + } + else { + netif = gnrc_netif_get_by_pid(iface); } /* parse destination address */ if (ipv6_addr_from_str(&addr, addr_str) == NULL) { @@ -86,11 +90,11 @@ static void send(char *addr_str, char *port_str, char *data, unsigned int num, return; } /* add netif header, if interface was given */ - if (iface > 0) { - gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, NULL, 0); + if (netif != NULL) { + gnrc_pktsnip_t *netif_hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0); - ((gnrc_netif_hdr_t *)netif->data)->if_pid = (kernel_pid_t)iface; - LL_PREPEND(ip, netif); + gnrc_netif_hdr_set_netif(netif_hdr->data, netif); + LL_PREPEND(ip, netif_hdr); } /* send packet */ if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) { diff --git a/examples/gnrc_networking_mac/udp.c b/examples/gnrc_networking_mac/udp.c index cb6d16835d..710ecfc5f9 100644 --- a/examples/gnrc_networking_mac/udp.c +++ b/examples/gnrc_networking_mac/udp.c @@ -38,6 +38,7 @@ static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX static void send(char *addr_str, char *port_str, char *data, unsigned int num, unsigned int delay) { + gnrc_netif_t *netif; int iface; uint16_t port; ipv6_addr_t addr; @@ -45,7 +46,10 @@ static void send(char *addr_str, char *port_str, char *data, unsigned int num, /* get interface, if available */ iface = ipv6_addr_split_iface(addr_str); if ((iface < 0) && (gnrc_netif_numof() == 1)) { - iface = gnrc_netif_iter(NULL)->pid; + netif = gnrc_netif_iter(NULL); + } + else { + netif = gnrc_netif_get_by_pid(iface); } /* parse destination address */ if (ipv6_addr_from_str(&addr, addr_str) == NULL) { @@ -85,11 +89,11 @@ static void send(char *addr_str, char *port_str, char *data, unsigned int num, return; } /* add netif header, if interface was given */ - if (iface > 0) { - gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, NULL, 0); + if (netif != NULL) { + gnrc_pktsnip_t *netif_hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0); - ((gnrc_netif_hdr_t *)netif->data)->if_pid = (kernel_pid_t)iface; - LL_PREPEND(ip, netif); + gnrc_netif_hdr_set_netif(netif_hdr->data, netif); + LL_PREPEND(ip, netif_hdr); } /* send packet */ if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) { diff --git a/tests/gnrc_ipv6_fwd_w_sub/main.c b/tests/gnrc_ipv6_fwd_w_sub/main.c index 12583fc9ba..36ccd81fb9 100644 --- a/tests/gnrc_ipv6_fwd_w_sub/main.c +++ b/tests/gnrc_ipv6_fwd_w_sub/main.c @@ -131,12 +131,10 @@ static gnrc_pktsnip_t *_build_recvd_pkt(void) { gnrc_pktsnip_t *netif; gnrc_pktsnip_t *pkt; - gnrc_netif_hdr_t *netif_hdr; netif = gnrc_netif_hdr_build(NULL, 0, NULL, 0); assert(netif); - netif_hdr = netif->data; - netif_hdr->if_pid = _mock_netif->pid; + gnrc_netif_hdr_set_netif(netif->data, _mock_netif); pkt = gnrc_pktbuf_add(netif, _l2_payload, sizeof(_l2_payload), GNRC_NETTYPE_IPV6); assert(pkt); diff --git a/tests/gnrc_sixlowpan/main.c b/tests/gnrc_sixlowpan/main.c index 6a327333a8..4ab6e29a85 100644 --- a/tests/gnrc_sixlowpan/main.c +++ b/tests/gnrc_sixlowpan/main.c @@ -141,7 +141,7 @@ static void _send_packet(void) gnrc_netif_hdr_init(&(netif_hdr.netif_hdr), 8, 8); - netif_hdr.netif_hdr.if_pid = netif->pid; + gnrc_netif_hdr_set_netif(&netif_hdr.netif_hdr, netif); uint8_t data1[] = { /* 6LoWPAN Header */ diff --git a/tests/gnrc_udp/udp.c b/tests/gnrc_udp/udp.c index 2cad2a6497..1689ddbe87 100644 --- a/tests/gnrc_udp/udp.c +++ b/tests/gnrc_udp/udp.c @@ -82,6 +82,7 @@ static void *_eventloop(void *arg) static void send(char *addr_str, char *port_str, char *data_len_str, unsigned int num, unsigned int delay) { + gnrc_netif_t *netif; int iface; char *conversion_end; uint16_t port; @@ -91,7 +92,10 @@ static void send(char *addr_str, char *port_str, char *data_len_str, unsigned in /* get interface, if available */ iface = ipv6_addr_split_iface(addr_str); if ((iface < 0) && (gnrc_netif_numof() == 1)) { - iface = gnrc_netif_iter(NULL)->pid; + netif = gnrc_netif_iter(NULL); + } + else { + netif = gnrc_netif_get_by_pid(iface); } /* parse destination address */ if (ipv6_addr_from_str(&addr, addr_str) == NULL) { @@ -135,16 +139,16 @@ static void send(char *addr_str, char *port_str, char *data_len_str, unsigned in return; } /* add netif header, if interface was given */ - if (iface > 0) { - gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, NULL, 0); + if (netif != NULL) { + gnrc_pktsnip_t *netif_hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0); if(netif == NULL) { puts("Error: unable to allocate NETIF header"); gnrc_pktbuf_release(ip); return; } - ((gnrc_netif_hdr_t *)netif->data)->if_pid = (kernel_pid_t)iface; - LL_PREPEND(ip, netif); + gnrc_netif_hdr_set_netif(netif_hdr->data, netif); + LL_PREPEND(ip, netif_hdr); } /* send packet */ if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) {