File dovecot-2.4.0-gethostbyname.patch of Package dovecot

diff -purN a/m4/nsl.m4 b/m4/nsl.m4
--- a/m4/nsl.m4	2025-01-24 08:08:40.000000000 +0100
+++ b/m4/nsl.m4	2025-01-31 12:50:33.382319844 +0100
@@ -1,6 +1,3 @@
 AC_DEFUN([DOVECOT_NSL], [
-  AC_SEARCH_LIBS([inet_aton], [resolv])
-  AC_SEARCH_LIBS([gethostbyname], [nsl])
   AC_SEARCH_LIBS([socket], [socket])
-  AC_SEARCH_LIBS([gethostent], [nsl])
 ])
diff -purN a/src/lib/hostpid.c b/src/lib/hostpid.c
--- a/src/lib/hostpid.c	2025-01-24 08:08:40.000000000 +0100
+++ b/src/lib/hostpid.c	2025-01-31 16:40:32.072392558 +0100
@@ -50,20 +50,31 @@ void hostpid_deinit(void)
 
 const char *my_hostdomain(void)
 {
-	struct hostent *hent;
 	const char *name;
+	struct addrinfo hints, *res;
 
-	if (my_domain == NULL) {
-		name = getenv(MY_HOSTDOMAIN_ENV);
-		if (name == NULL) {
-			hent = gethostbyname(my_hostname);
-			name = hent != NULL ? hent->h_name : NULL;
-			if (name == NULL) {
-				/* failed, use just the hostname */
-				name = my_hostname;
-			}
-		}
+	if (my_domain != NULL) {
+		return my_domain;
+	}
+
+	name = getenv(MY_HOSTDOMAIN_ENV);
+	if (name != NULL) {
 		my_domain = i_strdup(name);
+		return my_domain;
+	}
+
+	i_zero(&hints);
+	hints.ai_family = AF_UNSPEC;            // IPV4 or IPV6
+	hints.ai_socktype = SOCK_STREAM;        // TCP
+	hints.ai_flags = AI_CANONNAME;
+
+	if (getaddrinfo(my_hostname, NULL, &hints, &res) == 0) {
+		my_domain = i_strdup(res->ai_canonname);
+		freeaddrinfo(res);
+		return my_domain;
 	}
+
+	/* failed, use just the hostname */
+	my_domain = i_strdup(my_hostname);
 	return my_domain;
 }
openSUSE Build Service is sponsored by