File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,6 +89,16 @@ netif_t *netif_iter(netif_t *last);
8989
9090int netif_get_name (netif_t * netif , char * name );
9191
92+ /**
93+ * @brief Gets the numeric identifier of an interface
94+ *
95+ * @param[in] netif A network interface.
96+ *
97+ * @return The numeric identifier of an interface
98+ * @return -1 if @p netif is not registered
99+ */
100+ int16_t netif_get_id (const netif_t * netif );
101+
92102/**
93103 * @brief Gets interface by name
94104 *
@@ -103,6 +113,16 @@ int netif_get_name(netif_t *netif, char *name);
103113 */
104114netif_t * netif_get_by_name (const char * name );
105115
116+ /**
117+ * @brief Gets interface by a numeric identifier.
118+ *
119+ * @param[in] id A numeric identifier.
120+ *
121+ * @return The interface on success.
122+ * @return NULL if no interface with identifier @p id.
123+ */
124+ netif_t * netif_get_by_id (int16_t id );
125+
106126/**
107127 * @brief Gets option from an interface
108128 *
Original file line number Diff line number Diff line change @@ -40,6 +40,17 @@ netif_t *netif_iter(netif_t *last)
4040 return (netif_t * )last -> node .next ;
4141}
4242
43+ int16_t netif_get_id (const netif_t * netif )
44+ {
45+ list_node_t * node = netif_list .next ;
46+ for (int16_t i = 0 ; node ; i ++ , node = node -> next ) {
47+ if (netif == (netif_t * )node ) {
48+ return i ;
49+ }
50+ }
51+ return -1 ;
52+ }
53+
4354netif_t * netif_get_by_name (const char * name )
4455{
4556 assert (name );
@@ -57,4 +68,16 @@ netif_t *netif_get_by_name(const char *name)
5768
5869 return NULL ;
5970}
71+
72+ int16_t netif_get_by_id (int16_t netif )
73+ {
74+ list_node_t * node = netif_list .next ;
75+ for (int16_t i = 0 ; node ; i ++ , node = node -> next ) {
76+ if (i == id ) {
77+ return (netif_t * )node ;
78+ }
79+ }
80+ return -1 ;
81+ }
82+
6083/** @} */
You can’t perform that action at this time.
0 commit comments