


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <dos.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>


main(int argc, char *argv[])
	{
	int s,n;
	FILE *fp;
	FILE *sin,*sout;
	struct sockaddr_in servaddr;
	struct hostent *he;
	int bit,writebit,readbit,exceptbit=0,iobit;
	char *hostname;
	char sendstring[128];
	char buff[1024];
	int bytes;
	struct timeval t;
	char *username;

	printf("%d %d",'\n','\r');

	return;

	if (argc!=2)
		{
		printf("FINGER v1.0 (c) 1994 Takoyaki Software Ltd.\n");
		printf("Written by Dylan Cuthbert.\n\n");
		printf("Mail bugs/requests to one or all of the following:\n");
		printf("  dyl@takoyaki.demon.co.uk\n");
		printf("  dyl@cix.compulink.co.uk\n");
		printf("  dyl@twics.co.jp\n");
		printf("  dyl@bix.com\n");
		printf("  dylan@argonaut.com\n\n");
		printf("Other software is available from ftp://takoyaki.demon.co.uk.\n\n");
		printf("Usage: FINGER <name>@<host> for user information.\n");
		printf("       FINGER <host> for list of online users.\n");
		exit(10);
		}

	if (!(hostname = strchr(argv[1],'@')))
		{
		hostname = argv[1];
		username = "";
		}
	else
		{
		*hostname++ = '\0';
		username = argv[1];
		}

	if (!so_init()) printf("Socket interface failed to initialise.\n");

	s = socket(AF_INET, SOCK_STREAM, 0);

	if (!(he = gethostbyname(hostname)))
		{
		printf("Unable to connect to %s.\n",hostname);
		return;
		}

	servaddr.sin_family = he->h_addrtype;
	servaddr.sin_port = htons(79);
	memcpy(&servaddr.sin_addr,he->h_addr_list[0],he->h_length);

	printf("Trying... %s (%s)\n",hostname,inet_ntoa(servaddr.sin_addr));

	if (connect(s, (struct sockaddr *)(&servaddr),sizeof(servaddr)) == -1)
		{
		printf("Failed to connect.\n",hostname);
		exit(30);
		}

	iobit = writebit = bit = 1L<<s;
	readbit = 0;
	t.tv_sec = 10;
	t.tv_usec = 0;
	iobit = select(s+1,(struct fd_set *)&readbit,(struct fd_set *)&writebit,(struct fd_set *)&exceptbit,&t);	/* Get read/write status */

	if (iobit>0)
		{
		sprintf(sendstring,"%s\r\n",username);
		if (send(s,sendstring,strlen(sendstring),0)<=0)
			{
			printf("Connection broken.\n");
			}
		}
	else printf("Connection broken.\n");


	while (1)
		{
		iobit = readbit = bit = 1L<<s;
		writebit = 0;
		t.tv_sec = 10;
		t.tv_usec = 0;
		iobit = select(s+1,(struct fd_set *)&readbit,(struct fd_set *)&writebit,(struct fd_set *)&exceptbit,&t);	/* Get read/write status */

		if (iobit>0)
			{
			bytes = recv(s,buff,sizeof(buff)-1,0);

			if (bytes<=0) break;
			buff[bytes] = '\0';
			printf("%s",buff);
			}
		}
	
	so_close(s);

	so_exit();
	}

