Skip to content

Commit

Permalink
examples/gnrc_networking: use netutils_get_ipv6()
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Jul 20, 2021
1 parent 3081eeb commit 0bb1527
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
1 change: 1 addition & 0 deletions examples/gnrc_networking/Makefile
Expand Up @@ -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
Expand Down
17 changes: 5 additions & 12 deletions examples/gnrc_networking/udp.c
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 0bb1527

Please sign in to comment.