<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi.</p>
<p><br>
</p>
<p>Nowadays I'm having problems to take right control of SIP messages, in a situation with user agents present in the LAN and WAN (some of them are behind NAT, to the point of view of OpenSIPS).</p>
<p>To control everything, I'm using local domain and public domain registered in the Domain table. In addiction I intend to implement the following algorithm:</p>
<p><br>
</p>
<br>
<p>If message == SIP INVITE </p>
<p>{</p>
<p><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>//Tries to guess if client's request originated behind a nat. The parameter determines what heuristics is used</p>
<p><span>&nbsp;&nbsp;&nbsp; </span>// <span class="x_emphasis"><em>2</em></span> - the &quot;received&quot; test is used: address in Via is compared against source IP address of signaling .</p>
<p><span>&nbsp;&nbsp;&nbsp; </span>// <span class="x_emphasis"><em>32</em></span> - address in Contact is compared against source IP address of signaling.<br>
</p>
<p><span>&nbsp;&nbsp;&nbsp; </span>If ( ! nat_uac_test(2 &#43; 32))</p>
<p><span>&nbsp;&nbsp;&nbsp; </span>{</p>
<p><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp; </span>//caller is in local network</p>
<p><br>
</p>
<p><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 111, 201);">If callee is behind a NAT from the point of view of opensips</span></span></p>
<p><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp; </span>{</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; avp_db_query(&quot;select domain from domain where attrs = public&quot;, &quot;$avp(DOMAIN)&quot;);<br>
</p>
<p><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp; </span>set_advertised_address (&quot;$avp(DOMAIN));<br>
</p>
<p><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp; </span>}</p>
<p><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp; </span>else</p>
<p><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp; </span>{</p>
<p><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;avp_db_query(&quot;select domain from domain where attrs = local&quot;, &quot;$avp(DOMAIN)&quot;);<br>
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp; </span>set_advertised_address (&quot;$avp(DOMAIN));</span><br>
</p>
<p><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp; </span>}<br>
</p>
<p><span>&nbsp;&nbsp;&nbsp; </span>}</p>
<p><span>&nbsp;&nbsp;&nbsp; </span>else</p>
<p><span>&nbsp;&nbsp;&nbsp; </span>{</p>
<p><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;avp_db_query(&quot;select domain from domain where attrs = public&quot;, &quot;$avp(DOMAIN)&quot;);<br>
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;&nbsp; </span><span></span>set_advertised_address (&quot;$avp(DOMAIN));</span><br>
</p>
<p><span>&nbsp;&nbsp;&nbsp; </span>}<br>
</p>
<p>}</p>
<br>
<p>However, how can I know whether the callee is not in the same network area as the caller, so the callee is behind a NAT?</p>
<p><br>
</p>
<p>Any hint will be very helpful!<br>
</p>
<p><br>
</p>
<div id="Signature">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div class="BodyFragment"><font size="2">
<div class="PlainText">RODRIGO PIMENTA CARVALHO<br>
Inatel Competence Center<br>
Software<br>
Ph: &#43;55 35 3471 9200 RAMAL 979<br>
</div>
</font></div>
</div>
</div>
</div>
</body>
</html>