diff options
| author | Yoshinobu Inoue <shin@FreeBSD.org> | 2000-02-09 00:38:06 +0000 |
|---|---|---|
| committer | Yoshinobu Inoue <shin@FreeBSD.org> | 2000-02-09 00:38:06 +0000 |
| commit | 0db018f059c646176557736314043167e48723e9 (patch) | |
| tree | 8f676557bd71b27ba72b18df616a2eedf0c85099 /lib/libc/net/getnameinfo.c | |
| parent | a683a7dd4f600574a9e62a1c8b11d6e03e612906 (diff) | |
Notes
Diffstat (limited to 'lib/libc/net/getnameinfo.c')
| -rw-r--r-- | lib/libc/net/getnameinfo.c | 18 |
1 files changed, 14 insertions, 4 deletions
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 */ |
