diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2025-03-26 08:42:35 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2025-03-26 08:45:44 +0100 |
commit | 735904142f95d0500c0eae6bf763e4ad24b6b9fd (patch) | |
tree | 6bc7f72d4092052800da6a91658f04feac60223e | |
parent | a83fa4c7582e537980f0bed750890d9618230967 (diff) | |
download | slirp-735904142f95d0500c0eae6bf763e4ad24b6b9fd.zip slirp-735904142f95d0500c0eae6bf763e4ad24b6b9fd.tar.gz slirp-735904142f95d0500c0eae6bf763e4ad24b6b9fd.tar.bz2 |
apple: Fix getting IPv4 DNS server address when IPv4 and IPv4 are interleaved
When getting an IPv4 DNS server address, if libresolv returns
IPv4
IPv6
IPv4
IPv6
(or just IPv4 and IPv6)
we would still have found == 1 on the second iteration and thus take the
IPv6 even if it's not the proper af. We can as well just completely ignore
the non-matching af entries.
Fixes #85
-rw-r--r-- | src/slirp.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/slirp.c b/src/slirp.c index bccee53..62a018a 100644 --- a/src/slirp.c +++ b/src/slirp.c @@ -289,9 +289,12 @@ static int get_dns_addr_libresolv(int af, void *pdns_addr, void *cached_addr, found = 0; DEBUG_MISC("IP address of your DNS(s):"); for (int i = 0; i < count; i++) { - if (af == servers[i].sin.sin_family) { - found++; + if (af != servers[i].sin.sin_family) { + continue; } + + found++; + if (af == AF_INET) { addr = &servers[i].sin.sin_addr; } else { // af == AF_INET6 |