Search for SRV Records from iPhone SDK

In a Windows or Mac OS X terminal, if you type ...

nslookup -type=SRV _xmpp-server._tcp.gmail.com 

... (for example) you will get a bunch of SRV records related to various google chat servers.

Does anyone have experience in this area and perhaps know how to service this information (host name, port, weight, priority) using the iPhone SDK? I experimented with Bonjour classes, but so far no luck.

Thanks!

+4
source share
3 answers

I believe that you need to use the DNSServiceDiscovery framework. I do not have an iPhone SDK, but a Google search suggests that it is available on the iPhone.

See Apple Developer Website for full API details .

I have included some (incomplete) sample code:

 #include <dns_sd.h> int main(int argc, char *argv[]) { DNSServiceRef sdRef; DNSServiceErrorType res; DNSServiceQueryRecord( &sdRef, 0, 0, "_xmpp-server._tcp.gmail.com", kDNSServiceType_SRV, kDNSServiceClass_IN, callback, NULL ); DNSServiceProcessResult(sdRef); DNSServiceRefDeallocate(sdRef); } 

You will need to provide your own callback function and note that the rdata field sent to the callback is in a wired format, so you will have to decode the raw data from the SRV record fields yourself.

+11
source

Hmm, it seems like I can't run system() on a simulator or device. I can run NSTask on a simulator, but not an iPhone, and NSTask not part of the Foundation structure.

The ISC BIND package is BSD licensed. If possible, it is possible that the relevant parts of the dig code can be directly transferred to the project.

0
source

All Articles