* 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 */
| 342 | * NULL: get failed |
| 343 | */ |
| 344 | struct 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 | /** |