Networking
Networking
10.0.0.1/255.255.255.0
00001010.00000000.00000000.00000001/11111111.11111111.11111111.00000000
10.0.0.1/24
Routing
● To send a packet to a machine on another subnet the frame is sent to a router
● A router usually has more than one network interface (and MAC address)
● A router always has more than one IP address (at least one per subnet)
● Machine A (subnet one):
○ MAC: aa:aa:aa:aa:aa:aa
○ IP: 192.168.0.1 / 255.255.255.0
● Machine B (subnet two):
○ MAC: bb:bb:bb:bb:bb:bb
○ IP: 192.168.1.1 / 255.255.255.0
● Router (both subnets):
○ MAC1: cc:cc:cc:cc:cc:cc
○ IP1: 192.168.0.254 / 255.255.255.0
○ MAC2: dd:dd:dd:dd:dd:dd
○ IP2: 192.168.1.254 / 255.255.255.0
An Example Hop
● Machine A wants to talk to machine B, but machine B is on a different subnet
● So it sends a frame using the MAC for its default gateway as the destination:
○ Source MAC: aa:aa:aa:aa:aa:aa
○ Destination MAC: cc:cc:cc:cc:cc:cc (the router’s first MAC!)
○ Source IP: 192.168.0.1
○ Destination IP: 192.168.1.1 (machine B’s IP!)
● Router receives the frame, and then sends:
○ Source MAC: dd:dd:dd:dd:dd:dd (the router’s second MAC)
○ Destination MAC: bb:bb:bb:bb:bb:bb
○ Source IP: 192.168.0.1
○ Destination IP: 192.168.1.1
● The router modified the source and destination MACs
● Machine B receives the frame from the router :)
A Hop
Multiple Choice
● Machine A sent the frame to its default gateway as a last resort
● It might have had another option in its routing table:
● With this table the MAC for 192.168.0.253 would have been the destination
● Multiple networks connected via routers form what we call the internet :)
The OSI Model
# Name Unit What?
... ← Sure.
... ← Good.
The Real Version
192.168.0.1:56789 192.168.0.2:80
SYN → ...
ACK → ...
DATA → ...
... ← ACK
... ← DATA
ACK → ...
... ← FIN
... ← ACK
Retransmissions
● If the sender doesn’t receive an ACK after a while it will resend the data
192.168.0.1:56789 192.168.0.2:80
...handshake...
DATA → ...
... ← ACK
... ← DATA
...time passes...
... ← DATA
ACK → ...
...termination...
Skipping A Few Layers (for OSI at least)
● HTTP is an application layer protocol
● HTTP version 1.1 is just plaintext
○ So simple you can write it by hand!
● It might be encrypted with, say, TLS, but we’ll ignore that for now
● HTTP version 2 isn’t plaintext, but we’re going to ignore that too
● When we’re talking about an application layer protocol we can (mostly) ignore
the lower layers :)
Let’s Talk HTTP
192.168.0.1:56789 192.168.0.2:80
...handshake...
...termination...
The Request
● Each line in the request is separated by a Carriage Return and a Line Feed
character (CRLF sequence)
● The request is terminated by two CRLF sequences
● Headers are sent in the form Key: value
What What?
GET /index.html HTTP/1.1 Get me the file at /index.html; I’m using HTTP version 1.1
Connection: close Please close the TCP connection when you’ve sent me the data
What What?
HTTP/1.1 200 OK I’m using HTTP version 1.1; that request is OK!
Content-Type: text/html I’m going to send you some text that happens to be HTML
Content-Length: 1337 You’ll need to read 1337 bytes to get all of the response body
192.168.0.1:56789 8.8.8.8:53
192.168.0.1:56789 8.8.8.8:53