Improved handling of ephemeral ports

When using ephemeral port the actual port being used was not returned.
The socket.bind(String addr) method now returns correct port also for
ephermal ports.