Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

(patch) whois

From: Andrey Matveev <andrushock(at)korovino.net>
Date: Mon Dec 16 2002 - 06:36:33 EST


Hello,

  no functional changes, fix typo in err() message at calloc() failure, add missed   check for malloc() failure, ansify, do some KNF.

  Thanks

-- 
 Andrushock

>>-----cut here-----
--- src/usr.bin/whois/whois.c.orig      Sat Dec 14 06:03:05 2002
+++ src/usr.bin/whois/whois.c   Mon Dec 16 16:54:43 2002
@@ -49,9 +49,11 @@
 

#include <sys/types.h>
+
#include <netinet/in.h>
#include
#include
+
#include <err.h>
@@ -80,24 +82,17 @@ static void whois(char *, struct addrinfo *, int); int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { - int ch, i, j, error; - int use_qnichost, flags; - char *host; - char *qnichost; + int ch, i, j, error, len; + int use_qnichost = 0, flags = 0; + char *host = NULL, *qnichost = NULL; struct addrinfo hints, *res;
#ifdef SOCKS
SOCKSinit(argv[0]);
#endif
- host = NULL; - qnichost = NULL; - flags = 0; - use_qnichost = 0; while ((ch = getopt(argc, argv, "adgh:ilmpqQrR")) != -1) switch((char)ch) { case 'a': @@ -166,11 +161,10 @@ if ((*argv)[i] == '.') j = i; if (j != 0) { - int len = i - j + 1 + strlen(QNICHOST_TAIL); - + len = i - j + 1 + strlen(QNICHOST_TAIL); qnichost = (char *) calloc(len, sizeof(char)); if (!qnichost) - err(1, "malloc"); + err(1, "calloc"); strlcpy(qnichost, *argv + j + 1, len); strlcat(qnichost, QNICHOST_TAIL, len); memset(&hints, 0, sizeof(hints)); @@ -202,10 +196,7 @@ } static void -whois(name, res, flags) - char *name; - struct addrinfo *res;
Do you need help?X
- int flags; +whois(char *name, struct addrinfo *res, int flags) { FILE *sfi, *sfo; char *buf, *p, *nhost, *nbuf = NULL; @@ -250,7 +241,8 @@ else if (buf[len - 1] == '\n') buf[len - 1] = '\0'; else { - nbuf = malloc(len + 1); + if ((nbuf = malloc(len + 1)) == NULL) + err(1, "malloc"); memcpy(nbuf, buf, len); nbuf[len] = '\0'; buf = nbuf; @@ -292,10 +284,8 @@ hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; error = getaddrinfo(nhost, "whois", &hints, &res2); - if (error != 0) { - warnx("%s: %s", nhost, gai_strerror(error)); - return; - } + if (error) + errx(EX_NOHOST, "%s: %s", nhost, gai_strerror(error)); if (!nomatch) free(nhost); whois(name, res2, 0); >>-----end of diff-----
Received on Tue Dec 17 06:40:49 2002

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:29:40 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library