diff --git a/include/re_dns.h b/include/re_dns.h index 4b33915be..4164c6a14 100644 --- a/include/re_dns.h +++ b/include/re_dns.h @@ -224,6 +224,7 @@ void dnsc_cache_flush(struct dnsc *dnsc); void dnsc_cache_max(struct dnsc *dnsc, uint32_t max); void dnsc_getaddrinfo(struct dnsc *dnsc, bool active); bool dnsc_getaddrinfo_enabled(struct dnsc *dnsc); +bool dnsc_has_srv(const struct dnsc *dnsc); /* DNS System functions */ diff --git a/src/dns/client.c b/src/dns/client.c index 716ca3302..eb4094e79 100644 --- a/src/dns/client.c +++ b/src/dns/client.c @@ -975,9 +975,16 @@ static int query(struct dns_query **qp, struct dnsc *dnsc, uint8_t opcode, struct dnshdr hdr; int err = 0; - if (!dnsc || !name || !srvv || !srvc || !(*srvc)) + if (!dnsc || !name) return EINVAL; + if ((!srvv || !srvc || !(*srvc)) && + (!dnsc->conf.getaddrinfo || + (type != DNS_TYPE_A && type != DNS_TYPE_AAAA))) { + + return EINVAL; + } + if (DNS_QTYPE_AXFR == type) proto = IPPROTO_TCP; @@ -1401,3 +1408,16 @@ bool dnsc_getaddrinfo_enabled(struct dnsc *dnsc) return dnsc->conf.getaddrinfo; } + + +/** + * Return whether any DNS servers are available + * + * @param dnsc DNS Client + * + * @return true if DNS servers are available, false otherwise + */ +bool dnsc_has_srv(const struct dnsc *dnsc) +{ + return dnsc->srvc != 0; +} diff --git a/src/sip/request.c b/src/sip/request.c index 017db0e7c..0dfe23563 100644 --- a/src/sip/request.c +++ b/src/sip/request.c @@ -737,7 +737,10 @@ static int sip_request_send(struct sip_request *req, struct sip *sip, return err; } } - else if (route->port) { + else if (route->port || + (req->tp_selected && + !dnsc_has_srv(req->sip->dnsc) && + dnsc_getaddrinfo_enabled(req->sip->dnsc))) { req->port = sip_transp_port(req->tp, route->port); err = addr_lookup(req, req->host);