[sip-comm-dev] getPublicAddressFor() failure mode


#1

My effort to connect two copies of sip-communicator failed. I traced it down to one side registering with address 127.0.0.1. The problem comes
from getPublicAddressFor()

In
NetworkAddressManager.getPublicAddressFor(int) line: 424
we read:
                InetAddress localHost = null;
                 try {
                     localHost = InetAddress.getLocalHost();
                     result = new InetSocketAddress(localHost, port);
                 }
However, the method getLocalHost() does not give public address values,
it just reads what /etc/hosts says.
See for example: http://www.jguru.com/faq/view.jsp?EID=790132.
Moveover, the concept of a host IP address isn't meaningful when machines have multiple network interfaces. DNS maps a name to an IP address, but a machine can have more than one name/address pair.

On the other hand, the overwhelming majority of sip-communicator users will have one IP address. Fixes shouldn't make it harder for most users.

One workaround is to hope that users can edit /etc/hosts when the code above is triggered. This will be mostly Linux I guess.

One code workaround is to scan all the network interfaces and pick one that isn't 127.0.0.1.

A fix would pick one address as above but set it as the default during config, allow users to override it then, and use the configured value in getPublicAddressFor().

A better fix would bind a socket to the configured sip-proxy and read the local address off the bound socket with getLocalAddress(). This would cover both the normal case of sip-communicator and the extra normal case where the sip-communicator is on 127.0.0.1. Well assuming that getLocalAddress() works...

Hope this helps,
John.

···

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net


#2

Actually the SIP Communicator already implements such behavior (and even a bit more). See the comment for NetworkAddressManager.getLocalHost():
/**
* Returns a localhostAddress. The method uses the following algorithm to
* choose among multiple addresses:
* if stun is enabled - queries STUN server and saves returned address
* Scans addresses for all network interfaces
* if an address that matches the one returned by the STUN server is found - it is returned
* else
* if a non link local (starting with 172.16-31, 10, or 192.168) address is found it is returned
* else
* if a link local address is found it is returned
* else
* if the any address is accepted - it is returned
* else
* returns the InetAddress.getLocalHost()
* if the InetAddress.getLocalHost() fails returns
* the "any" local address - 0.0.0.0
*/

The problem in ur case was the fact that apparently whenever stun was used the getLocalHost() method did not get called ... which is a bug. This should be fixed (and ur report acked). CVS udpate and let me know whether it now works for u.

Thanks
Emil

The problem in your case was that you are apparently using stun

JOHN J. BARTON wrote:

···

My effort to connect two copies of sip-communicator failed. I traced it down to one side registering with address 127.0.0.1. The problem comes
from getPublicAddressFor()

In
NetworkAddressManager.getPublicAddressFor(int) line: 424
we read:
               InetAddress localHost = null;
                try {
                    localHost = InetAddress.getLocalHost();
                    result = new InetSocketAddress(localHost, port);
                }
However, the method getLocalHost() does not give public address values,
it just reads what /etc/hosts says.
See for example: http://www.jguru.com/faq/view.jsp?EID=790132.
Moveover, the concept of a host IP address isn't meaningful when machines have multiple network interfaces. DNS maps a name to an IP address, but a machine can have more than one name/address pair.

On the other hand, the overwhelming majority of sip-communicator users will have one IP address. Fixes shouldn't make it harder for most users.

One workaround is to hope that users can edit /etc/hosts when the code above is triggered. This will be mostly Linux I guess.

One code workaround is to scan all the network interfaces and pick one that isn't 127.0.0.1.

A fix would pick one address as above but set it as the default during config, allow users to override it then, and use the configured value in getPublicAddressFor().

A better fix would bind a socket to the configured sip-proxy and read the local address off the bound socket with getLocalAddress(). This would cover both the normal case of sip-communicator and the extra normal case where the sip-communicator is on 127.0.0.1. Well assuming that getLocalAddress() works...

Hope this helps,
John.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net