From 9b59fde4e0c287dde4ddb2f4f34f4b0a58dacbf9 Mon Sep 17 00:00:00 2001 From: Yoshinobu Inoue Date: Tue, 28 Dec 1999 05:37:39 +0000 Subject: [PATCH] Small bug fix and improvements (1)added error check of if_nameindex() return value at getaddrinfo(). (2)print out more detailed information when getaddrinfo() error value is EAI_SYSTEM.(in this case system error num is kept in errno) (1) is Discovered by: jinmei@kame.net in KAME environment. --- lib/libc/net/getaddrinfo.c | 7 +++++++ sbin/ping6/ping6.c | 10 ++++++++-- usr.sbin/rip6query/rip6query.c | 6 +++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index 79b07dee28b3..dd8524393df4 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -766,6 +766,10 @@ explore_numeric_scope(pai, hostname, servname, res) #ifdef INET6 case AF_INET6: scope = if_nametoindex(cp); + if (scope == 0) { + error = EAI_SYSTEM; + goto free; + } break; #endif } @@ -784,6 +788,9 @@ explore_numeric_scope(pai, hostname, servname, res) } } +#ifdef INET6 +free: +#endif free(hostname2); return error; diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index d1186559400c..34de2bdc00b4 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -434,6 +434,8 @@ main(argc, argv) ret_ga = getaddrinfo(target, NULL, &hints, &res); if (ret_ga) { fprintf(stderr, "ping6: %s\n", gai_strerror(ret_ga)); + if (ret_ga == EAI_SYSTEM) + errx(1, "%s", strerror(errno)); exit(1); } if (res->ai_canonname) @@ -586,8 +588,12 @@ main(argc, argv) for (hops = 0; hops < argc - 1; hops++) { struct addrinfo *iaip; - if ((error = getaddrinfo(argv[hops], NULL, &hints, &iaip))) - errx(1, gai_strerror(error)); + if ((error = getaddrinfo(argv[hops], NULL, &hints, &iaip))) { + fprintf(stderr, "ping6: %s\n", gai_strerror(error)); + if (error == EAI_SYSTEM) + errx(1, strerror(errno)); + exit(1); + } if (SIN6(res->ai_addr)->sin6_family != AF_INET6) errx(1, "bad addr family of an intermediate addr"); diff --git a/usr.sbin/rip6query/rip6query.c b/usr.sbin/rip6query/rip6query.c index 59e7932a57a3..6c2fb5c0fc36 100644 --- a/usr.sbin/rip6query/rip6query.c +++ b/usr.sbin/rip6query/rip6query.c @@ -119,7 +119,11 @@ main(argc, argv) hints.ai_socktype = SOCK_STREAM; error = getaddrinfo(argv[0], pbuf, &hints, &res); if (error) { - errx(1, "%s: %s", argv[0], gai_strerror(error)); + fprintf(stderr, "rip6query: %s: %s\n", argv[0], + gai_strerror(error)); + if (error == EAI_SYSTEM) + errx(1, "%s", strerror(errno)); + exit(1); /*NOTREACHED*/ } if (res->ai_next) {