mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2026-01-01 01:41:18 +01:00
netif: add functions to get and get by identifier
This commit is contained in:
parent
18ad1e7154
commit
b8294f1ba0
@ -89,6 +89,16 @@ netif_t *netif_iter(netif_t *last);
|
||||
|
||||
int netif_get_name(netif_t *netif, char *name);
|
||||
|
||||
/**
|
||||
* @brief Gets the numeric identifier of an interface
|
||||
*
|
||||
* @param[in] netif A network interface.
|
||||
*
|
||||
* @return The numeric identifier of an interface
|
||||
* @return -1 if @p netif is not registered
|
||||
*/
|
||||
int16_t netif_get_id(const netif_t *netif);
|
||||
|
||||
/**
|
||||
* @brief Gets interface by name
|
||||
*
|
||||
@ -103,6 +113,16 @@ int netif_get_name(netif_t *netif, char *name);
|
||||
*/
|
||||
netif_t *netif_get_by_name(const char *name);
|
||||
|
||||
/**
|
||||
* @brief Gets interface by a numeric identifier.
|
||||
*
|
||||
* @param[in] id A numeric identifier.
|
||||
*
|
||||
* @return The interface on success.
|
||||
* @return NULL if no interface with identifier @p id.
|
||||
*/
|
||||
netif_t *netif_get_by_id(int16_t id);
|
||||
|
||||
/**
|
||||
* @brief Gets option from an interface
|
||||
*
|
||||
|
||||
@ -40,6 +40,17 @@ netif_t *netif_iter(netif_t *last)
|
||||
return (netif_t *)last->node.next;
|
||||
}
|
||||
|
||||
__attribute__((weak)) int16_t netif_get_id(const netif_t *netif)
|
||||
{
|
||||
list_node_t *node = netif_list.next;
|
||||
for (int16_t i = 0; node; i++, node = node->next) {
|
||||
if (netif == (netif_t *)node) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
netif_t *netif_get_by_name(const char *name)
|
||||
{
|
||||
assert(name);
|
||||
@ -57,4 +68,16 @@ netif_t *netif_get_by_name(const char *name)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
__attribute__((weak)) netif_t *netif_get_by_id(int16_t id)
|
||||
{
|
||||
list_node_t *node = netif_list.next;
|
||||
for (int16_t i = 0; node; i++, node = node->next) {
|
||||
if (i == id) {
|
||||
return (netif_t *)node;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user