mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
feat(esp_netif): add an API to get all preferred ip6 addresses
This commit is contained in:
@@ -2203,6 +2203,30 @@ int esp_netif_get_all_ip6(esp_netif_t *esp_netif, esp_ip6_addr_t if_ip6[])
|
||||
}
|
||||
return addr_count;
|
||||
}
|
||||
|
||||
int esp_netif_get_all_preferred_ip6(esp_netif_t *esp_netif, esp_ip6_addr_t if_ip6[])
|
||||
{
|
||||
ESP_LOGV(TAG, "%s esp-netif:%p", __func__, esp_netif);
|
||||
|
||||
if (esp_netif == NULL || if_ip6 == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int addr_count = 0;
|
||||
struct netif *p_netif = esp_netif->lwip_netif;
|
||||
|
||||
if (p_netif != NULL && netif_is_up(p_netif)) {
|
||||
for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
|
||||
// Only return the IPs which are:
|
||||
// 1. the state is preferred
|
||||
// 2. not the IP6_ADDR_ANY(all bits are `0`)
|
||||
if (ip6_addr_ispreferred(netif_ip6_addr_state(p_netif, i)) && !ip_addr_cmp(&p_netif->ip6_addr[i], IP6_ADDR_ANY)) {
|
||||
memcpy(&if_ip6[addr_count++], &p_netif->ip6_addr[i], sizeof(ip6_addr_t));
|
||||
}
|
||||
}
|
||||
}
|
||||
return addr_count;
|
||||
}
|
||||
#endif
|
||||
|
||||
esp_netif_flags_t esp_netif_get_flags(esp_netif_t *esp_netif)
|
||||
|
Reference in New Issue
Block a user