Skip to content

TFTP ackPacket

Elbasiouny, Mahmoud edited this page Mar 6, 2026 · 5 revisions

ACK packets (opcode 4) acknowledge the receipt of a DATA packet. They are the simplest TFTP packet type - just an opcode and a block number.

Source file: tftp.c
Hammer concepts: h_int_range · h_sequence


ACK Packet Layout

 2 bytes    2 bytes
+---------+---------+
| Opcode  | Block # |
+---------+---------+

According to the RFC:

  • Opcode - 2 bytes, value 4
  • Block # - 2 bytes, the block number being acknowledged (range 0–65535)

A block number of 0 is used to acknowledge a WRQ before any DATA packets are sent.


Step 1: Opcode

H_RULE(opc, h_int_range(h_uint16(), 4, 4));

This only accepts a value of exactly 4.


Step 2: Block Number

H_RULE(blockNum, h_int_range(h_uint16(), 0, UINT16_MAX));

Unlike DATA packets (which start at 1), ACK block numbers start at 0.


Step 3: Assemble the ACK Parser

H_RULE(ackPacket, h_sequence(opc, blockNum, h_end_p(), NULL));

h_end_p() ensures there are no extra bytes after the block number, since an ACK packet is exactly 4 bytes.


Summary

Concept Hammer Function Why It Matters in TFTP
Exact value match h_int_range(p, 4, 4) Opcode must be exactly 4
Full range h_int_range(p, 0, MAX) Block number can be 0–65535
Parse in order h_sequence Opcode followed by block number

Next: ERROR Packets

Previous: DATA Packets

Clone this wiki locally