Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Port number from listen address

25 views
Skip to first unread message

Roy Hann

unread,
Mar 13, 2023, 1:14:12 PM3/13/23
to
Now that a listen address can have a "subport" number up to 15
(formerly only up to 7), how is it hashed to an IP port number?

I could just set one up to see where the extra bit pops up, but if
someone knows off the top of their head...

Roy

Roy Hann

unread,
Mar 13, 2023, 5:11:10 PM3/13/23
to
I went ahead and set one up. It turns out to be about as complicated as
you might guess.

Before I describe the change, there is a weird presentation of the
old port number hash at
https://communities.actian.com/s/article/Manual-Calculation-of-the-tcp-ip-Port-Number-from-Listen-Address.
There is a better presentation including C code at
https://ariel.its.unimelb.edu.au/~yuan/ingres/ingres_net_port.html. The
latter explanation makes it clear the hash starts by setting bit 14,
then additional bits are turned on depending on the listen address.

In the new method, if the subport is less than or equal to 7 then bit 14
is still set to 1. But if the subport is greater than 7 then
bit 15 is set to 1 instead. The low-order three bits are set to
whatever the subport is, masked with 0x07. (So if it's 8 the low order
three bits are 000; if it is 10 the low order three bits are 010,
etc.)

Roy
0 new messages