mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +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
|
USEMODULE += gnrc_pktdump
|
||||||
# Additional networking modules that can be dropped if not needed
|
# Additional networking modules that can be dropped if not needed
|
||||||
USEMODULE += gnrc_icmpv6_echo
|
USEMODULE += gnrc_icmpv6_echo
|
||||||
|
USEMODULE += netutils
|
||||||
# Add also the shell, some shell commands
|
# Add also the shell, some shell commands
|
||||||
USEMODULE += shell
|
USEMODULE += shell
|
||||||
USEMODULE += shell_commands
|
USEMODULE += shell_commands
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "net/gnrc/netif/hdr.h"
|
#include "net/gnrc/netif/hdr.h"
|
||||||
#include "net/gnrc/udp.h"
|
#include "net/gnrc/udp.h"
|
||||||
#include "net/gnrc/pktdump.h"
|
#include "net/gnrc/pktdump.h"
|
||||||
|
#include "net/utils.h"
|
||||||
#include "timex.h"
|
#include "timex.h"
|
||||||
#include "utlist.h"
|
#include "utlist.h"
|
||||||
#if IS_USED(MODULE_ZTIMER_MSEC)
|
#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,
|
static void send(char *addr_str, char *port_str, char *data, unsigned int num,
|
||||||
unsigned int delay)
|
unsigned int delay)
|
||||||
{
|
{
|
||||||
gnrc_netif_t *netif = NULL;
|
netif_t *netif;
|
||||||
char *iface;
|
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
ipv6_addr_t addr;
|
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 */
|
/* 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");
|
puts("Error: unable to parse destination address");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -97,7 +89,8 @@ static void send(char *addr_str, char *port_str, char *data, unsigned int num,
|
|||||||
if (netif != NULL) {
|
if (netif != NULL) {
|
||||||
gnrc_pktsnip_t *netif_hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
|
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);
|
ip = gnrc_pkt_prepend(ip, netif_hdr);
|
||||||
}
|
}
|
||||||
/* send packet */
|
/* send packet */
|
||||||
|
Loading…
Reference in New Issue
Block a user