Move some useful internal macros from udp_send.c and put them in ip.h where they can be used more generally
This commit is contained in:
parent
29b819365b
commit
686dcbb79c
@ -327,6 +327,47 @@ EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link addres
|
||||
((uint16_t*)(addr))[7] = HTONS((addr7)); \
|
||||
} while (0)
|
||||
|
||||
/****************************************************************************
|
||||
* Macro: ip6_get_ipv4addr
|
||||
*
|
||||
* Description:
|
||||
* Decode an encoded IPv4 address.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ipv6addr - The IPv6 address (net_ipv6addr_t) containing the encoded
|
||||
* IPv4 address
|
||||
*
|
||||
* Returned Value:
|
||||
* The decode IPv4 addreses (in_addr_t)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define ip6_get_ipv4addr(ipv6addr) \
|
||||
(((in_addr_t)(ipv6addr)->s6_addr[12]) | \
|
||||
((in_addr_t)(ipv6addr)->s6_addr[13] << 8) | \
|
||||
((in_addr_t)(ipv6addr)->s6_addr[14] << 16) | \
|
||||
((in_addr_t)(ipv6addr)->s6_addr[15] << 24))
|
||||
|
||||
/****************************************************************************
|
||||
* Macro: ip6_is_ipv4addr
|
||||
*
|
||||
* Description:
|
||||
* Test if an IPv6 is an encoded IPv4 address.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ipv6addr - The IPv6 address to be tested
|
||||
*
|
||||
* Returned Value:
|
||||
* True is returned if ipv6addr holds an encoded IPv4 address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define ip6_is_ipv4addr(ipv6addr) \
|
||||
((ipv6addr)->s6_addr32[0] == 0 && \
|
||||
(ipv6addr)->s6_addr32[1] == 0 && \
|
||||
(ipv6addr)->s6_addr16[4] == 0 && \
|
||||
(ipv6addr)->s6_addr16[5] == 0xffff)
|
||||
|
||||
/****************************************************************************
|
||||
* Macro: net_ipv4addr_copy, net_ipv4addr_hdrcopy, net_ipv6addr_copy, and
|
||||
* net_ipv6addr_hdrcopy
|
||||
|
@ -73,18 +73,6 @@
|
||||
#define UDPIPv6BUF \
|
||||
((struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN])
|
||||
|
||||
#define IN6_IS_ADDR_IPV4(a) \
|
||||
((a)->s6_addr32[0] == 0 && \
|
||||
(a)->s6_addr32[1] == 0 && \
|
||||
(a)->s6_addr16[4] == 0 && \
|
||||
(a)->s6_addr16[5] == 0xffff)
|
||||
|
||||
#define IN6_GET_ADDR_IPV4(a) \
|
||||
(((in_addr_t)(a)->s6_addr[12]) | \
|
||||
((in_addr_t)(a)->s6_addr[13] << 8) | \
|
||||
((in_addr_t)(a)->s6_addr[14] << 16) | \
|
||||
((in_addr_t)(a)->s6_addr[15] << 24))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
@ -133,7 +121,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
if (conn->domain == PF_INET ||
|
||||
(conn->domain == PF_INET6 &&
|
||||
IN6_IS_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr)))
|
||||
ip6_is_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr)))
|
||||
#endif
|
||||
{
|
||||
/* Get pointers to the IPv4 header and the offset TCP header */
|
||||
@ -159,9 +147,9 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
if (conn->domain == PF_INET6 &&
|
||||
IN6_IS_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr))
|
||||
ip6_is_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr))
|
||||
{
|
||||
in_addr_t raddr = IN6_GET_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr);
|
||||
in_addr_t raddr = ip6_get_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr);
|
||||
net_ipv4addr_hdrcopy(ipv4->destipaddr, &raddr);
|
||||
}
|
||||
else
|
||||
@ -253,7 +241,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
if (conn->domain == PF_INET ||
|
||||
(conn->domain == PF_INET6 &&
|
||||
IN6_IS_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr)))
|
||||
ip6_is_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr)))
|
||||
#endif
|
||||
{
|
||||
udp->udpchksum = ~udp_ipv4_chksum(dev);
|
||||
|
Loading…
Reference in New Issue
Block a user