MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / netdev_get_by_ifindex

Function netdev_get_by_ifindex

components/net/netdev/src/netdev.c:344–369  ·  view source on GitHub ↗

* This function will get network interface device * in network interface device list by netdev ifindex. * * @param ifindex the ifindex of network interface device * * @return != NULL: network interface device object * NULL: get failed */

Source from the content-addressed store, hash-verified

342 * NULL: get failed
343 */
344struct netdev *netdev_get_by_ifindex(int ifindex)
345{
346 rt_slist_t *node = RT_NULL;
347 struct netdev *netdev = RT_NULL;
348
349 if (netdev_list == RT_NULL)
350 {
351 return RT_NULL;
352 }
353
354 rt_spin_lock(&_spinlock);
355
356 for (node = &(netdev_list->list); node; node = rt_slist_next(node))
357 {
358 netdev = rt_slist_entry(node, struct netdev, list);
359 if (netdev && (netdev->ifindex == ifindex))
360 {
361 rt_spin_unlock(&_spinlock);
362 return netdev;
363 }
364 }
365
366 rt_spin_unlock(&_spinlock);
367
368 return RT_NULL;
369}
370
371#ifdef RT_USING_SAL
372/**

Callers 2

Calls 3

rt_slist_nextFunction · 0.85
rt_spin_lockFunction · 0.50
rt_spin_unlockFunction · 0.50

Tested by 2