* This function will get the first network interface device * in network interface device list by protocol family type. * * @param family the network interface device protocol family type * * @return != NULL: network interface device object * NULL: get failed */
| 379 | * NULL: get failed |
| 380 | */ |
| 381 | struct netdev *netdev_get_by_family(int family) |
| 382 | { |
| 383 | rt_slist_t *node = RT_NULL; |
| 384 | struct netdev *netdev = RT_NULL; |
| 385 | struct sal_proto_family *pf = RT_NULL; |
| 386 | |
| 387 | if (netdev_list == RT_NULL) |
| 388 | { |
| 389 | return RT_NULL; |
| 390 | } |
| 391 | |
| 392 | rt_spin_lock(&_spinlock); |
| 393 | |
| 394 | for (node = &(netdev_list->list); node; node = rt_slist_next(node)) |
| 395 | { |
| 396 | netdev = rt_slist_entry(node, struct netdev, list); |
| 397 | pf = (struct sal_proto_family *) netdev->sal_user_data; |
| 398 | if (pf && pf->skt_ops && pf->family == family && netdev_is_up(netdev)) |
| 399 | { |
| 400 | rt_spin_unlock(&_spinlock); |
| 401 | return netdev; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | for (node = &(netdev_list->list); node; node = rt_slist_next(node)) |
| 406 | { |
| 407 | netdev = rt_slist_entry(node, struct netdev, list); |
| 408 | pf = (struct sal_proto_family *) netdev->sal_user_data; |
| 409 | if (pf && pf->skt_ops && pf->sec_family == family && netdev_is_up(netdev)) |
| 410 | { |
| 411 | rt_spin_unlock(&_spinlock); |
| 412 | return netdev; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | rt_spin_unlock(&_spinlock); |
| 417 | |
| 418 | return RT_NULL; |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * This function will get the family type from network interface device |