In my app, I want to resolve an address with a DNS server address of my choice (the DNS isn't mine, I just want to resolve domain of my app with other dns server). i have try this code.
#include <dns.h>
#include <dns_sd.h>
#include <sys/socket.h>
static NSData * synchronousDNSQuery() {
NSData * result;
NSURL * confURL;
dns_handle_t dns;
uint8_t responseBuffer[4096];
struct sockaddr_storage fromAddr;
uint32_t fromAddrLen;
int32_t queryResult;
confURL = [[NSBundle mainBundle] URLForResource:@"resolv" withExtension:@"conf"];
dns = dns_open(confURL.fileSystemRepresentation);
fromAddrLen = sizeof(fromAddr);
queryResult = dns_query(
dns,
"example.com.",
kDNSServiceClass_IN,
kDNSServiceType_A,
(char *) responseBuffer,
sizeof(responseBuffer),
(struct sockaddr *) &fromAddr,
&fromAddrLen
);
if (queryResult > 0) {
result = [NSData dataWithBytes:responseBuffer length:(NSUInteger) queryResult];
NSLog(@"response %@ from %@",
result,
[NSData dataWithBytes:&fromAddr length:(NSUInteger) fromAddrLen]
);
} else {
result = nil;
NSLog(@"error");
}
dns_free(dns);
return result;
}
However, this code can not compile success .
here is the error message
Undefined symbols for architecture x86_64
_dns_free
_dns_open
_dns_query
how to resolve this compiler error? or Is there any other way to customize dns service?