From owner-freebsd-bugs Mon Dec 18 17:40: 7 2000 From owner-freebsd-bugs@FreeBSD.ORG Mon Dec 18 17:40:04 2000 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id DAE1637B400 for ; Mon, 18 Dec 2000 17:40:02 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id eBJ1e2997955; Mon, 18 Dec 2000 17:40:02 -0800 (PST) (envelope-from gnats) Date: Mon, 18 Dec 2000 17:40:02 -0800 (PST) Message-Id: <200012190140.eBJ1e2997955@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Phil Homewood Subject: Re: bin/23635: [PATCH] whois enhancement - smarter whois-servers.net lookups Reply-To: Phil Homewood Sender: gnats@FreeBSD.org Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/23635; it has been noted by GNATS. From: Phil Homewood To: gnats-admin@FreeBSD.org, freebsd-bugs@FreeBSD.org Cc: Subject: Re: bin/23635: [PATCH] whois enhancement - smarter whois-servers.net lookups Date: Tue, 19 Dec 2000 11:17:59 +1000 I said: > It also fixes a minor annoyance in that "whois example.com." fails. Oops, that version doesn't. This one does. Please supersede my previous patch with this one. --- usr.bin/whois/whois.c.orig Sat Jul 15 17:29:31 2000 +++ usr.bin/whois/whois.c Tue Dec 19 11:14:33 2000 @@ -84,6 +84,7 @@ { int ch, i, j, error; int use_qnichost, flags; + int found = 0; char *host; char *qnichost; struct addrinfo hints, *res; @@ -160,29 +161,43 @@ free(qnichost); qnichost = NULL; } - for (i = j = 0; (*argv)[i]; i++) { - if ((*argv)[i] == '.') { - j = i; - } + for (i = 0; (*argv)[i]; i++); + if (i <= 1) { + errx(EX_NOHOST, + "Can't search for the null string."); } - if (j != 0) { - qnichost = (char *) calloc(i - j + 1 + - strlen(QNICHOST_TAIL), sizeof(char)); - if (!qnichost) { - err(1, "calloc"); + if ((*argv)[i - 1] == '.') i--; + for (j = 0; (*argv)[j]; j++) { + if (((*argv)[j] == '.') && !found) { + qnichost = (char *) calloc(i - j + 1 + + strlen(QNICHOST_TAIL), + sizeof(char)); + if (!qnichost) { + err(1, "calloc"); + } + strncpy(qnichost, *argv + j + 1, + i - j - 1); + strcat(qnichost, QNICHOST_TAIL); + + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = 0; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + error = getaddrinfo(qnichost, "whois", + &hints, &res); + if (error == 0) { + found = 1; + } else { + free(qnichost); + qnichost = NULL; + } } - strcpy(qnichost, *argv + j + 1); - strcat(qnichost, QNICHOST_TAIL); - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = 0; - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - error = getaddrinfo(qnichost, "whois", - &hints, &res); - if (error != 0) - errx(EX_NOHOST, "%s: %s", qnichost, - gai_strerror(error)); + } + if (!found) { + errx(EX_NOHOST, + "Cannot locate whois server for %s", + *argv); } } if (!qnichost) { -- Phil Homewood pdh@asiaonline.net Senior Technician +61 7 3620 1930 Asia Online (Queensland) http://www.asiaonline.net/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message