Can and will an operating system reuse a source port number for a connection to a different destination address/port combination?
If I connect()
to enough hosts, and keep those connections open, eventually I'll run out of unique source ports, exhausting the ephemeral range, the non-root range (1025-65,535; assuming non-root) or the absolute range (0-65,535). I want to know if those represent real limits to the number of hosts I can simultaneously have a connection to. I'm interested in what the standards promise (or don't), as well as the reality on Linux (Windows would be a bonus).
I know that opening that many connections will likely run into a number of other limits; that's a different issue and question. If it matters, this massive number of connections would be divided among a similarly large number of processes. I'm interested in the case where I'm requesting an ephemeral port, not manually bind()
ing one. If under "normal" circumstances ports won't be reused, are there ways of changing that behavior from user-space (at which point bind()
ing to a specific point becomes an option)?