LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 09-03-2007, 11:04 PM   #1
sachinsharma10
LQ Newbie
 
Registered: Sep 2007
Posts: 3

Rep: Reputation: 0
Post How to select TCP_Ports Range


Hi All,

Need a favor from your side...

I want to select the port range for a selected process in linux...

Detailed:
I have to assign the tcp_port (/etc/services) range for a selected process so when it start it choose the ports with in the specified range.

Problem what i am facing:
When ever i start first process it takes the available (free) port and when i start the second process it wont start becasue the port was configured for second process was used by first process so my process wont start...

Hence i want to assign the tcp_ports range for a selected process. so it wont choose my assign ports for other process...

Regards,
Sachin
 
Old 09-04-2007, 06:38 AM   #2
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 51
If a process asks for _listening_ (then it's a server) on a specific port, then nothing can influence the decision, it's hardcoded.
If you are talking about a client that connects to something then the kernel assigns the source port and in this case yes you can influence the source port.
If the client specifically requests a source port (due to firewall restriction for example) then it is fixed also.
 
Old 09-04-2007, 11:36 PM   #3
sachinsharma10
LQ Newbie
 
Registered: Sep 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Can i have more details on your second points (If you are talking about a client that connects to something then the kernel assigns the source port and in this case yes you can influence the source port). because we are dealing with same type of scenario.

If possible please let me know the procedure.
Anyhow, thanks for the reply..
 
Old 09-05-2007, 04:38 AM   #4
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 51
Clarification:
Usually when a client connects to a server, the destination port is fixed (== listening port of the server). The source port is set to 0 by default is the application doesn't set it, meaning the kernel has to take a new non-used one. In older kernels, it will take n+1 (client 1 gets 1024, client 2 1025 etc,..). In newer kernels it is randomized (client 1 gets 3213, client 2 gets 21244,...). So usually if the application lets the kernel decide, you should have no problems.
If the application requires a fixed source port (the application specifically sets the source port) then this source port is used. A TCP connection is a 4tuple (source adress,source port, dest adress, dest port). There can not be 2 exact same TCP connections: In the case of an app that sets manually the source port (==source port is the same) and connects to the same server (==dest port is same) on the same machine (==dest adress same) from the same machine (==source adress same), you can only have 1 connection. This is your case and there is no workaround but to modify the app to use another source port available.

The tcp port range is used for all applications and not per application.
If an application does not specify a source port (in the code, sin.port is not touched and let as its default value 0) then the kernel will assign itself a source port in this range.

If the application specifies a specific source port then this tcp port range is not used to override the application decision. So it won't help you I guess.


To summarize, you can not establish 2 connection from the same client to the same server if the app manually sets the source adress otherwise there would be a big mess on the network.

It could be that there is a workaround when setting ip aliases adresses or playing with NAT but I have no clue. The cleaner would be to modify the application.

Last edited by nx5000; 09-05-2007 at 04:39 AM.
 
Old 09-06-2007, 05:14 AM   #5
sachinsharma10
LQ Newbie
 
Registered: Sep 2007
Posts: 3

Original Poster
Rep: Reputation: 0
If you dont mind would you please provide some lights on your 3rd scenario i.e. --- If the client specifically requests a source port (due to firewall restriction for example) then it is fixed also.

Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
select in vi adnanm Linux - Newbie 5 06-02-2007 05:36 AM
select() Kroenecker Programming 1 03-12-2006 01:01 AM
select jhon Programming 5 11-01-2005 09:46 PM
Select() did not select my socket thvo Programming 1 05-08-2005 12:20 AM
what os to select kevinasr Linux - Newbie 2 05-18-2003 06:52 AM


All times are GMT -5. The time now is 06:06 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration