Search code examples
javaip-addresssipjain-sip

JAIN SIP: Identify inbound IP for SIP message when listening on 0.0.0.0


When using the JAIN SIP API, I create a ListeningPoint instance with an address of 0.0.0.0 (ie. listen on all interfaces):

sipStack.createListeningPoint("0.0.0.0", 5060, "TCP");

Is there a way for me to identify which IP interface an incoming SIP message arrived on (in order to derive an appropriate Contact header address in the response message, amongst other uses)?


Solution

  • It's not a good idea to listen to 0.0.0.0, there are cases where the SIP stack will have to guess what address to use too and it may guess wrong. I think it's not possible to tell the address using the standard APIs, but you can almost always use private APIs from implementations. For example https://jsip.ci.cloudbees.com/job/jsip/javadoc/gov/nist/javax/sip/message/SIPMessage.html#getLocalAddress()

    You can also guess by the Via headers etc. But again not a good idea.