* This function will get the first network interface device * in network interface device list by IP address. * * @param ip_addr the network interface device IP address * * @return != NULL: network interface device object * NULL: get failed */
| 270 | * NULL: get failed |
| 271 | */ |
| 272 | struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr) |
| 273 | { |
| 274 | rt_slist_t *node = RT_NULL; |
| 275 | struct netdev *netdev = RT_NULL; |
| 276 | |
| 277 | if (netdev_list == RT_NULL) |
| 278 | { |
| 279 | return RT_NULL; |
| 280 | } |
| 281 | |
| 282 | rt_spin_lock(&_spinlock); |
| 283 | |
| 284 | for (node = &(netdev_list->list); node; node = rt_slist_next(node)) |
| 285 | { |
| 286 | netdev = rt_slist_entry(node, struct netdev, list); |
| 287 | if (netdev && ip_addr_cmp(&(netdev->ip_addr), ip_addr)) |
| 288 | { |
| 289 | rt_spin_unlock(&_spinlock); |
| 290 | return netdev; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | rt_spin_unlock(&_spinlock); |
| 295 | |
| 296 | return RT_NULL; |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * This function will get network interface device |