delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/07/02/18:03:46

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
From: "Gerrit P. Haase" <gp AT familiehaase DOT de>
Organization: Esse keine toten Tiere
To: Bob Zimmerman <bobzim AT metaworld DOT com>
Date: Tue, 3 Jul 2001 00:04:08 +0200
MIME-Version: 1.0
Subject: Re: Whois
Reply-to: gp AT familiehaase DOT de
CC: cygwin AT cygwin DOT com
Message-ID: <3B410BF8.9587.64DDDB@localhost>
In-reply-to: <20010629072329.D37762@enteract.com>
X-mailer: Pegasus Mail for Win32 (v3.12cDE)

Bob Zimmerman schrieb am 2001-06-29, 7:23:

> Is there a port of WHOIS? 

I don't know who wrote it, i found it in the cygwin archives:

/*
 * Cygwin whois
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>

#define	NICHOST		"whois.internic.net"
#define	DNICHOST	"whois.nic.mil"
#define	GNICHOST	"whois.nic.gov"
#define	ANICHOST	"whois.arin.net"
#define	RNICHOST	"whois.ripe.net"
#define	PNICHOST	"whois.apnic.net"
#define RUNICHOST   "whois.ripn.net"
#define DENICHOST   "whois.nic.de"
#define	WHOIS_PORT	43

static void usage (void);

int
main(int argc, char **argv)
{
	register FILE *sfi, *sfo;
	register int ch;
	struct sockaddr_in sin;
	struct hostent *hp;
	struct servent *sp;
	int s;
	char *host;

#ifdef	SOCKS
	SOCKSinit(argv[0]);
#endif

	host = NICHOST;
	while ((ch = getopt(argc, argv, "badgh:prR")) != -1)
		switch((char)ch) {
		case 'b':
			host = DENICHOST;
			break;
		case 'a':
			host = ANICHOST;
			break;
		case 'd':
			host = DNICHOST;
			break;
		case 'g':
			host = GNICHOST;
			break;
		case 'h':
			host = optarg;
			break;
		case 'p':
			host = PNICHOST;
			break;
		case 'r':
			host = RNICHOST;
			break;
		case 'R':
			host = RUNICHOST;
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (!argc)
		usage();

	s = socket(PF_INET, SOCK_STREAM, 0);
	if (s < 0){
		fprintf(stderr, "%s: %s", "socket", strerror(errno));
		return -1;
	}

	memset(&sin, 0, sizeof sin);
/*	sin.sin_len = sizeof sin; */
	sin.sin_family = AF_INET;
	
	hp = gethostbyname(host);
	if (hp == NULL){
		fprintf(stderr, "%s: %s", host, "gethostbyname() failed\n");
		return -2;
	}
	host = (char *)hp->h_name;
	sin.sin_addr = *(struct in_addr *)hp->h_addr_list[0];

	sp = getservbyname("whois", "tcp");
	if (sp == NULL)
		sin.sin_port = htons(WHOIS_PORT);
	else
		sin.sin_port = sp->s_port;

	if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0){
		fprintf(stderr, "%s: %s", "connect", strerror(errno));
		return -3;
	}

	sfi = fdopen(s, "r");
	sfo = fdopen(s, "w");
	if (sfi == NULL || sfo == NULL){
		fprintf(stderr, "%s: %s", "fdopen", strerror(errno));
		return -5;
	}
	while (argc-- > 1)
		(void)fprintf(sfo, "%s ", *argv++);
	(void)fprintf(sfo, "%s\r\n", *argv);
	(void)fflush(sfo);
	while ((ch = getc(sfi)) != EOF)
		putchar(ch);
	exit(0);
}

static void
usage()
{
	fprintf(stderr, "usage: whois [-badgprR] [-h hostname] name ...\n");
	exit(-5);
}


/* gph */

-- 
=^..^=

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019