Networking Basics

Ethernet (as well as Wi-Fi and Bluetooth) uses MAC addresses, [soure] while IP addresses are used by the Internet Protocol. TCP packages (TCP header + data) are placed inside the IP packages. [source] For this reason, our first example uses MAC addresses as well as IP addresses.

Ports are a concept of TCP and UDP and uniquely describe a certain application that is running on the targeted computer to which the packet is sent. [source] A process can request a port from the OS using the bind system call. [source] If no other process uses this port, the OS assigns the requested port to the application by writing the port and the corresponding process into a certain table. [source]

A socket in UNIX is just a file. [source]

Network address translation (NAT), [source] also called IP masquerading is the method of using a single IPv4 address for an entire private network. The ISP (internet service provider) assigns the IPv4 address to the router. The router changes the private IPv4 address in the IP packet to the public IPv4 address, and the port of the source host to an unused port of the router (port address translation). It then recalculates the checksum and sends the package on its way. He then stores the private IPv4 address and port of the source host together with the destination address and the port that the router itself assigned. If inbound traffic arrives, it uses this data and swaps its own IPv4 address and the port back to the private IPv4 address and port of the original source host (which now is the destination host). [source]

Networking Hardware basics