Calling getaddrinfo(3) in 32-bit binary on 64-bit host
Yuri Pankov
yuripv at icloud.com
Sun Jan 21 23:33:26 UTC 2018
On Mon, Jan 22, 2018 at 05:14:59AM +0800, Li-Wen Hsu wrote:
> Hi all,
>
> Recently I found a strange case: calling getaddrinfo(3) cannot resolve IPv6
> address in 32-bit binary on 64-bit host.
> It happens on vanilla installed 11.1-R and also on r327788 snapshot build.
>
> For a program like this:
> https://gist.github.com/lwhsu/1288aa5be90b9e7da934a3e2bfc55aa3
>
> It works fine when compiled as a 32-bit binary and run on a 32-bit host.
> As expected, It is also works fine when compiled as a 64-bit binary and run
> on a 64-bit host
>
> However, when taking the 32-bit binary and run on a 64 bit system (with
> /usr/lib32 installed),
> getaddrinfo(3) just returns: "Non-recoverable failure in name resolution"
Apparently, it goes through addrconfig() down to getifaddrs() returning
bogus data for IPv6 addresses. This most likely has to with SALIGN
being incorrect for 32-bit binary trying to parse route messages from
64-bit kernel. I'm not sure about proper fix here, but changing SALIGN
to be 7 (that is, "sizeof(long) - 1" on amd64 platform) makes your test
case return correct data.
More information about the freebsd-hackers
mailing list