sock: choose target with the lowest priority

sock_srv_lookup chose the last target in the answer section. But it must
choose one with the lowest priority it can reach (due to RFC2052).
This commit is contained in:
Dmitry Podgorny
2015-10-15 17:49:44 +03:00
parent 182803926b
commit 4cc9ba79c4

View File

@@ -837,6 +837,7 @@ int sock_srv_lookup(const char *service, const char *proto,
#else
if (!set) {
unsigned char buf[65535];
unsigned short min;
int len;
if ((len = res_query(fulldomain, C_IN, T_SRV, buf, 65535)) > 0) {
@@ -853,22 +854,22 @@ int sock_srv_lookup(const char *service, const char *proto,
netbuf_get_dnsquery_question(buf, 65536, &offset, &question);
}
min = 65535;
for (i = 0; i < header.ancount; i++) {
netbuf_get_dnsquery_resourcerecord(buf, 65536, &offset, &rr);
if (rr.type == 33) {
struct dnsquery_srvrdata *srvrdata = &(rr.rdata);
snprintf(resulttarget, resulttargetlength, "%s",
srvrdata->target);
*resultport = srvrdata->port;
set = 1;
if (srvrdata->priority < min || !set) {
snprintf(resulttarget, resulttargetlength, "%s",
srvrdata->target);
*resultport = srvrdata->port;
set = 1;
min = srvrdata->priority;
}
}
}
for (i = 0; i < header.ancount; i++) {
netbuf_get_dnsquery_resourcerecord(buf, 65536, &offset, &rr);
}
}
}
#endif