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?
-
Your question title and last sentence don't ask the same question. It's unclear what you're asking.– I say Reinstate MonicaJun 22, 2019 at 23:38
-
@TwistyImpersonator Forget about the last part. he he– Noajm IsMy NameJun 22, 2019 at 23:40
-
2There is no such thing as "outgoing port". There are local/remote, or source/destination, ports.– u1686_grawityJun 22, 2019 at 23:51
-
@Ramhound So, are you saying no it can not know my local port number!– Noajm IsMy NameJun 22, 2019 at 23:52
-
@grawity I do not know. Don't blame me, blame who asked that question– Noajm IsMy NameJun 22, 2019 at 23:53
2 Answers
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 1.1.1.1 to 2.2.2.2, 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).
-
-
2But in case of IPv4 the other end only knows the external port due to NAT– phuclvJun 23, 2019 at 3:32
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] => 45.56.125.54
[SERVER_PORT] => 443
[REMOTE_ADDR] => 174.131.63.212
[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
)