-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Eric,

On 3/26/20 13:58, Eric Robinson wrote:
> Many people say the maximum number of client ports is 64K.
> However, TCP connections only require unique sockets, which are
> defined as...
>
> local_IP:local_port -> remote_ip:remote_port
>
> Theoretically, it is possible for a client process to keep using
> the same local source port, as long as the connections are to a
> unique destinations. For example on a local machine, the following
> connections should be possible...
>
> 192.168.5.100:1400 -> 192.168.5.200:3306 192.168.5.100:1400 ->
> 192.168.5.201:3306 192.168.5.100:1400 -> 192.168.5.202:3306
> 192.168.5.100:1400 -> 192.168.5.203:3306

I think you must be confusing something, here. The left-hand side of
that list looks like it cannot happen. Each client connection requires
its own source-port, so port 1400 cannot be used by many simultaneous
connections.

It's also strange for me to see client port numbers so low. Typically,
client ports are much higher. It's also very uncommon for the client
to specify a source-port, so the OS's TCP/IP stack usually allocates
an available port, which is why they end up being higher-numbered
ports. Have a look here for a very informative answer:

https://superuser.com/a/1118742/408230

Note that the maximum number of client port is DEFINITELY fixed at
64k, because of the data types used by the C library. This happens
when you bind() a socket to a port:

int bind(int sockfd, const struct sockaddr *addr,
         socklen_t addrlen);

struct sockaddr is:

           struct sockaddr {
               sa_family_t sa_family;
               char        sa_data[14];
           }

and, for the AF_INET socket address family (from <netinet/in.h>):

           struct sockaddr_in {
               sa_family_t    sin_family; /* address family: AF_INET */
               in_port_t      sin_port;   /* port in network byte order
*/
               struct in_addr sin_addr;   /* internet address */
           };

Continuing down the road, in_port_t (from <netinet/in.h>

/* Type to represent a port.  */
typedef uint16_t in_port_t;

So the port number is unsigned 16-bit. you can't squeeze more than 64
ports out of that.

Note that you aren't limited to 64k sockets, as you have intimated:
ports can be re-used.

> I've seen this demonstrated successfully here:
>
> https://serverfault.com/questions/326819/does-the-tcp-source-port-have
- -to-be-unique-per-host
>
>  As someone on that page pointed out, while it is possible, it does
>  not commonly occur in practice "because most TCP APIs don't
> provide a way to create more than one connection with the same
> source port, unless they have different source IP addresses." This
> leads to the 64K maximum client port range, but it is really a
> limitation of the APIs, not TCP.
>
> So how does tomcat handle things? Is it limited to a maximum 64K
> client source ports, or is it 64K per destination, as it should
> be?

The short answer is that Tomcat doesn't handle this. There are very
few outgoing connections that Tomcat makes, and database connections
aren't on that list. What you are seeing is the JDBC driver's
connection being handled by Java, which ultimately is being handled by
the JRE and the OS working together. I see you are using port 3306
which is MySQL and/or MariaDB. I don't know of any driver which
bothers to set the local port, so it's again strange to me to see port
1400 getting ... any use at all.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl5+KvEACgkQHPApP6U8
pFi5rxAAp8HoqhQFOX6FtR3r+f1wkcdx7eLVc68e1NngB05hXdLTiXtmRy+XRXYy
8XahJkFvqWkKpKKcRopn714g+P44qMcXCtLtgQ3iTRB9dwp5uuYKN5z6QbaAzWfq
vPb8UXESFoxCiXVBuV5Q8H+9utvS1OaST8exkwuAi33dkuh/Es4gFWpmbrKVhExl
s4TNwq2UCTB5d6ybNM8AZzeAiNxkrop9+zi3AcgcVN6KMUS/dPWen3YTchUyTpdc
821gOKVrpy3nvPdCJv2dtoZ7G343D/Ice+ZYaDEe+oooOcPu88siOzna5vVDyUSM
z7o3XsQ/zHIihfDwG5F1z0upWEGPPy5RD9VwOGvlCCDrG3dCHpYrgYfcOm3jA1kh
6Bu1y8vIy2qX7ZWEaHPOyAMpZKsodugpGR6Piov78OsEQWBLW5pD5E1sOBkXa2TO
QSoadpWSjTVlTfDvZvTM4l5KDA+Q8NFmBPvoViejXIQCsshT4Hz4fEnBZTSPzQLf
6bxJrp9+5Y9f2ZFM3Iss4NR6PfCTE5LbWGJZOY+IWzN1p2UUJtEw1nazbWc57kRx
ZLZgwz8D0IiNnooU3NA6rr+hqC+FPYgszGOS3BJUyfUn7PetZbtoOA5ouZn7S5jQ
kq18P3k9z9rc/BKSaSnYdX7NmUavkqfM0Nw+Dwrmds3fdchUVoY=
=DXcE
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to