0

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.

zaplec
  • 1,681
  • 4
  • 23
  • 51

1 Answers1

1

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.

Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • I've tried to do the SRV query to several domains now and it seems that it's just random when some sites return the SRV record. The suggested `_nicname._tcp.us` first returned nothing, but after sometime it gave me an answer. The same happened when I tried to do the SRV query with `dig` and `nslookup`commands. I thought that every domain returns at least something when they get the SRV query. Also I found some other suggested sites like `_sip._udp_columbia.edu` and it behaves exactly the same way: Sometimes it returns the record and sometimes it doesn't. – zaplec Mar 02 '12 at 07:36