Get free TCP port?
Posted: Mon Sep 15, 2008 9:36 pm
Hi,
I want to start my daemon at a particular TCP port. The exact port number is not important, so what matters is having a free port that is not in use by other daemons. And it is better to have a port out of range [0, 1024] that is dedicated for "system" ports.
So is there a good way to find a free port for my purpose? Of course we can always enumerating the port (for ex by using "netstat -t"), so we can see which one is not in use. But I dont like that way very much.
The programming language is C, in Linux. Any idea?
Many thanks,
J
I want to start my daemon at a particular TCP port. The exact port number is not important, so what matters is having a free port that is not in use by other daemons. And it is better to have a port out of range [0, 1024] that is dedicated for "system" ports.
So is there a good way to find a free port for my purpose? Of course we can always enumerating the port (for ex by using "netstat -t"), so we can see which one is not in use. But I dont like that way very much.
The programming language is C, in Linux. Any idea?
Many thanks,
J