Skip to content

Instantly share code, notes, and snippets.

@meddulla
Last active January 3, 2023 12:05
Show Gist options
  • Save meddulla/793b2e5cad36441cdf6fd23d3c7427c0 to your computer and use it in GitHub Desktop.
Save meddulla/793b2e5cad36441cdf6fd23d3c7427c0 to your computer and use it in GitHub Desktop.
TCP sequence numbers - example image download

Example image download - Summary table of a client requesting an image

Source: https://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/

Sequence and ack numbers shown here are relative. “When a host initiates a TCP session, its initial sequence number is effectively random; it may be any value between 0 and 4,294,967,295, inclusive. However, protocol analyzers like Wireshark will typically display relative sequence and acknowledgement numbers in place of the actual values. These numbers are relative to the initial sequence number of that stream.”

Packet NrDirectionSeq NrAck NrPayload LenFlagsNotes
1-> (client)000SYNClient initiates connection to server
2<- (server)010SYN, ACKServer ACKs client request and requests a connection as well. Ack nr increased to acknowledget client’s SYN
3->110ACKClient increases its own seq nr by 1 to due to last syn sent (seq nr is equal to last ack if all goes well in connection and ack’s server’s SYN)
4->11725PSH, ACKClient sends HTTP header GET /image.png. Sets the PSH/Push flag so that the server kernerl won’t buffer the bytes and instead send them directly to the userland application
5<-1726 = 1 + 7250ACKServer acks client download request. Ack number is the previous ack number + the last received payload length
6<-17261448ACKDownload starts/server starts sending data
7->72614490ACKClient acks previous packet (1+1448=1449)
8<-14497261448ACKServer continues download
9->72628970ACKClient acks previous packet (1449+1448=2897)
..
36<-217217261230PSH,ACKServer sends the final `HTTP/1.1 200 OK`. PSH so the client’s kernel won’t buffer and push the bytes downstream to the client app
37->72622951 (21721+1230)0ACK
38->726229510FIN, ACKClient says it wants to close the connection (since the server has said it has finished sending the msg by using HTTP 200 OK)
39<-229517271230FIN,ACKServer acks client’s FIN request and sends a FIN of his own. the clien’ts FIN increases the ack by 1 (726+1)
40->727229510ACKClients acks the server’s FIN. Both sides have ack’ed the other’s FIN. Connection ends here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment