MX レコードの取得(mx.cpp for Win32)

#include <windows.h>
#include <windns.h>
#include <cstdio>

#pragma comment(lib, "dnsapi.lib")

bool get_mx(char* server)
{

	DNS_RECORD* pQueryResultsSet = NULL;
	if (::DnsQuery(
		server,
		DNS_TYPE_MX,
		DNS_QUERY_STANDARD,
		NULL,
		&pQueryResultsSet,
		NULL)){

		return false;
	}

	DNS_RECORD* p = pQueryResultsSet;
	for (int i = 0; ; ++i){

		if (DNS_TYPE_MX != p->wType){

			break;
		}
		printf("%s(%d): %s\n", p->pName, i, p->Data.MX.pNameExchange);
		if (NULL == p->pNext){

			break;
		}
		p = p->pNext;
	}

	GlobalFree(pQueryResultsSet);

	return true;
}

int main(int argc, char* argv[])
{

	(void)get_mx("nec.co.jp");
	getchar();

	return 0;
}

BACK


View My Stats