Blame SOURCES/rsyslog-8.24.0-rhbz1056548-getaddrinfo.patch

b65758
diff --git a/runtime/net.c b/runtime/net.c
b65758
index 3610fc5..2d8de94 100644
b65758
--- a/runtime/net.c
b65758
+++ b/runtime/net.c
b65758
@@ -1181,26 +1181,24 @@ getLocalHostname(uchar **ppName)
b65758
 	}
b65758
 
b65758
 	char *dot = strstr(hnbuf, ".");
b65758
+	struct addrinfo *res = NULL;
b65758
 	if(!empty_hostname && dot == NULL) {
b65758
 		/* we need to (try) to find the real name via resolver */
b65758
-		struct hostent *hent = gethostbyname((char*)hnbuf);
b65758
-		if(hent) {
b65758
-			int i = 0;
b65758
-			if(hent->h_aliases) {
b65758
-				const size_t hnlen = strlen(hnbuf);
b65758
-				for(i = 0; hent->h_aliases[i]; i++) {
b65758
-					if(!strncmp(hent->h_aliases[i], hnbuf, hnlen)
b65758
-					   && hent->h_aliases[i][hnlen] == '.') {
b65758
-						break; /* match! */
b65758
-					}
b65758
-				}
b65758
-			}
b65758
-			if(hent->h_aliases && hent->h_aliases[i]) {
b65758
-				CHKmalloc(fqdn = (uchar*)strdup(hent->h_aliases[i]));
b65758
-			} else {
b65758
-				CHKmalloc(fqdn = (uchar*)strdup(hent->h_name));
b65758
+		struct addrinfo flags;
b65758
+		memset(&flags, 0, sizeof(flags));
b65758
+		flags.ai_flags = AI_CANONNAME;
b65758
+		int error = getaddrinfo((char*)hnbuf, NULL, &flags, &res;;
b65758
+		if (error != 0) {
b65758
+			dbgprintf("getaddrinfo: %s\n", gai_strerror(error));
b65758
+			ABORT_FINALIZE(RS_RET_IO_ERROR);
b65758
+		}
b65758
+		if (res != NULL) {
b65758
+			/* When AI_CANONNAME is set first member of res linked-list */
b65758
+			/* should contain what we need */
b65758
+			if (res->ai_canonname != NULL && res->ai_canonname[0] != '\0') {
b65758
+				CHKmalloc(fqdn = (uchar*)strdup(res->ai_canonname));
b65758
+				dot = strstr((char*)fqdn, ".");
b65758
 			}
b65758
-			dot = strstr((char*)fqdn, ".");
b65758
 		}
b65758
 	}
b65758
 
b65758
@@ -1215,6 +1213,9 @@ getLocalHostname(uchar **ppName)
b65758
 
b65758
 	*ppName = fqdn;
b65758
 finalize_it:
b65758
+	if (res != NULL) {
b65758
+		freeaddrinfo(res);
b65758
+	}
b65758
 	RETiRet;
b65758
 }
b65758