-1

I want to estabilish TCP connection over the internet between 2 computers which are in different local networks (the local networks use wifi). I have looked for description of TCP protocol, esspecially the structure of TCP header: http://en.wikipedia.org/wiki/Transmission_Control_Protocol#Checksum_computation

I assumed from that data that only: Source address (global ip), Destination address (global ip), Source port, Destination port are needed.

But how does the router in recipient's local network know which computer in this network is the final destination without MAC address or local ip address?

EDIT: In my situation I have: a mobile phone connected to the internet (not by wifi) and the server (pc) in home local network connected to router by wifi.

So the question is: Are the global sender/reciepient IP address and ports all that are needed or are the MAC addresses also needed to estabilish connection?

If MAC is not necessary what if there are two computers in the same network that are listening on the same port. As far as I remember all pc's use port 80 for http which uses tcp. Why are there no conflicts?

2 Answers 2

3

In a switched network, yes the MAC address is required by the client.

In a routed network, no the MAC address is not required by the client.

In the routed example, the packet leaves the source network via the default route. That router then consults its routing table to decide how to send the traffic to the destination. On arrival at the destination network, the ARP protocol is used for the router to discover the correct MAC address on the local network and the packet is sent.

4
  • In this situation we have: a mobile phone connected to the internet(not by wifi) and the server(pc) in home local network. Jan 21, 2014 at 1:16
  • Sounds like the routed example.
    – dmourati
    Jan 21, 2014 at 1:17
  • I described it better in the edit in op. Thank you for all your help : ) . As soon as I can upvote I'll do that. Jan 21, 2014 at 1:18
  • See also: en.wikipedia.org/wiki/Network_socket
    – dmourati
    Jan 21, 2014 at 1:19
2

If MAC is not necessary what if there are two computers in the same network that are listening on the same port. As far as I remember all pc's use port 80 for http which uses tcp. Why are there no conflicts?

There are conflicts. This is one of the reasons being behind NAT and on a network with a single public IP kind of sucks. There are three ways the router can tell which machine to send the packet to:

  1. If the connection originated from the inside, the router can make a NAT table entry. When it sees the inbound packet, it looks up the source IP address, source port, and destination port up in its NAT table. This tells is the inside destination IP address. It can then rewrite the destination IP address.

  2. If port forwarding is specifically set up in the router, it can look up this destination port and rewrite the destination IP address as configured.

  3. If a dynamic protocol like UPnP is configured, then the inside machine can create a dynamic forwarding entry in the router, allowing it to rewrite the destination IP address.

Not the answer you're looking for? Browse other questions tagged .