assign port number

if i have root privilege, can i assign a port number below 1000 for my server side socket program.  i am not sure how to do it, do i have to modify the /etc/services files or just execute my server side program as a root, so i am able to "bind" a socket with port number below 1000. any input will be greatly appreicated.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

read the manual pages, buddy!

man services includes the first lines:
       services is a plain ASCII file providing a mapping between
       friendly textual names for internet  services,  and  their
       underlying assigned port numbers and protocol types. Every
       networking program should look into this file to  get  the
       port number (and protocol) for its service.  The C library
       routines   getservent(3),   getservbyname(3),   getservby­
       port(3), setservent(3), and endservent(3) support querying
       this file from programs.

so: you may bind to any port you'd like as long as you are root, but you should use services as a "configuration" file, where you take the right port from....
vzhangAuthor Commented:
thanks gunny for your input!  what happen if i bind a port which is used by other services like "telnet". am i going to have a conflict if i start to run my program. if i am not the root, what is samllest port number am allowed to bind. i run into trouble couple times with binding the socket to the port when i executed the program as user.  it complains that  port is in service.  i just want to choose a port number that will alway allowed me to bind to that port.  
i'm not sure wheater this is defined or not. actualy if you use /etc/services a port conflict should never happen. also it is quite clear that you are going to run into trouble, when installing two services on the same port.

man services, 3th paragraph:
       Port numbers below 1024 (so-called 'low  numbered'  ports)
       can  only  be  bound  to by root (see bind(2), tcp(7), and
       udp(7).)  This is so that clients connecting to  low  num­
       bered ports can trust that the service running on the port
       is the standard implementation, and not  a  rogue  service
       run  by  a  user  of the machine.  Well-known port numbers
       specified by the IANA are normally located  in  this  root
       only space.

if you want to choose a "safe" port (this is an assumption, since as long as your port is not a standard, you could always run into confilct on some other machine) have a look at your existing /etc/services and choose something like port 13193, i'm quite sure not much people are using such things :)

also i realy recommand you to READ the services manualpage!!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vzhangAuthor Commented:
thanks again gunny, do you know why when i termined my server socket program and try to run it again, it give me the message "bind: Address already in use ", that doesn't make any sense, so each time i terminated my program i have to change the port number and recompile the programs again in order to execute it. any input will be greatly appreciated.  for now, i think i will just change the /etc/services file and choose a port below 1024 and run as root.
'you sure you killed the socket?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.