From f853dfb8a1c1c9f048eacc2f8ba502a37e9525ff Mon Sep 17 00:00:00 2001 From: Steven Edwards Date: Mon, 21 Jan 2002 23:13:45 +0000 Subject: [PATCH] BSD 4.x whois client for win32. svn path=/trunk/; revision=2542 --- rosapps/net/whois/makefile | 20 +++++ rosapps/net/whois/whois.c | 175 +++++++++++++++++++++++++++++++++++++ rosapps/net/whois/whois.rc | 39 +++++++++ 3 files changed, 234 insertions(+) create mode 100644 rosapps/net/whois/makefile create mode 100644 rosapps/net/whois/whois.c create mode 100644 rosapps/net/whois/whois.rc diff --git a/rosapps/net/whois/makefile b/rosapps/net/whois/makefile new file mode 100644 index 00000000000..f43684b0be2 --- /dev/null +++ b/rosapps/net/whois/makefile @@ -0,0 +1,20 @@ + +PATH_TO_TOP=../../../reactos + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = whois + +TARGET_SDKLIBS = ws2_32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_GCCLIBS = iberty + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/net/whois/whois.c b/rosapps/net/whois/whois.c new file mode 100644 index 00000000000..d79397b95ce --- /dev/null +++ b/rosapps/net/whois/whois.c @@ -0,0 +1,175 @@ +/* + * Copyright (c) 1980, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * 8/1/97 - Ted Felix + * Ported to Win32 from 4.4-BSDLITE2 from wcarchive. + * Added WSAStartup()/WSACleanup() and switched from the + * more convenient fdopen()/fprintf() to send()/recv(). + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright (c) 1980, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +static char sccsid[] = "@(#)whois.c 8.1 (Berkeley) 6/6/93"; +#endif /* not lint */ + +#include +/*#include */ +#include +/*#include */ +/*#include */ +#include + +//#include +#include +#include + +#define NICHOST "whois.internic.net" + +void usage(); +void leave(int iExitCode); + +void main(int argc, char **argv) +{ + extern char *optarg; + extern int optind; + char ch; + struct sockaddr_in sin; + struct hostent *hp; + struct servent *sp; + int s; + char *host; + WORD wVersionRequested; + WSADATA wsaData; + int err; + + host = NICHOST; + while ((ch = (char)getopt(argc, argv, "h:")) != EOF) + switch((char)ch) { + case 'h': + host = optarg; + break; + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (!argc) + usage(); + + /* Start winsock */ + wVersionRequested = MAKEWORD( 1, 1 ); + err = WSAStartup( wVersionRequested, &wsaData ); + if ( err != 0 ) + { + /* Tell the user that we couldn't find a usable */ + /* WinSock DLL. */ + fprintf(stderr, "WSAStartup failed\n"); + return; + } + + hp = gethostbyname(host); + if (hp == NULL) { + (void)fprintf(stderr, "whois: %s: ", host); + leave(1); + } + host = hp->h_name; + + s = socket(hp->h_addrtype, SOCK_STREAM, 0); + if (s < 0) { + perror("whois: socket"); + leave(1); + } + + bzero(/*(caddr_t)*/&sin, sizeof (sin)); + sin.sin_family = hp->h_addrtype; + if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + perror("whois: bind"); + leave(1); + } + + bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length); + sp = getservbyname("whois", "tcp"); + if (sp == NULL) { + (void)fprintf(stderr, "whois: whois/tcp: unknown service\n"); + leave(1); + } + + sin.sin_port = sp->s_port; + + /* have network connection; identify the host connected with */ + (void)printf("[%s]\n", hp->h_name); + + if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + fprintf(stderr, "whois: connect error = %d\n", WSAGetLastError()); + leave(1); + } + + /* WinSock doesn't allow using a socket as a file descriptor. */ + /* Have to use send() and recv(). whois will drop connection. */ + + /* For each request */ + while (argc-- > 1) + { + /* Send the request */ + send(s, *argv, strlen(*argv), 0); + send(s, " ", 1, 0); + argv++; + } + /* Send the last request */ + send(s, *argv, strlen(*argv), 0); + send(s, "\r\n", 2, 0); + + /* Receive anything and print it */ + while (recv(s, &ch, 1, 0) == 1) + putchar(ch); + + leave(0); +} + +void usage() +{ + (void)fprintf(stderr, "usage: whois [-h hostname] name ...\n"); + leave(1); +} + +void leave(int iExitCode) +{ + WSACleanup(); + exit(iExitCode); +} \ No newline at end of file diff --git a/rosapps/net/whois/whois.rc b/rosapps/net/whois/whois.rc new file mode 100644 index 00000000000..76c16b221f6 --- /dev/null +++ b/rosapps/net/whois/whois.rc @@ -0,0 +1,39 @@ +#include +#include + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION RES_UINT_FV_MAJOR,RES_UINT_FV_MINOR,RES_UINT_FV_REVISION,RES_UINT_FV_BUILD + PRODUCTVERSION RES_UINT_PV_MAJOR,RES_UINT_PV_MINOR,RES_UINT_PV_REVISION,RES_UINT_PV_BUILD + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", RES_STR_COMPANY_NAME + VALUE "FileDescription", "ReactOS TCP/IPv4 Win32 Whois\0" + VALUE "FileVersion", RES_STR_FILE_VERSION + VALUE "InternalName", "ping\0" + VALUE "LegalCopyright", RES_STR_LEGAL_COPYRIGHT + VALUE "OriginalCopyright", "Steven Edwards (Isolation@users.sourceforge.net)\0" + VALUE "OriginalFilename", "whois.exe\0" + VALUE "ProductName", RES_STR_PRODUCT_NAME + VALUE "ProductVersion", RES_STR_PRODUCT_VERSION + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END +