mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 23:28:29 +08:00
net/udp: Fix hybrid dual-stack IPv6/IPv4 socket
- Fix `ip6_map_ipv4addr` and `ip6_get_ipv4addr` macro to work under
different endianness.
- Use `iob_reserve` instead of `iob_trimhead` in `udp_datahandler`.
- Because we may set `sockaddr_in6` into IPv4 header, which causes
`offset` become negative. `iob_reserve` can hold this case while
`iob_trimhead` cannot.
- Select IPv4 domain in send case.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
@@ -374,9 +374,8 @@ extern "C"
|
||||
do \
|
||||
{ \
|
||||
memset(ipv6addr, 0, 5 * sizeof(uint16_t)); \
|
||||
ipv6addr[5] = 0xffff; \
|
||||
ipv6addr[6] = (uint16_t)((uint32_t)ipv4addr >> 16); \
|
||||
ipv6addr[7] = (uint16_t)ipv4addr & 0xffff; \
|
||||
(ipv6addr)[5] = 0xffff; \
|
||||
net_ipv4addr_hdrcopy(&(ipv6addr)[6], &(ipv4addr)); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
@@ -395,11 +394,7 @@ extern "C"
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#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))
|
||||
#define ip6_get_ipv4addr(ipv6addr) net_ip4addr_conv32(&(ipv6addr)[6])
|
||||
|
||||
/****************************************************************************
|
||||
* Macro: ip6_is_ipv4addr
|
||||
|
||||
Reference in New Issue
Block a user