<p>This may be a non-issue, but I have been using <code>sip_resolvehost</code> in an attempt to create fall-through scenarios based on protocol preference, so I am just trying to understand the logic.</p>

<p>When a protocol is specified (<code>tls</code> for example, but a port is omitted when calling <code>sip_resolvehost</code>, an attempt is made to resolve the SRV record (<code>_sips._tcp.domain.com</code>).  If the SRV record does not exist, it simply tries to resolve the A record for the domain, but then preserves the attempted protocol and default port for that protocol in the return.</p>

<p>Here is a pseudo example of the flow:</p>

<p>1) sip_resolvehost(*name="opensips.org", *port=0, *protocol=PROTO_TLS)<br>
2) attempt to find srv record _sips._tcp.opensips.org<br>
3) no record exists<br>
4) set the port to 5061 (the default for PROTO_TLS)<br>
5) resolve the A record for opensips.org<br>
6) return the results</p>

<p>It seems it would be better, if falling through to an A (or AAAA) record to set the port and protocol to a default:</p>

<pre><code>diff --git a/resolve.c b/resolve.c
index 86ac6e5..8a5686c 100644
--- a/resolve.c
+++ b/resolve.c
@@ -1835,7 +1835,7 @@ do_srv:
                LM_WARN("domain name too long (%d),"
                        " unable to perform SRV lookup\n", name-&gt;len);
                /* set defaults */
-               if (port) *port = (is_sips)?SIPS_PORT:SIP_PORT;
+                if (port) *port = SIP_PORT;
                goto do_a;
        }

@@ -1876,7 +1876,7 @@ do_srv:
        LM_DBG("no valid SRV record found for %s, trying A record lookup...\n",
                tmp);
        /* set default port */
-       if (port) *port = protos[*proto].default_port;
+       if (port) *port = SIP_PORT;

 do_a:
        /* do A record lookup */
</code></pre>

<p>Or, if requesting a <strong>specific</strong> protocol, which was <strong>not</strong> found, then return 0 so a decision could be made upstream.</p>

<p>I may be way off base, just trying to see if this was the intended result.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/OpenSIPS/opensips/issues/482">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AFOcie90Iyi6kWJMfhjsAiHxRtZ2oiPIks5oD9PxgaJpZM4EK8Cp.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
  <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
    <link itemprop="url" href="https://github.com/OpenSIPS/opensips/issues/482"></link>
    <meta itemprop="name" content="View Issue"></meta>
  </div>
  <meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>