From a7eba295f0646a544e543131d16c5740a4875404 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Mon, 7 Apr 2008 17:20:25 +0000 Subject: Handle scope IDs in resolv.conf. --- resolv/res_init.c | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'resolv') diff --git a/resolv/res_init.c b/resolv/res_init.c index d1a5681a93..a2840968f3 100644 --- a/resolv/res_init.c +++ b/resolv/res_init.c @@ -69,22 +69,22 @@ static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; static const char rcsid[] = "$BINDId: res_init.c,v 8.16 2000/05/09 07:10:12 vixie Exp $"; #endif /* LIBC_SCCS and not lint */ -#include -#include -#include -#include - -#include -#include -#include - #include +#include #include #include #include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include @@ -327,15 +327,41 @@ __res_vinit(res_state statp, int preinit) { if ((el = strchr(cp, '\n')) != NULL) *el = '\0'; + if ((el = strchr(cp, SCOPE_DELIMITER)) != NULL) + *el = '\0'; if ((*cp != '\0') && (inet_pton(AF_INET6, cp, &a6) > 0)) { struct sockaddr_in6 *sa6; sa6 = malloc(sizeof(*sa6)); if (sa6 != NULL) { - sa6->sin6_addr = a6; sa6->sin6_family = AF_INET6; sa6->sin6_port = htons(NAMESERVER_PORT); + sa6->sin6_flowinfo = 0; + sa6->sin6_addr = a6; + + if (__builtin_expect (el == NULL, 1)) + sa6->sin6_scope_id = 0; + else { + int try_numericscope = 1; + if (IN6_IS_ADDR_LINKLOCAL (&a6) + || IN6_IS_ADDR_MC_LINKLOCAL (&a6)) { + sa6->sin6_scope_id + = if_nametoindex (el + 1); + if (sa6->sin6_scope_id != 0) + try_numericscope = 0; + } + + if (try_numericscope) { + char *end; + sa6->sin6_scope_id + = (uint32_t) strtoul (el + 1, &end, + 10); + if (*end != '\0') + sa6->sin6_scope_id = 0; + } + } + statp->_u._ext.nsaddrs[nservall] = sa6; statp->_u._ext.nssocks[nservall] = -1; statp->_u._ext.nsmap[nservall] = MAXNS + 1; -- cgit v1.2.1