#include"DNS.h"


// dodac Dnsapi.lib
CString SprawdzNazwe(CString nazwaHosta, char * adresServeraDNS)
{
	PDNS_RECORD pDnsRecord;
	IN_ADDR ipaddr;
	CString wynik;
	wynik.Empty();

	PIP4_ARRAY pSrvList = (PIP4_ARRAY) LocalAlloc(LPTR,sizeof(IP4_ARRAY));
	pSrvList->AddrCount = 1;
	pSrvList->AddrArray[0] = inet_addr(adresServeraDNS);

	int odp = DnsQuery(nazwaHosta,DNS_TYPE_A,DNS_QUERY_STANDARD,pSrvList,&pDnsRecord,NULL);

	if(odp)
	{
		MessageBox(0,L"Błąd funkcji DnsQuery",L"",MB_OK);
	}
	else
	{
		ipaddr.S_un.S_addr = (pDnsRecord->Data.A.IpAddress);
		char * chAddr = inet_ntoa(ipaddr);
		int dlugosc = strlen(chAddr);
        wchar_t  wchAddr[16] = {'\0'};
		mbstowcs(wchAddr,chAddr,dlugosc);
		wynik.Append(wchAddr);
		DnsRecordListFree(pDnsRecord, DnsFreeRecordListDeep);
	}
	LocalFree(pSrvList);
	return wynik;
}