diff --git a/examples/gnrc_networking/Makefile b/examples/gnrc_networking/Makefile index aa06541d76..a59b776599 100644 --- a/examples/gnrc_networking/Makefile +++ b/examples/gnrc_networking/Makefile @@ -23,6 +23,7 @@ USEMODULE += auto_init_gnrc_rpl USEMODULE += gnrc_pktdump # Additional networking modules that can be dropped if not needed USEMODULE += gnrc_icmpv6_echo +USEMODULE += netutils # Add also the shell, some shell commands USEMODULE += shell USEMODULE += shell_commands diff --git a/examples/gnrc_networking/udp.c b/examples/gnrc_networking/udp.c index f7ae44df6d..ad222e5135 100644 --- a/examples/gnrc_networking/udp.c +++ b/examples/gnrc_networking/udp.c @@ -28,6 +28,7 @@ #include "net/gnrc/netif/hdr.h" #include "net/gnrc/udp.h" #include "net/gnrc/pktdump.h" +#include "net/utils.h" #include "timex.h" #include "utlist.h" #if IS_USED(MODULE_ZTIMER_MSEC) @@ -43,21 +44,12 @@ static gnrc_netreg_entry_t server = static void send(char *addr_str, char *port_str, char *data, unsigned int num, unsigned int delay) { - gnrc_netif_t *netif = NULL; - char *iface; + netif_t *netif; uint16_t port; ipv6_addr_t addr; - iface = ipv6_addr_split_iface(addr_str); - if ((!iface) && (gnrc_netif_numof() == 1)) { - netif = gnrc_netif_iter(NULL); - } - else if (iface) { - netif = gnrc_netif_get_by_pid(atoi(iface)); - } - /* parse destination address */ - if (ipv6_addr_from_str(&addr, addr_str) == NULL) { + if (netutils_get_ipv6(&addr, &netif, addr_str) < 0) { puts("Error: unable to parse destination address"); return; } @@ -97,7 +89,8 @@ static void send(char *addr_str, char *port_str, char *data, unsigned int num, if (netif != NULL) { gnrc_pktsnip_t *netif_hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0); - gnrc_netif_hdr_set_netif(netif_hdr->data, netif); + gnrc_netif_hdr_set_netif(netif_hdr->data, + container_of(netif, gnrc_netif_t, netif)); ip = gnrc_pkt_prepend(ip, netif_hdr); } /* send packet */