4

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!

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
adam
  • 22,404
  • 20
  • 87
  • 119

3 Answers3

11

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.

Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • The above link is dead. Use this: https://developer.apple.com/library/mac/documentation/networking/conceptual/dns_discovery_api/Introduction.html – JaredH Aug 20 '14 at 02:56
  • Some additional information and utilization is [here](https://justanapplication.wordpress.com/category/ios/ios_api/dns_sd_api/dnsservicequeryrecord/) – malex Apr 09 '15 at 19:39
1

I think your best bet is to implement a DNS query tool using CFNetwork.

Try to read more about this here: http://developer.apple.com/documentation/Networking/Conceptual/CFNetwork/Introduction/chapter_1_section_1.html#//apple_ref/doc/uid/TP30001132-CH1-DontLinkElementID_24

Marius
  • 3,589
  • 3
  • 27
  • 30
0

Hmm, looks like I can't run system() on the Simulator or the device. I can run NSTask on the Simulator, but not the iPhone, and NSTask is not part of the Foundation framework.

The ISC BIND package has a BSD license. If feasible, perhaps relevant parts of the dig code could be wrapped into the project directly.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345