1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

examples/gnrc_minimal: use netifs_print_ipv6()

This commit is contained in:
Marian Buschsieweke 2022-06-02 12:38:33 +02:00
parent bfb8a55764
commit b564f95757
No known key found for this signature in database
GPG Key ID: CB8E3238CE715A94

View File

@ -24,29 +24,17 @@
#include "net/ipv6/addr.h" #include "net/ipv6/addr.h"
#include "net/gnrc.h" #include "net/gnrc.h"
#include "net/gnrc/netif.h" #include "net/gnrc/netif.h"
#include "net/netif.h"
int main(void) int main(void)
{ {
puts("RIOT network stack example application"); puts("RIOT network stack example application");
/* get interfaces and print their addresses */ /* print all IPv6 addresses */
gnrc_netif_t *netif = NULL; printf("{\"IPv6 addresses\": [\"");
while ((netif = gnrc_netif_iter(netif))) { netifs_print_ipv6("\", \"");
ipv6_addr_t ipv6_addrs[CONFIG_GNRC_NETIF_IPV6_ADDRS_NUMOF]; puts("\"]}");
int res = gnrc_netapi_get(netif->pid, NETOPT_IPV6_ADDR, 0, ipv6_addrs,
sizeof(ipv6_addrs));
if (res < 0) {
continue;
}
for (unsigned i = 0; i < (unsigned)(res / sizeof(ipv6_addr_t)); i++) {
char ipv6_addr[IPV6_ADDR_MAX_STR_LEN];
ipv6_addr_to_str(ipv6_addr, &ipv6_addrs[i], IPV6_ADDR_MAX_STR_LEN);
printf("My address is %s\n", ipv6_addr);
}
}
/* main thread exits */ /* main thread exits */
return 0; return 0;