Operating System - HP-UX
1830908 Members
1766 Online
110017 Solutions
New Discussion

configuring the starting port number in UX

 
SOLVED
Go to solution
Tim Killinger
Regular Advisor

configuring the starting port number in UX

Don't know if I'm asking this question correctly, I'm a UX admin researching for a programmer.

Is there a way to configure/specify the starting TCP port number in UX? I'm assuming the programmer wants this configured/specified at the UX level, or maybe he can specify in his code.
6 REPLIES 6
Dave Hutton
Honored Contributor
Solution

Re: configuring the starting port number in UX

The /etc/services is there to do what I think your asking. To reserve a specific port for an app.

Dave
Sridhar Bhaskarla
Honored Contributor

Re: configuring the starting port number in UX

Hi,

I am not sure if I understood your requirement correctly. You can see all the registered ports on the system in /etc/services file.

For user access, the smallest port is 1024. You can get this information from ndd.

ndd -get /dev/tcp tcp_smallest_nonpriv_port

For arbitrary ports, it is

ndd -get /dev/tcp tcp_smallest_anon_port

Use udp instead of tcp in the above for UDP ports.

I wouldn't suggest to reconfigure nonpriv_port to further low. You may play around with the anon-port if you want. But make sure you don't have any ports falling in that range that are being used by your applications before you make the change.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor

Re: configuring the starting port number in UX

If the Network Programmer doesn't know this then he probably shouldn't be writing code yet. The choice of ports is the sole disgression of the programmer. Now, if he wants to have a daemon listen on a particular port, he can choose to do it numerically OR (the preferred method) he can use getservbyname(). An entry is made in the /etc/services file or map for perhaps, myservice tcp/7080. Then he calls getservbyname() sending in tcp as the protocol and myservice as the servicename and he gets back 7080. Man getservbyname for details.

Actually, nowadays there is actually little reason to write socket stuff in C because Perl does it so well and is almost as fast.
Perl's IO::Socket Module works extrememly well.

I attach a small Perl script that sets up a port and calls getservbyname(). Its actually a multi-host semaphore server but it should
illustrate how this works.


If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: configuring the starting port number in UX

I'll also attach a client that will talk to the Perl semaphore server. With these two pieces, he should have a good idea of how to do this.

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: configuring the starting port number in UX

I'll try again with client.pl.

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

Re: configuring the starting port number in UX

You can specify the source (starting) port in C or C++ using bind() see:

http://www.fortunecity.com/skyscraper/arpanet/6/cc.htm

If you do not specify the port in your code then on the newer HPUX systems the source port will be selected randomly from the range given in

ndd -get /dev/tcp tcp_smallest_anon_port

and

ndd -get /dev/tcp tcp_largest_anon_port

Older HPUX systems used to start at something like 1025 and use them sequentially but this was thought to make life too easy for hackers so they changed it. For other UNIX versions see:

http://www.ncftpd.com/ncftpd/doc/misc/ephemeral_ports.html

Ron