yasirmturk
yasirmturk

Reputation: 1954

How to get All DNS records with iOS SDK

i am looking for so long to get a solution regarding getting DNS records by using iOS SDK???

i am able to resolve ip addesses against host name here but that is not what i want... i need to get all DNS records including PTR, Name, NS, MX, CNAME etc.. please your help or a code snippet is very much appreciated

Upvotes: 1

Views: 2646

Answers (2)

Drmorgan
Drmorgan

Reputation: 539

In case others come across this in their search and want to see more details:

I found it to be from #include <dns_sd.h>

// domain is a NSString
DNSServiceRef sdRef;
DNSServiceQueryRecord(&sdRef, 0, 0, [domain UTF8String], kDNSServiceType_MX, kDNSServiceClass_IN, callBack, NULL);
DNSServiceProcessResult(sdRef);
DNSServiceRefDeallocate(sdRef);

This is for if you wanted the MX records for a domain. callBack is a C method

static void callBack(
                         DNSServiceRef       sdRef,
                         DNSServiceFlags     theFlags,
                         uint32_t            theInterfaceIndex,
                         DNSServiceErrorType theErrorCode,
                         const char*         theName,
                         uint16_t            theType,
                         uint16_t            theClass,
                         uint16_t            theDataLength,
                         const void*         theData,
                         uint32_t            theTTL,
                         void*               theContext)
{
    // do your magic here...
}

The callback method is called once it finds a response, note that you can receive multiple callbacks. For example when checking the domain of my office email I received 7 call backs.

Upvotes: 1

yasirmturk
yasirmturk

Reputation: 1954

Try exploring

DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
    (
    DNSServiceRef                       *sdRef,
    DNSServiceFlags                     flags,
    uint32_t                            interfaceIndex,
    const char                          *fullname,
    uint16_t                            rrtype,
    uint16_t                            rrclass,
    DNSServiceQueryRecordReply          callBack,
    void                                *context  /* may be NULL */
    );

from

#include <dns_util.h>

I have actually written my objective-c wrapper using this function for all kinds of DNS records..but i cant get time to publish it somewhere

Upvotes: 2

Related Questions