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)?

John Rix
  • 6,271
  • 5
  • 40
  • 46

1 Answers1

1

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.

Vladimir Ralev
  • 1,371
  • 9
  • 18
  • Thanks @VladimirRalev. I did investigate the Via headers as a possibility early on, but did not see the destination address in there, at least when looking at the SIP message dispatched from the remote party (direct to my endpoint). I take your point though about it not generally being a good idea to use 0.0.0.0 though and may look to re-factor the design to avoid this. – John Rix Feb 06 '15 at 15:59
  • By the way, even if not using 0.0.0.0, but a specific IP address, if I am listening on multiple transports, how can I determine which one a request arrived on? I can't even find a way to do that, which seems odd. I don't know how to determine the Contact header to send back in a response to an INVITE. – John Rix Mar 24 '15 at 15:59
  • Each transport should have its own SipProvider, then for each event you can see the provider like this SipProvider sipProvider = (SipProvider) requestEvent.getSource(); and see if its your udp or tcp provider. It is also fairly safe to check the Via headers of the SIP messages themselves. – Vladimir Ralev Mar 24 '15 at 19:11
  • Thanks for the tip on the getSource method - had missed that. In JAIN SIP 1.2 though, SipProvider implementations support zero to many ListeningPoints (one for each required transport), so I cannot determine the transport from the SipProvider instance. I did think of using the Via headers after adding my comment above, and this seems to be working, so good to have the confirmation. Thanks for your help! – John Rix Mar 24 '15 at 22:54
  • Yes the API allows multiple listening points, but you can just use one per transport. This is how it's done in most JAIN-SIP apps. Via works very reliably too, just make sure you handle correctly multiple Via headers for both requests and responses. – Vladimir Ralev Mar 25 '15 at 17:56