zsock_getaddrinfo() returns garbage values if IPv4 address is passed and hints->ai_family == AF_INET6 #18870
Labels
area: Networking
bug
The issue is a bug, or the PR is fixing a bug
priority: low
Low impact/importance bug
Milestone
Describe the bug
When
zsock_getaddrinfo()
is passed anode
value that is already a valid stringified IPv4 address, buthints->ai_family
is configured toAF_INET6
, the returned address is unusable.To Reproduce
CMakeLists.txt:
prj.conf:
main.c:
c0a8:101:196:8:5830:8:0:41
. Note that the first two segments,c0a8:101
, is192.168.1.1
printed in IPv6 notation. The rest are random bytes from uninitialized memory.Expected behavior
zsock_getaddrinfo()
in this usage shall fail.If
AI_V4MAPPED
flag is passed throughhints->ai_flags
, and if Zephyr supported IPv4-mapped IPv6 addresses, then returning a proper IPv4-mapped IPv6 address would also be acceptable, but AFAIK, Zephyr does not support IPv4-mapped IPv6 addresses.Impact
If both IPv4 and IPv6 are configured,
zsock_getaddrinfo()
prefers IPv4 addresses (i.e., returns them first). If an application wants to support IPv4/v6 dual stack, wants to support both domain names and numeric addresses, and wants to prefer IPv6 addresses, one possible approach is to callgetaddrinfo()
withAF_INET6
hint first, and then fall back toAF_INET
if that does not yield any results. This approach does not work on Zephyr because of this bug.A different approach is necessary as a workaround, e.g. attempting to use
inet_pton()
first, or usinggetaddrinfo()
without family hint and reordering the results. However, this can be an obstacle when attempting to use existing code that would otherwise be trivially portable to Zephyr.Environment (please complete the following information):
aa9b762d12
The text was updated successfully, but these errors were encountered: