From 65a0917d4661e370b50beed8f06f5577bfeea59f Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Thu, 10 Jan 2008 21:15:56 -0800 Subject: get_address_info: don't allow duplicate entries to be returned in the list OS-X's getaddrinfo() can return duplicate entries (and does for localhost with the default 10.5 /etc/hosts). This caused some annoying crashes which this patch takes care of. See http://trac.macosforge.org/projects/xquartz/ticket/44 --- gethost.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'gethost.c') diff --git a/gethost.c b/gethost.c index a0f30da..94c1d99 100644 --- a/gethost.c +++ b/gethost.c @@ -307,7 +307,15 @@ struct addrlist *get_address_info ( family = FamilyInternet6; } - if (len > 0 && src != NULL) { + struct addrlist *duplicate; + for(duplicate = retval; duplicate != NULL; duplicate = duplicate->next) { + if(duplicate->family == family && duplicate->len == len && + memcmp(duplicate->address, src, len) == 0) { + break; + } + } + + if (len > 0 && src != NULL && duplicate == NULL) { struct addrlist *newrv = malloc (sizeof(struct addrlist)); if (newrv) { newrv->address = malloc (len); -- cgit v1.2.1