Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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)
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() ?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.