Skip to content

Instantly share code, notes, and snippets.

@yarshure
Created July 1, 2014 09:14
Show Gist options
  • Save yarshure/0943a357139cb5e37412 to your computer and use it in GitHub Desktop.
Save yarshure/0943a357139cb5e37412 to your computer and use it in GitHub Desktop.
iOS dns PTR record query
#include <dns_sd.h>
#include <resolv.h>
void DNSSD_API callback
(
DNSServiceRef sdRef,
DNSServiceFlags flags,
uint32_t interfaceIndex,
DNSServiceErrorType errorCode,
const char *fullname,
uint16_t rrtype,
uint16_t rrclass,
uint16_t rdlen,
const void *rdata,
uint32_t ttl,
void *context
);
void DNSSD_API callback
(
DNSServiceRef sdRef,
DNSServiceFlags flags,
uint32_t interfaceIndex,
DNSServiceErrorType errorCode,
const char *fullname,
uint16_t rrtype,
uint16_t rrclass,
uint16_t rdlen,
const void *rdata,
uint32_t ttl,
void *context
)
{
NSLog(@"queryCallback: flags == %d error code == %d", flags, errorCode);
char result[256]={0};
//memcpy(result, rdata, rdlen);
//NSString *a=[[NSString alloc] initWithBytes:rdata length:rdlen encoding:NSUTF8StringEncoding];
dn_expand(rdata, rdata + rdlen, rdata, result, 256);
NSLog(@"result %s",result);
}
int test()
{
DNSServiceRef sdRef;
DNSServiceErrorType res;
res=DNSServiceQueryRecord(
&sdRef, 0, 0,
"1.18.168.192.in-addr.arpa.",
kDNSServiceType_PTR,
kDNSServiceClass_IN,
callback,
NULL
);
DNSServiceProcessResult(sdRef);
DNSServiceRefDeallocate(sdRef);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment