I'm trying to implement a simple DNS SRV query by using res_query
. My code for the res_query part is following:
char* target;
short* port;
union {
HEADER hdr;
u_char buf[1024];
} response;
ns_msg handle;
ns_rr rr;
u_char buf[256], *p;
int t, len, priority, weight;
if ((len = res_query(query, C_IN, ns_t_srv, (u_char *)&response, sizeof(response))) <0 ) {
cout << "res_query returned -1, no answer" << endl;
return 0;
}
This is just a part of the code, but I guess there's all the required things to do the res_query
. Every time I execute the SRV query, the res_query returns '-1', meaning it fails. Is the problem in my res_query or am I doing something else wrong?
I've tried to do the SRV query to www.example.com
.
res_query
will return -1 if no matching record is found.
Apart from that your code works fine for me, although OSX requires ns_c_in
instead of C_IN
.
Try testing with _nicname._tcp.us.
instead of www.example.com
.