summaryrefslogtreecommitdiff
path: root/usr.bin/whois
diff options
context:
space:
mode:
authorKevin Lo <kevlo@FreeBSD.org>2014-01-04 15:51:52 +0000
committerKevin Lo <kevlo@FreeBSD.org>2014-01-04 15:51:52 +0000
commit372ab06ee7ea628a8266407c7dd96bd4d9ffd263 (patch)
tree3131777e004c05fceb7674850c357e5c3fd899d9 /usr.bin/whois
parentc809a67a722a990f0a69b169bf56eff5a36f0ef2 (diff)
downloadsrc-test-372ab06ee7ea628a8266407c7dd96bd4d9ffd263.tar.gz
src-test-372ab06ee7ea628a8266407c7dd96bd4d9ffd263.zip
The whois() function is called in a loop so make sure we close the
socket to the whois server before returning. Obtained from: OpenBSD
Notes
Notes: svn path=/head/; revision=260259
Diffstat (limited to 'usr.bin/whois')
-rw-r--r--usr.bin/whois/whois.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/usr.bin/whois/whois.c b/usr.bin/whois/whois.c
index d76d05a672bc6..99926b8e111ad 100644
--- a/usr.bin/whois/whois.c
+++ b/usr.bin/whois/whois.c
@@ -275,7 +275,7 @@ s_asprintf(char **ret, const char *format, ...)
static void
whois(const char *query, const char *hostname, int flags)
{
- FILE *sfi, *sfo;
+ FILE *fp;
struct addrinfo *hostres, *res;
char *buf, *host, *nhost, *p;
int i, s;
@@ -295,20 +295,19 @@ whois(const char *query, const char *hostname, int flags)
if (res == NULL)
err(EX_OSERR, "connect()");
- sfi = fdopen(s, "r");
- sfo = fdopen(s, "w");
- if (sfi == NULL || sfo == NULL)
+ fp = fdopen(s, "r+");
+ if (fp == NULL)
err(EX_OSERR, "fdopen()");
if (strcmp(hostname, GERMNICHOST) == 0) {
- fprintf(sfo, "-T dn,ace -C US-ASCII %s\r\n", query);
+ fprintf(fp, "-T dn,ace -C US-ASCII %s\r\n", query);
} else if (strcmp(hostname, "dk" QNICHOST_TAIL) == 0) {
- fprintf(sfo, "--show-handles %s\r\n", query);
+ fprintf(fp, "--show-handles %s\r\n", query);
} else {
- fprintf(sfo, "%s\r\n", query);
+ fprintf(fp, "%s\r\n", query);
}
- fflush(sfo);
+ fflush(fp);
nhost = NULL;
- while ((buf = fgetln(sfi, &len)) != NULL) {
+ while ((buf = fgetln(fp, &len)) != NULL) {
while (len > 0 && isspace((unsigned char)buf[len - 1]))
buf[--len] = '\0';
printf("%.*s\n", (int)len, buf);
@@ -350,6 +349,7 @@ whois(const char *query, const char *hostname, int flags)
}
}
}
+ fclose(fp);
if (nhost != NULL) {
whois(query, nhost, 0);
free(nhost);