resolv: Remove compat-gethnamddr.c address sorting code
diff mbox series

Message ID 87a7lpm2du.fsf@oldenburg.str.redhat.com
State New
Headers show
Series
  • resolv: Remove compat-gethnamddr.c address sorting code
Related show

Commit Message

Florian Weimer Dec. 1, 2018, 8:13 p.m. UTC
Address sorting is virtually unused and has hardly any visible
effect, so let's do not keep it for these compatibility symbols.
(Address sorting for NSS-based interfaces is unaffected by this.)

2018-12-01  Florian Weimer  <fweimer@redhat.com>

	* resolv/compat-gethnamaddr.c (addrsort): Remove.
	(getanswer): Do not call addrsort.

Patch
diff mbox series

diff --git a/resolv/compat-gethnamaddr.c b/resolv/compat-gethnamaddr.c
index 0e24dcbbcc..cddda2b353 100644
--- a/resolv/compat-gethnamaddr.c
+++ b/resolv/compat-gethnamaddr.c
@@ -91,8 +91,6 @@  static struct hostent *res_gethostbyname2_context (struct resolv_context *,
 static void map_v4v6_address (const char *src, char *dst) __THROW;
 static void map_v4v6_hostent (struct hostent *hp, char **bp, int *len) __THROW;
 
-extern void addrsort (char **, int) __THROW;
-
 # if PACKETSZ > 65536
 #  define	MAXPACKET	PACKETSZ
 # else
@@ -379,13 +377,6 @@  getanswer (const querybuf *answer, int anslen, const char *qname, int qtype)
 	if (haveanswer) {
 		*ap = NULL;
 		*hap = NULL;
-		/*
-		 * Note: we sort even if host can take only one address
-		 * in its return structures - should give it the "best"
-		 * address in that case, not some random one
-		 */
-		if (_res.nsort && haveanswer > 1 && qtype == T_A)
-			addrsort(h_addr_ptrs, haveanswer);
 		if (!host.h_name) {
 			n = strlen(qname) + 1;	/* for the \0 */
 			if (n > buflen || n >= MAXHOSTNAMELEN)
@@ -871,45 +862,4 @@  map_v4v6_hostent (struct hostent *hp, char **bpp, int *lenp)
 	}
 }
 
-extern void
-addrsort (char **ap, int num)
-{
-	int i, j;
-	char **p;
-	short aval[MAXADDRS];
-	int needsort = 0;
-
-	p = ap;
-	for (i = 0; i < num; i++, p++) {
-	    for (j = 0 ; (unsigned)j < _res.nsort; j++)
-		if (_res.sort_list[j].addr.s_addr ==
-		    (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))
-			break;
-	    aval[i] = j;
-	    if (needsort == 0 && i > 0 && j < aval[i-1])
-		needsort = i;
-	}
-	if (!needsort)
-	    return;
-
-	while (needsort < num) {
-	    for (j = needsort - 1; j >= 0; j--) {
-		if (aval[j] > aval[j+1]) {
-		    char *hp;
-
-		    i = aval[j];
-		    aval[j] = aval[j+1];
-		    aval[j+1] = i;
-
-		    hp = ap[j];
-		    ap[j] = ap[j+1];
-		    ap[j+1] = hp;
-
-		} else
-		    break;
-	    }
-	    needsort++;
-	}
-}
-
 #endif	/* SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_25) */