/* main routine */
#include"fatfinger.h" /* includes & other stuff */
#include"functions.h" /* declared functions */

int main(int argc, char **argv)
{
	if(argc<3) heLp(argv[0]);

	int opt;
	char *hostname=argv[1],*username=argv[2],*userlist=NULL,*logfile=NULL;
	char *finger_Stuff;
	struct hostent *Host_struct;
	FILE *userlstfp,*logfilefp;

	if(!(Host_struct=gethostbyname(hostname)))
	{
		perror("gethostbyname()"); exit(EXIT_FAILURE);
	}

	while((opt=getopt(argc,argv,"f:l:"))!=EOF)
		switch(opt)
		{
			case 'f':
				userlist=optarg;
				break;
			case 'l':
				logfile=optarg;
				break;
			default:
				heLp(argv[0]);
		}

	printf("-+[ FatFinger - Remote user [enumeration & infogathering] tool.\n");
	printf("-+[ nitrous@danitrous\n");
	printf("-+[ www.danitrous.org\n\n");

	target.sin_family=AF_INET;
	target.sin_port=htons(79);
	target.sin_addr=*((struct in_addr *)Host_struct->h_addr);
	bzero(&target.sin_zero,8);

	if(userlist)
	{
		userlstfp=callme_if_file(userlist,READ);

		if(logfile) logfilefp=callme_if_file(logfile,WRITE);

		while(fgets(username,32,userlstfp))
		{
			finger_Stuff=finger(username);
			if(logfile)
				log_it(logfilefp,finger_Stuff);
		}

		if(logfile) fclose(logfilefp);
		fclose(userlstfp);
		exit(EXIT_SUCCESS);
	}

	if(logfile)
	{
		logfilefp=callme_if_file(logfile,WRITE);

		log_it(logfilefp,finger(username));

		fclose(logfilefp);
		exit(EXIT_SUCCESS);
	}

	finger(username);

	return 0;
}

