#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/signal.h>
#include <errno.h>
#include "check_neocast.h"

extern int dig_func(int , char **, int *);

void *thread_dig_job(void *arg)
{
	char *paraop[512];
	int result, i;
	int ancount = 0;

	paraop[0] = (char *)malloc(512);
	paraop[1] = (char *)malloc(512);
	paraop[2] = (char *)malloc(512);
	memset(paraop[0], 0, 512);
	memset(paraop[1], 0, 512);
	memset(paraop[2], 0, 512);

	strncpy(paraop[0], "dig", 512);
	strncpy(paraop[1], "@ns1.ktics.co.kr", 512);
	strncpy(paraop[2], "vol2-hangame.ktics.co.kr", 512);

	result = dig_func(3, paraop, &ancount);

	fprintf(stderr, "\n\n (shared_num : %d) ------------Result : %d\n", (int)arg, result);
	fprintf(stderr, "------------ANSWER: %d\n", ancount);

	for (i = 0; i < 3; i++)
		free(paraop[i]);

	pthread_exit((void *)NULL);
	return;
}

int main()
{
	void *thread_dig_job(void *);
	int shared_num = 777;

	for ( ; ; )
	{
		pthread_t thrid;

		pthread_create(&thrid, NULL, &thread_dig_job, (void *)shared_num);
		pthread_join(thrid, NULL);
		sleep(2);
	}

	return 0;
}
