* This function will get network interface device * in network interface device list by netdev name. * * @param name the network interface device name * * @return != NULL: network interface device object * NULL: get failed */
| 306 | * NULL: get failed |
| 307 | */ |
| 308 | struct netdev *netdev_get_by_name(const char *name) |
| 309 | { |
| 310 | rt_slist_t *node = RT_NULL; |
| 311 | struct netdev *netdev = RT_NULL; |
| 312 | |
| 313 | if (netdev_list == RT_NULL) |
| 314 | { |
| 315 | return RT_NULL; |
| 316 | } |
| 317 | |
| 318 | rt_spin_lock(&_spinlock); |
| 319 | |
| 320 | for (node = &(netdev_list->list); node; node = rt_slist_next(node)) |
| 321 | { |
| 322 | netdev = rt_slist_entry(node, struct netdev, list); |
| 323 | if (netdev && (rt_strncmp(netdev->name, name, rt_strlen(name) < RT_NAME_MAX ? rt_strlen(name) : RT_NAME_MAX) == 0)) |
| 324 | { |
| 325 | rt_spin_unlock(&_spinlock); |
| 326 | return netdev; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | rt_spin_unlock(&_spinlock); |
| 331 | |
| 332 | return RT_NULL; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * This function will get network interface device |