| 1589 | } |
| 1590 | |
| 1591 | int sal_getaddrinfo(const char *nodename, |
| 1592 | const char *servname, |
| 1593 | const struct addrinfo *hints, |
| 1594 | struct addrinfo **res) |
| 1595 | { |
| 1596 | struct netdev *netdev = netdev_default; |
| 1597 | struct sal_proto_family *pf; |
| 1598 | int ret = 0; |
| 1599 | rt_uint32_t i = 0; |
| 1600 | |
| 1601 | if (SAL_NETDEV_NETDBOPS_VALID(netdev, pf, getaddrinfo)) |
| 1602 | { |
| 1603 | ret = pf->netdb_ops->getaddrinfo(nodename, servname, hints, res); |
| 1604 | } |
| 1605 | else |
| 1606 | { |
| 1607 | /* get the first network interface device with up status */ |
| 1608 | netdev = netdev_get_first_by_flags(NETDEV_FLAG_UP); |
| 1609 | if (SAL_NETDEV_NETDBOPS_VALID(netdev, pf, getaddrinfo)) |
| 1610 | { |
| 1611 | ret = pf->netdb_ops->getaddrinfo(nodename, servname, hints, res); |
| 1612 | } |
| 1613 | else |
| 1614 | { |
| 1615 | ret = -1; |
| 1616 | } |
| 1617 | } |
| 1618 | |
| 1619 | if (ret == RT_EOK) |
| 1620 | { |
| 1621 | /*record the netdev and res*/ |
| 1622 | for (i = 0; i < SAL_SOCKETS_NUM; i++) |
| 1623 | { |
| 1624 | if (sal_dev_res_tbl[i].res == RT_NULL) |
| 1625 | { |
| 1626 | sal_dev_res_tbl[i].res = *res; |
| 1627 | sal_dev_res_tbl[i].netdev = netdev; |
| 1628 | break; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | RT_ASSERT((i < SAL_SOCKETS_NUM)); |
| 1633 | } |
| 1634 | |
| 1635 | return ret; |
| 1636 | } |
| 1637 | |
| 1638 | void sal_freeaddrinfo(struct addrinfo *ai) |
| 1639 | { |
no test coverage detected