[ale] Open port

Joseph A Knapka jknapka at earthlink.net
Thu May 23 00:46:16 EDT 2002


Jeff Tillotson wrote:
> 
> In C, is there a way to check if a port is open prior to opening it?   I have
> lookef at getsockopt but that won't so what I want.  I have search the web
> and "UNIX Networking Programming" and there isn't an answer there.
> 
> What I need is to check if a port is already open.  If it is open then I just
> exit the app.  If it isn't then I will bind to the port and all is good.
> 
> Any assistance would be appreciated.

Try to connect() to it at the IP address you intend
to bind it at. If you get ECONNREFUSED, then it's
probably open. Unless IPchains or similar is in the
way.

Cheers,

-- Joe
   Looking for a new .sig.

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list