Attached is a patch to make ares_parse_srv_reply successfully parse an SRV reply containing non-SRV answers, such as CNAMEs. This code makes no attempt to follow or validate the CNAME chain, it just skips over non-SRV answers. This is probably enough for simple replies.
-- Larry Lansing It's Google: Not only do we re-invent the wheel, we vulcanize our own rubber.
==== //depot/google3/third_party/ares/ares_parse_srv_reply.c#3 - /home/llansing/src/discovery/8/google3/third_party/ares/ares_parse_srv_reply.c ==== --- /tmp/g4-20711/cache/depot/google3/third_party/ares/ares_parse_srv_reply.c#3 2009-11-25 13:37:26.000000000 -0800 +++ /home/llansing/src/discovery/8/google3/third_party/ares/ares_parse_srv_reply.c 2009-11-25 13:52:38.743423000 -0800 @@ -140,23 +140,21 @@ srv_last = srv_curr; srv_curr->priority = ntohs (*((unsigned short *)aptr)); - aptr += sizeof(unsigned short); - srv_curr->weight = ntohs (*((unsigned short *)aptr)); - aptr += sizeof(unsigned short); - srv_curr->port = ntohs (*((unsigned short *)aptr)); - aptr += sizeof(unsigned short); + srv_curr->weight = ntohs (*((unsigned short *)(aptr + 2))); + srv_curr->port = ntohs (*((unsigned short *)(aptr + 4))); - status = ares_expand_name (aptr, abuf, alen, &srv_curr->host, &len); + status = ares_expand_name (aptr + 6, abuf, alen, &srv_curr->host, + &len); if (status != ARES_SUCCESS) break; - - /* Move on to the next record */ - aptr += len; } /* Don't lose memory in the next iteration */ free (rr_name); rr_name = NULL; + + /* Move on to the next record */ + aptr += rr_len; } if (hostname)