1834008 Members
1871 Online
110063 Solutions
New Discussion

UDP Port allocation

 
SOLVED
Go to solution
Alessandro Quagliaroli
Occasional Contributor

UDP Port allocation

Hello all,
I'd like to know how the operating system works when an udp server socket is created leaving the O.S. to assign the port to use.
Does it look in /etc/services first?
If so also for ports in the unregistered range?

Thanks
Alessandro
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: UDP Port allocation

Entries in the services file or (NIS) map mean nothing other than port to service name mapping and nothing is "reserved" by such an entry.

Essentially you need to execute:
ndd -get /dev/udp udp_largest_anon_port
ndd -get /dev/udp udp_smallest_anon_port

and the first free port in that range wins. NOTE: Not all releases display the udp_smallest_anon_port.

If it ain't broke, I can fix that.
Matti_Kurkela
Honored Contributor

Re: UDP Port allocation

As Clay said.

/etc/services is used only if your application uses either getservbyname() or getservbyport() function.

For a good overview how various operating systems (including HP-UX) allocate ports when nothing is specified, see:
http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html

MK
MK
Alessandro Quagliaroli
Occasional Contributor

Re: UDP Port allocation

Thanks both.
AQ
Alessandro Quagliaroli
Occasional Contributor

Re: UDP Port allocation

The info provided cleared my doubts.