The original code did not deal with UDP binding failures, this new code does one random port attempt and then sets port to 0 to get 'OS default' behaviour, and ASSERTs that that has to work.
Patch also moves the local UDP port range definition to udp.h from udp.c.
This addresses the issue where a server would otherwise reject a valid
connection attempt from a rebooted node, due to the server thinking that
packet belonged to a recently closed session. By starting off the local
TCP port numbers at random* points each boot the risk of port reuse
across a reboot is significantly reduced.
*) As random as can be had via the lower 12 bits of the ccounter.