This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Hi! Although glibc reads sortlist directives in /etc/resolv.conf (it is documented in resolv.conf man page btw) and records them in _res structure, it does not use them. This patch makes this work. Tested with ftp.netscape.com lookup which gives 5 addresses in 2 different networks. 2001-08-14 Jakub Jelinek <jakub@redhat.com> * resolv/nss_dns/dns-host.c (RESOLVSORT): Define. (addrsort): New. * resolv/gethnamaddr.c (RESOLVSORT): Define. --- libc/resolv/nss_dns/dns-host.c.jj Mon Jul 9 14:57:48 2001 +++ libc/resolv/nss_dns/dns-host.c Tue Aug 14 05:21:38 2001 @@ -1,4 +1,4 @@ -/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. +/* Copyright (C) 1996-2000, 2001 Free Software Foundation, Inc. This file is part of the GNU C Library. Extended from original form by Ulrich Drepper <drepper@cygnus.com>, 1996. @@ -86,6 +86,8 @@ #include <resolv/mapv4v6addr.h> #include <resolv/mapv4v6hostent.h> +#define RESOLVSORT + /* Maximum number of aliases we allow. */ #define MAX_NR_ALIASES 48 #define MAX_NR_ADDRS 48 @@ -330,6 +332,51 @@ _nss_dns_gethostbyaddr_r (const void *ad return NSS_STATUS_SUCCESS; } +#ifdef RESOLVSORT +static void addrsort (char **ap, int num); + +static void +addrsort (char **ap, int num) +{ + int i, j; + char **p; + short aval[MAX_NR_ADDRS]; + int needsort = 0; + + p = ap; + if (num > MAX_NR_ADDRS) + num = MAX_NR_ADDRS; + 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 - 2; 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; +} +#endif static enum nss_status getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype, --- libc/resolv/gethnamaddr.c.jj Tue May 9 07:47:59 2000 +++ libc/resolv/gethnamaddr.c Mon Aug 13 17:57:19 2001 @@ -68,6 +68,8 @@ static char rcsid[] = "$Id: gethnamaddr. #include <errno.h> #include <syslog.h> +#define RESOLVSORT + #ifndef LOG_AUTH # define LOG_AUTH 0 #endif Jakub
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |