<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi,<br>
    <br>
    This is a question for the sake of comprehension, as I actually
    solved the problem with a workaround.<br>
    <br>
    I am trying to get Kamailio working with a third party SIP provider.
    The SIP server of this provider pings my Kamailio with OPTIONS
    messages. Being located in a sub-network, the SIP messages are
    relayed to a router (not a SIP router, just a gateway to the
    Internet) which is not listening/sending on port 5060 but on 13377.
    When Kamailio answer to OPTIONS, it send back the message to the
    router on the port 5060 which is wrong. Here is the topology:<br>
    <br>
    <font face="Courier New, Courier, monospace"><b>Kamailio</b>                      
      <b>Router</b>                       <b>SIP Server</b><br>
      <i>my.sip.domain               174.37.217.1                  
        197.17.144.4</i><br>
         |                              | ? <--------------------
      5060 |<br>
         | 5060 <---------------- 13377
      |                              |<br>
         | 5060 ----------------−> 5060
      |                              |<br>
         |                              | X                            |<br>
      <br>
      <font face="sans-serif">You can see that, Kamailio answers to the
        wrong port, but I think this is somewhat coherent since the SIP
        message says that the port 5060 is in use. But still, I would
        have liked that the correct port was used: </font><br>
      <br>
      <b>Kamailio</b>                       <b>Router</b>
                            <b>SIP Server</b></font><font face="Courier
      New, Courier, monospace"><font face="Courier New, Courier,
        monospace"><br>
        <i>my.sip.domain               174.37.217.1                  
          197.17.144.4<br>
        </i></font>   |                              | ?
      <-------------------- 5060 |<br>
         | 5060 <---------------- 13377
      |                              |<br>
         | 5060 ---------------−> 13377
      |                              |<br>
         |                              | ? -------------------->
      5060 |</font><br>
    <br>
    But I do not understand where Kamailio is supposed to find the
    correct port. Below are the transport frames, and SIP frames.<br>
    <br>
    Kamailio receives:<br>
    <br>
    <font face="Courier New, Courier, monospace">Internet Protocol
      Version 4, Src: 174.37.217.1 (174.37.217.1), Dst: 172.16.8.61
      (172.16.8.61)<br>
          Source: 174.37.217.1 (174.37.217.1)<br>
          Destination: 172.16.8.61 (172.16.8.61)<br>
      User Datagram Protocol, Src Port: 13377 (13377), Dst Port: sip
      (5060)<br>
          Source port: 13377 (13377)<br>
          Destination port: sip (5060)<br>
      <br>
      OPTIONS sip:my.sip.domain:5060 SIP/2.0<br>
      Via: SIP/2.0/UDP 197.17.144.4:5060;branch=z9hG4bKb9340cb29ba<br>
      From: <sip:197.17.144.4>;tag=1797904074<br>
      To: <sip:my.sip.domain><br>
      Date: Mon, 10 Aug 2015 10:01:51 GMT<br>
      Call-ID: <a class="moz-txt-link-abbreviated" href="mailto:c7f38580-5c817680-b94-38512c6@197.17.144.4">c7f38580-5c817680-b94-38512c6@197.17.144.4</a><br>
      User-Agent: Cisco-CUCM10.5<br>
      CSeq: 101 OPTIONS<br>
      Contact: <sip:197.17.144.4:5060><br>
      Max-Forwards: 0<br>
      Content-Length: 0</font><br>
    <br>
    ...and then sends:<br>
    <br>
    <font face="Courier New, Courier, monospace">Internet Protocol
      Version 4, Src: 172.16.8.61 (172.16.8.61), Dst: 174.37.217.1
      (174.37.217.1)<br>
          Source: 172.16.8.61 (172.16.8.61)<br>
          Destination: 174.37.217.1 (174.37.217.1)<br>
      User Datagram Protocol, Src Port: sip (5060), Dst Port: sip (5060)<br>
          Source port: sip (5060)<br>
          Destination port: sip (5060)<br>
      <br>
      SIP/2.0 200 OK<br>
      Via: SIP/2.0/UDP
      197.17.144.4:5060;branch=z9hG4bKb9340cb29ba;received=174.37.217.1<br>
      From: <sip:197.17.144.4>;tag=1797904074<br>
      To:
      <sip:my.sip.domain>;tag=b27e1a1d33761e85846fc98f5f3a7e58.de7a<br>
      Call-ID: <a class="moz-txt-link-abbreviated" href="mailto:c7f38580-5c817680-b94-38512c6@197.17.144.4">c7f38580-5c817680-b94-38512c6@197.17.144.4</a><br>
      CSeq: 101 OPTIONS<br>
      Allow: INVITE,ACK,BYE,CANCEL,INFO,OPTIONS,REFER,SUBSCRIBE,NOTIFY<br>
      Accept: */*<br>
      Accept-Encoding: <br>
      Accept-Language: en<br>
      Supported: <br>
      Server: kamailio (4.3.1 (x86_64/linux))<br>
      Content-Length: 0</font><br>
    <br>
    We see clearly that the port is wrong here. But in the received SIP
    frame, everything suggests that the correct port is 5060, and I do
    not think Kamailio will look at the transport frame to send the
    response back to the correct port. Am I correct stating this ? Maybe
    the Via header should contain a port along with the IP address ?<br>
    <br>
    I solved the problem by using TCP instead of UDP, as I know that
    since the TCP connection is maintained, the port would be correct
    (because imposed by the gateway).<br>
    <br>
    I am sorry if the question does not directly relates to Kamailio,
    but any explanation here would be appreciated, as I am a student
    trying to learn how all this is working :)<br>
    <br>
    Cheers,<br>
    Jean-Marie.<br>
  </body>
</html>