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

Function netdev_get_by_family

components/net/netdev/src/netdev.c:381–419  ·  view source on GitHub ↗

* 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 */

Source from the content-addressed store, hash-verified

379 * NULL: get failed
380 */
381struct 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

Callers 3

alloc_socketFunction · 0.85
socket_initFunction · 0.85

Calls 3

rt_slist_nextFunction · 0.85
rt_spin_lockFunction · 0.50
rt_spin_unlockFunction · 0.50

Tested by 1