From 05934f97678ef7d5925562d6cae001d60b9909bc Mon Sep 17 00:00:00 2001 From: shin Date: Wed, 9 Feb 2000 00:38:06 +0000 Subject: [PATCH] IPv6 scoped addr format is changed as recent KAME change. KAME scoped addr format is changed recently. before: addr@scope now: scope%addr Because the end of IPv6 numeric addr is tend to be truncated in `netstat -rn ` output, so placing scope part at starting of addr will be convenient. Approved by: jkh Obtained from: KAME project --- lib/libc/net/getaddrinfo.c | 4 ++-- lib/libc/net/getnameinfo.c | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index 9f0a47ab7b9f..125ea694605f 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -707,7 +707,7 @@ explore_numeric_scope(pai, hostname, servname, res) switch (pai->ai_family) { #ifdef INET6 case AF_INET6: - scope = if_nametoindex(cp); + scope = if_nametoindex(hostname2); if (scope == 0) { error = EAI_SYSTEM; goto free; @@ -716,7 +716,7 @@ explore_numeric_scope(pai, hostname, servname, res) #endif } - error = explore_numeric(pai, hostname2, servname, res); + error = explore_numeric(pai, cp, servname, res); if (error == 0) { for (cur = *res; cur; cur = cur->ai_next) { #ifdef INET6 diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c index 5ca6140b0da0..42f7906ee9f9 100644 --- a/lib/libc/net/getnameinfo.c +++ b/lib/libc/net/getnameinfo.c @@ -189,14 +189,24 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) unsigned int ifindex = ((struct sockaddr_in6 *)sa)->sin6_scope_id; char ifname[IF_NAMESIZE * 2 /* for safety */]; + int scopelen, numaddrlen; if ((if_indextoname(ifindex, ifname)) == NULL) return ENI_SYSTEM; - if (strlen(host) + 1 /* SCOPE_DELIMITER */ - + strlen(ifname) > hostlen) + scopelen = strlen(ifname); + numaddrlen = strlen(host); + if (numaddrlen + 1 /* SCOPE_DELIMITER */ + + scopelen > hostlen) return ENI_MEMORY; - *ep = SCOPE_DELIMITER; - strcpy(ep + 1, ifname); + /* + * Shift the host string to allocate + * space for the scope ID part. + */ + memmove(host + scopelen + 1, host, numaddrlen); + /* copy the scope ID and the delimiter */ + memcpy(host, ifname, scopelen); + host[scopelen] = SCOPE_DELIMITER; + host[scopelen + 1 + numaddrlen] = '\0'; } } #endif /* INET6 */