mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
examples/gnrc_networking: use netutils_get_ipv6()
This commit is contained in:
parent
3081eeb556
commit
0bb15273ec
@ -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
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user