V
V
VBKesha2014-10-05 23:29:04
Domain Name System
VBKesha, 2014-10-05 23:29:04

Win32 how to get SRV DNS record in C/C++?

There was a need to get SRV records under Win32. What can be used for this? It is desirable that it be synchronous without any callback. Compatibility from Win2K is highly desirable, extreme case of XP and higher.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VBKesha, 2014-10-06
@VBKesha

Found it myself:

#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <Windns.h>


int main()
{
    DNS_STATUS status;
    PDNS_RECORD ret;
    status = DnsQuery("_xmpp-client._tcp.yandex.ru",
                        DNS_TYPE_SRV,
                        DNS_QUERY_STANDARD,
                        NULL,
                        &ret,
                        NULL);

    if(status == 0) {
        printf("SRV %s:%d\n", ret->Data.SRV.pNameTarget, ret->Data.SRV.wPort);
        DnsRecordListFree(ret, 0);
    } else {
        printf("Record not found.\n");
    }

    return 0;
}

DnsQuery

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question