#ifndef FALSE
#define FALSE 0
#define TRUE (!(FALSE))
#endif
#include "defines.h"
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

#include <string.h>
#include <stdarg.h>
#include <time.h>
#include "../sam/tcplib.h"
#include "dns_use.h"
static int start;
void lookup_ans(int n, char *s)
{
	printf("======> Answer %d [%d] %s\n",time(NULL)-start,n,s);
}
static char dnshost[BFSZ];
void main(int argc, char *argv[])
{
	char bf[2000];
	int i;
	int mchan;
	int n=0;
	int ask_again = FALSE;
	start = time(NULL);
	if (argc==1) {
		printf("Usage: dnstest domain.name second.name [-file xxx.itm] [-i]\n");
		printf("Usage: dnstest -single\n");
		printf("Usage: dnstest -compare\n");
		printf("Usage: dnstest domain.name -dns 1.2.3.4\n");
		printf("Usage: dnstest domain.name -dns 1.2.3.4 -nfails 7\n");
		return;
	}
	tcp_init(printf);
	bk_init(printf,printf,printf);
	for (i=1; i<argc; i++) {
		if (strcmp(argv[i],"-i")==0)	{ask_again = TRUE;}
		else if (strcmp(argv[i],"-dns")==0)	{strcpy(dnshost,argv[++i]);}
		else mchan = mx_lookup_que(argv[i],lookup_ans,i);
	}
	printf("Dns (%s)\n",dnshost);
	if (strlen(dnshost)>0) bk_clear_nameserver();
	bk_add_nameserver(dnshost);

	for (;TRUE;) {
		mx_bkgnd(mchan,100);
		n++;
//		Sleep(100);
		if (n==100) if (ask_again) {
			n = 0;
			printf("Host to lookup "); gets(bf);
			mx_lookup_que(bf,lookup_ans,1);
		}
	}
}
static FILE *fin,*fout;
char *asked[100];
void lookup_f(int n, char *s)
{
	static int xx;
	xx++;
	printf("%s %s\n",asked[n],s);
	fprintf(fout,"%s %s\n",asked[n],s);
	fflush(fout);
}
