mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-20 12:55:43 +08:00
Squashed commit of the following:
apps/netutils/netlib: netlib_ipv[4|6]adaptor() will now use the new routing table interfaces if they are available: If the desination IP address does not correspond to the network served by any device, then the address of the router that should get us to the correct sub-net is is determined. Then the network adaptor that can communicate with the that router has the IP address that will returned. apps/netutils/netlib: Add new utilities netlib_ipv[4|6]router() that can be used to determine the IP address of a router that would be used some some destination IP address that is not locally accessible. apps/netutils/netlib: Add helpers for reading the routing table: netlib_read_ipv4route() and netlib_read_ipv6route()
This commit is contained in:
@@ -53,11 +53,11 @@
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
* Priver Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netlib_ipv4adaptor
|
||||
* Name: _netlib_ipv4adaptor
|
||||
*
|
||||
* Description:
|
||||
* Given the destination address, destipaddr, return the IP address
|
||||
@@ -87,7 +87,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int netlib_ipv4adaptor(in_addr_t destipaddr, FAR in_addr_t *srcipaddr)
|
||||
static int _netlib_ipv4adaptor(in_addr_t destipaddr, FAR in_addr_t *srcipaddr)
|
||||
{
|
||||
FAR struct ifreq *ifr;
|
||||
struct ifconf ifc;
|
||||
@@ -209,4 +209,71 @@ errout_with_sd:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netlib_ipv4adaptor
|
||||
*
|
||||
* Description:
|
||||
* Given the destination address, destipaddr, return the IP address
|
||||
* assigned to the network adaptor that connects the sub-net that
|
||||
* includes destipaddr.
|
||||
*
|
||||
* If routing table support is enabled, then this logic will account for
|
||||
* the case where the destination address is not locally accessible. In
|
||||
* this case, it will return the IP address of the network adaptor that
|
||||
* provides the correct router to handle that destination address.
|
||||
*
|
||||
* Input Parameters:
|
||||
* destipaddr - The destination IPv4 address
|
||||
* srcipaddr - The location to return that adaptor address that serves
|
||||
* the sub-net that includes the destination address.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success with srcipaddr valid. A negated
|
||||
* errno value is returned on any failure and in this case the srcipaddr
|
||||
* is not valid.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int netlib_ipv4adaptor(in_addr_t destipaddr, FAR in_addr_t *srcipaddr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(srcipaddr != NULL);
|
||||
ret = _netlib_ipv4adaptor(destipaddr, srcipaddr);
|
||||
|
||||
#ifdef HAVE_ROUTE_PROCFS
|
||||
if (ret < 0)
|
||||
{
|
||||
struct in_addr router;
|
||||
struct in_addr destinaddr;
|
||||
|
||||
/* If the first adaptor look-up on the the destination IP address
|
||||
* failed, then the IP address cannot be sent on any of the currently
|
||||
* up network devices configured with an IPv4 address.
|
||||
*
|
||||
* But perhaps the destination address is on a sub-net that is
|
||||
* accessible on a router that can be reached through a local network
|
||||
* adaptor?
|
||||
*/
|
||||
|
||||
destinaddr.s_addr = destipaddr;
|
||||
ret = netlib_ipv4router(&destinaddr, &router);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Yes... try again using the router address as the destination
|
||||
* address.
|
||||
*/
|
||||
|
||||
ret = _netlib_ipv4adaptor(router.s_addr, srcipaddr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
Reference in New Issue
Block a user