Subject: bin/17789: whois uses perror instead of gai_strerror (with patch)
To: None <gnats-bugs@gnats.netbsd.org>
From: Christian Biere <christianbiere@gmx.de>
List: netbsd-bugs
Date: 07/31/2002 19:01:29
>Number:         17789
>Category:       bin
>Synopsis:       whois uses perror instead of gai_strerror (with patch)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 31 19:02:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Christian Biere
>Release:        NetBSD 1.6_BETA4
>Organization:
        
>Environment:

>Description:

getaddrinfo() returns the error code itself. The only exception is
EAI_SYSTEM in which case you should use strerror() or perror() to get
the appropriate error message.

>How-To-Repeat:

$ whois -h ThereIsNoHost blah
whois: ThereIsNoHost: Unknown host: Undefined error: 0

>Fix:

Index: whois.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/whois/whois.c,v
retrieving revision 1.17
diff -u -r1.17 whois.c
--- whois.c	2001/04/06 11:13:46	1.17
+++ whois.c	2002/08/01 01:29:43
@@ -446,7 +446,9 @@
     hints.ai_protocol = 0;
     error = getaddrinfo(host, optport, &hints, &dst);
     if ((error) && (verb))
-      fprintf(stderr,"No such host: %s\n", whoishost);
+      fprintf(stderr,"whois: getaddrinfo() using host '%s' failed: %s\n", host, 
+              error != EAI_SYSTEM ? gai_strerror(error) : strerror(errno));
+
     if (error) {
 #endif
     
@@ -461,9 +463,10 @@
       hints.ai_protocol = 0;
       error = getaddrinfo(host, optport , &hints, &dst);
       if (error) {
-	fprintf(stderr,"No such host: %s\n", whoishost);
+	fprintf(stderr,"whois: getaddrinfo() using host '%s' failed: %s\n", 
+	        host, 
+	        error != EAI_SYSTEM ? gai_strerror(error) : strerror(errno));
 	if (verb) fprintf(stderr, "Now I give up ...\n");
-	perror("Unknown host");
 	exit(1);	
       }
 
@@ -481,8 +484,8 @@
     hints.ai_protocol = 0;
     error = getaddrinfo(host, optport, &hints, &dst);
     if (error) {
-      (void)fprintf(stderr, "whois: %s: ", host);
-      perror("Unknown host");
+      fprintf(stderr,"whois: getaddrinfo() using host '%s' failed: %s\n", host, 
+              error != EAI_SYSTEM ? gai_strerror(error) : strerror(errno));
       exit(1);
     }
   }
>Release-Note:
>Audit-Trail:
>Unformatted: