LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 05-24-2005, 10:39 AM   #1
DCalabrese
LQ Newbie
 
Registered: May 2005
Posts: 2

Rep: Reputation: 0
bind error on high ports "address already in use"


I recently ported an applciation from Solaris to Linux (Red Hat ES 3) and noticed that Linux doesn't allow you to bind to a port if the port is currently in a state of ESTABLISHED.

I run services listening on High ports (e.g. 47510). The problem is I also make outgoing connections, which will grab a random high port as the source port for this connection. Once a connection is establish from a high port, I am unable to bind to that port as a listen port.

On Solaris, I did not have this problem. The only states of a socket port that would prevent me from binding to it were:
LISTEN
CLOSE_WAIT
TIME_WAIT (I could get around this by setting SO_REUSEADDR)

Has anyone seen this, and have any suggestions on how to get around this?


Is there a way to force the local bind to a port, even if that port is being used as the source port for an outgoing connection?

Is there a way to tell the OS to exclude certain high ports from its list of outgoing source ports? (/proc/sys/net/ipv4/ip_local_port_range)

Thanks,
Dave
 
Old 05-24-2005, 03:33 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Strange. When using SO_REUSEADDR I have no such problems. One thing makes me wonder. Are you trying to open the same socket socket first using listen() and connect() ?
 
Old 05-25-2005, 09:21 AM   #3
DCalabrese
LQ Newbie
 
Registered: May 2005
Posts: 2

Original Poster
Rep: Reputation: 0
The outgoing socket connection with the source "high port" is being created in the normal way with a socket() and connect() call.

The bind to the listen port is being created as follows:
listen_socket = socket(AF_INET, SOCK_STREAM, 0);
setsocketopt(...) // SO_LINGER=0, SO_REUSEADDR=1, SO_KEEPALIVE=1
address.port = 45000;
bind(listen_socket, &address, sizeof(address);

If port 45000 happened to be in use by an outgoing socket connection, the bind fails with errno = 98 (EADDRINUSE) Address already in use.

This behavior only happens on the Linux build. When I run this on Solaris 9, the bind will be successful, even if port 45000 is in a state of ESTABLISHED due to an outgoing connection using that as a source port.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
dhcpd error "Can't bind to dhcp address" msjenkins Linux - Networking 4 10-06-2010 05:16 PM
"unable to bind socket - Address already in use" engineerwell Linux - General 7 05-12-2010 02:46 AM
"rcmd socket : All ports in use" Error alchimiste Linux - General 1 10-26-2006 10:33 AM
difference between "Web server local URL" and "IPv4 address"? kpachopoulos Linux - General 2 09-17-2004 01:30 PM
"NON-RECOVERABLE RESOLVER ERROR" when installing ports jamminparidise *BSD 1 02-11-2004 08:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration