Patrick wrote: >I need to bind my client within a specific port range, a range that is a >subset of the OS' range. That's why I cannot let the OS pick one at random. >Unless of course, there's a way to configure the OS so that it picks ports >from a specific range... > This discussion is now officially OFF TOPIC for this mailing list. Let this be the last message in the thread, unless you want to stop talking about generic socket programming and start talking about JSS or NSS.
Is this requirement so you can configure your firewall to only allow connections from those ports? It's a difficult requirement to satisfy, because the socket layer doesn't have a nice way to do it. That said, you don't have to resort to simple trial-and-error. Just keep track of what ports you are using. Every time your app binds to a local port, mark it as USED in some big bitmap. When you're done with it, mark it UNUSED. You still need to verify that the port is available, since some other part of the code may have grabbed it, or it may be in a wait state.
