libslirp: fix DNS resolution on MacOS

Signed-off-by: Ihar Hrachyshka <ihar.hrachyshka@gmail.com>
This commit is contained in:
Ihar Hrachyshka 2025-04-15 15:17:32 -04:00
parent 9dc02ffe49
commit 3902b08d8b
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,46 @@
From 735904142f95d0500c0eae6bf763e4ad24b6b9fd Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date: Wed, 26 Mar 2025 08:42:35 +0100
Subject: [PATCH] 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
---
src/slirp.c | 7 +++++--
1 file 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
--
GitLab

View File

@ -20,6 +20,12 @@ stdenv.mkDerivation rec {
sha256 = "sha256-Eqdw6epFkLv4Dnw/s1pcKW0P70ApZwx/J2VkCwn50Ew=";
};
patches = [
# https://gitlab.freedesktop.org/slirp/libslirp/-/commit/735904142f95d0500c0eae6bf763e4ad24b6b9fd
# Vendorized due to frequent instability of the upstream repository.
./fix-dns-for-darwin.patch
];
separateDebugInfo = true;
nativeBuildInputs = [