diff --git a/examples/gnrc_networking/udp.c b/examples/gnrc_networking/udp.c index c22a26a202..e8a559846e 100644 --- a/examples/gnrc_networking/udp.c +++ b/examples/gnrc_networking/udp.c @@ -39,19 +39,19 @@ 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; + gnrc_netif_t *netif = NULL; + char *iface; uint16_t port; ipv6_addr_t addr; - /* get interface, if available */ iface = ipv6_addr_split_iface(addr_str); - if ((iface < 0) && (gnrc_netif_numof() == 1)) { + if ((!iface) && (gnrc_netif_numof() == 1)) { netif = gnrc_netif_iter(NULL); } - else { - netif = gnrc_netif_get_by_pid(iface); + else if (iface) { + netif = gnrc_netif_get_by_pid(atoi(iface)); } + /* parse destination address */ if (ipv6_addr_from_str(&addr, addr_str) == NULL) { puts("Error: unable to parse destination address");