Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SRV record lookup with iPhone SDK

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

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

... (for example) you will receive a bunch of SRV records relating to different google chat servers..

Does anyone have any experience in this area and possibly know how to service this information (hostname, port, weight, priority) using the iPhone SDK? I have experimented with the Bonjour classes, but as yet have had no luck..

Thanks!

like image 995
adam Avatar asked Dec 17 '22 10:12

adam


1 Answers

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

See the Apple Developer Site for full API details.

I've included some (incomplete) sample code too:

#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'll need to provide your own callback function, and note that the rdata field sent to the callback is in wire-format, so you'll have to decode the raw data from the SRV record fields yourself.

like image 152
Alnitak Avatar answered Dec 24 '22 02:12

Alnitak