In Windows NT, the system typically assigns network-based TCP/IP services to a well-known port, in accordance with Request for Comments (RFC) 1700. POP3 servers, the topic of this continuing series of articles, run on TCP port 110. The first step in getting your mail server to answer requests on that port is to bind the socket.
To understand how to bind a TCP socket to a port, you need to look at the arguments for the bind() function. One of these arguments (the second) is a pointer to a sockaddr structure. For IP applications, that pointer is typically a sockaddr_in structure that contains the numeric IP address and port that you want to bind to locally. If you can't easily identify what interfaces are available, you can simply bind to all available local interfaces by specifying INADDR_ANY as the address.
One security risk that you need to be aware of is that users can bind two sockets to
the same port using a socket option known as SO_REUSEADDR. In other words, two different
applications can answer connections on the same port. So, in the case of a POP3 server,
one application might be delivering mail, while another is stealing passwords. Working
with NT 4.0 and earlier requires a lot of Registry reads to determine which IP addresses
are available. As a result, many programmers simply specify INADDR_ANY to get all the
interfaces. Under Windows 2000, you can have new interfaces popping up and down on the
fly. Unless youre prepared to write code to detect these changes, your service might
not behave properly if you dont bind to all the interfaces.
You're probably thinking, "Why not just specify INADDR_ANY all the time and avoid
these problems?" Here's the catch: If someone does bind to a specific IP address, the
OS prefers the specifically bound socket to one that binds to all available interfaces. To
handle this problem, Microsoft implemented the SO_EXCLUSIVEADDRUSE socket option in NT 4.0
Service Pack 4 (SP4) and Win2K. . . .


I am really sorry I am using this feedback form for discussing my problem.
But I would like to ask one thing. I am facing a JVM bind error in my application occasionally.
To give an insight of the application, I have a Java/EJB application. Many EJB services are running on different ports.
the problem here is, sometime once the site is up. some ports remain occupied once the process cummunicating with them ends. and then this lead to a server socket connection refused error and lead subsytem to the shutdown mode.
then i have to restart the server by killing those process and free the port to let the site working properly
I am not sure what is causing the ports to be occupied once the site gets a clean start.
To give an example, what i am saying, Some time say a process running on port 2145 will be occupied by the process running on port 1433 (SQL SERVER defaul port). It is just a one case of my problem.
Please help me in this.
I would be very thankful to you :)
Karan July 08, 2004