I have no details but I am curious because I know the browser uses different ports for each tab from reading this article Do web browsers use different outgoing ports for different tabs?
They do, because they need this information to send a reply back.
- Both peers of a TCP connection know each other's IP address, because the IP packet header includes both the 'source' and 'destination' addresses.
- Very similarly, both peers know each other's "local" port, because the TCP header includes both the 'source' and 'destination' port.
For example, when connecting to the SuperUser webserver, it'll see that you're sending a packet from IP address 22.214.171.124 to 126.96.36.199, from TCP port 34567 to 443, and its response to you will have the opposite parameters (i.e. it'll arrive from TCP port 443 to 34567).
Yes, the network stack, etc. as well as the server internals need to know how to send responses back in reply to the request.
However, that doesn't mean that the server software exposes it (easily or directly) to the programming language/tools/libraries that the site is using, or that the side can access and use any of it if it is there (think plain static HTML sites... they still exist).
Here's a sample of what is in the
$_SERVER array from PHP on an Apache instance. You can see the remote IP, port, etc. in there as well as some other interesting stuff... Note that each server software may expose the same information using a different name or in a different method...
Array ( [HTTPS] => on [SSL_TLS_SNI] => example.com [HTTP_HOST] => example.com [HTTP_CONNECTION] => keep-alive [HTTP_CACHE_CONTROL] => max-age=0 [HTTP_UPGRADE_INSECURE_REQUESTS] => 1 [HTTP_USER_AGENT] => Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36 [HTTP_DNT] => 1 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3 [HTTP_ACCEPT_ENCODING] => gzip, deflate, br [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.9,da;q=0.8 [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin [SERVER_SIGNATURE] => Apache/2.4.18 (Ubuntu) Server at example.com Port 443 [SERVER_SOFTWARE] => Apache/2.4.18 (Ubuntu) [SERVER_NAME] => example.com [SERVER_ADDR] => 188.8.131.52 [SERVER_PORT] => 443 [REMOTE_ADDR] => 184.108.40.206 [DOCUMENT_ROOT] => /var/www-example.com [REQUEST_SCHEME] => https [CONTEXT_PREFIX] => [CONTEXT_DOCUMENT_ROOT] => /var/www-example.com [SERVER_ADMIN] => [email protected] [SCRIPT_FILENAME] => /var/www-example.com/req.php [REMOTE_PORT] => 32906 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /req.php [SCRIPT_NAME] => /req.php [PHP_SELF] => /req.php [REQUEST_TIME_FLOAT] => 1561248971.904 [REQUEST_TIME] => 1561248971 )