<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">On 25.10.2022 19:11, Ross McKillop via
Users wrote:<br>
</div>
<blockquote type="cite"
cite="mid:B67B901C-D8E2-4385-8CC8-775128AD1518@rsmck.co.uk">
<div class=""><font class="" color="#000000"><br class="">
</font></div>
<div class=""><font class="" color="#000000">I would have expected
$socket_in(port) to contain the actual port that was used
(53235) and $socket_in(advertised_port) to contain the port
that is advertised as the listening port for that socket (e.g.
7700) - however $socket_in(port) contains 7700 and
$socket_in(advertised_port) is null. </font></div>
<div class=""><font class="" color="#000000"><br class="">
</font></div>
<div class=""><font class="" color="#000000">Is this the intended
behaviour and, if so, is there any way to access the *actual*
destination port that was used (even if it’s ephemeral)?</font></div>
<div class=""><font class="" color="#000000"><br class="">
</font></div>
<div class=""><font class="" color="#000000">Any advice anyone can
offer would be much appreciated :)</font></div>
</blockquote>
<p><font face="monospace">Hey, Ross!</font></p>
<p><font face="monospace">Regarding $socket: there is the READ-ONLY
$socket_in [1], concerning the ingress traffic and $socket_out
[2], READ-WRITE and fully optional, controlling the egress
traffic. And an OpenSIPS listener MAY additionally have an
"advertised" component, for scenarios where it's sitting behind
a NAT.<br>
</font></p>
<p><font face="monospace">I can't think of many good ways of
fetching/printing the ephemeral source port allocated by the
Operating System for a TCP connection:</font></p>
<p><font face="monospace">* Request time: you cannot print it while
processing the INVITE since the source port is not even
allocated until you run the very last t_relay()<br>
* Reply time: replies will be routed using topmost Via, so
*maybe* you have a chance at printing this port, by looking at
the topmost Via header (OpenSIPS-generated), using
transformations [3]. Even if OpenSIPS strips this header during
loose_route(), you should still have access to it thanks to the
"SIP message lumps" lazy evaluation mechanism.<br>
</font></p>
<p><font face="monospace">Still: may I ask why you need the "egress
ephemeral source port" information? Maybe there is an
alternative to the problem itself!<br>
</font></p>
<p><font face="monospace">[1]:
<a class="moz-txt-link-freetext" href="https://opensips.org/Documentation/Script-CoreVar-3-4#socket_in">https://opensips.org/Documentation/Script-CoreVar-3-4#socket_in</a><br>
[2]:
<a class="moz-txt-link-freetext" href="https://opensips.org/Documentation/Script-CoreVar-3-4#socket_out">https://opensips.org/Documentation/Script-CoreVar-3-4#socket_out</a><br>
[3]: <a class="moz-txt-link-freetext" href="https://www.opensips.org/Documentation/Script-Tran-3-4">https://www.opensips.org/Documentation/Script-Tran-3-4</a><br>
</font></p>
<p><font face="monospace">Best regards,<br>
</font></p>
<pre class="moz-signature" cols="72">--
Liviu Chircu
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/liviuchircu">www.twitter.com/liviuchircu</a> | <a class="moz-txt-link-abbreviated" href="http://www.opensips-solutions.com">www.opensips-solutions.com</a>
OpenSIPS eBootcamp 5-16 Dec | <a class="moz-txt-link-abbreviated" href="http://www.opensips.org/training">www.opensips.org/training</a></pre>
</body>
</html>