ICMP, ARP and DHCP (supporting)
The three helper protocols around IP: ICMP (error reports and ping and traceroute), ARP (finding the MAC address of the next hop and why the MAC addresses change at every router while the IP addresses do not) and DHCP (getting an address, mask, gateway and DNS server automatically: the four messages and the lease timers).
Why it exists
IP alone cannot do three jobs that every network needs. When a packet cannot be delivered, someone must tell the sender: that is ICMP. On an Ethernet, a sender that knows only the destination's IP address must find the MAC address to put in the frame: that is ARP. And a host that has just been plugged in knows nothing, not even its own address: DHCP gives it an address, a mask, a gateway and a DNS server. GATE asks which protocol does which job, what a frame looks like at each hop (which addresses change), the sizes of these messages, and the lease timers of DHCP.
Prerequisites
You need the IPv4 address structure and subnets from IPv4 addressing, and the Ethernet frame (6-byte MAC addresses, the type field, the 46-byte minimum data, the CRC) from Ethernet.
Precise definitions
ICMP: reports and tests
The Internet Control Message Protocol reports errors in IP delivery and carries diagnostic messages. An ICMP message is carried inside an IP datagram (IP protocol number 1); it is not UDP or TCP and has no ports. Format: type (8 bits), code (8 bits), checksum (16 bits, the Internet checksum of the whole ICMP message), then type-dependent fields (for an echo: a 16-bit identifier and a 16-bit sequence number) and data. An error message carries the IP header and the first 8 bytes of the datagram that caused it, so the sender can tell which connection it concerns.
| type, code | meaning | sent when |
|---|---|---|
| 8, 0 / 0, 0 | echo request / echo reply | ping |
| 3, 0 / 1 / 2 / 3 | destination unreachable: network / host / protocol / port | no route; host down; no such protocol; nothing listens on the UDP port |
| 3, 4 | destination unreachable: fragmentation needed and DF set | the datagram does not fit the MTU and may not be fragmented (path MTU discovery) |
| 11, 0 | time exceeded: TTL reached 0 | a router decremented the TTL to 0 |
| 11, 1 | time exceeded: fragment reassembly time expired | missing fragments |
| 5, x | redirect | a better first-hop router exists |
ping sends an echo request and measures the time until the echo reply. traceroute sends probes with TTL 1, 2, 3, ...: the router that makes the TTL 0 answers time exceeded from its own address, so the sender learns the path hop by hop; the destination ends the trace with port unreachable (UDP probes to an unused port) or an echo reply (ICMP probes). No ICMP error is sent about an ICMP error, about a broadcast, or about any fragment but the first.
ARP: from an IP address to a MAC address
A frame on a LAN needs the MAC address of the receiver. A sender that knows the next hop's IP address uses the Address Resolution Protocol:
- It looks in its ARP cache (a table of IP address to MAC address entries that expire after a while).
- If absent, it broadcasts an ARP request (Ethernet destination ff:ff:ff:ff:ff:ff, type 0x0806): "who has IP address X? tell me".
- The owner of X answers with a unicast ARP reply carrying its MAC address; the asker caches it.
An ARP packet is 28 bytes: hardware type (2: 1 for Ethernet), protocol type (2: 0x0800 for IPv4), hardware address length (1: 6), protocol address length (1: 4), operation (2: 1 request, 2 reply), sender MAC (6), sender IP (4), target MAC (6), target IP (4). It is shorter than the 46-byte minimum of an Ethernet data field, so the frame is padded by 18 bytes: a minimum-size frame of 64 bytes with header and CRC.
ARP works only inside one subnet. If the destination is on another subnet, the sender resolves the MAC address of its default gateway and addresses the frame to that: so along a route the source and destination IP addresses stay the same, while the source and destination MAC addresses change at every router (each hop is a new frame between two neighbours). Variants: a gratuitous ARP announces one's own address (and detects duplicates); proxy ARP lets a router answer for hosts behind it; RARP (MAC to IP) is obsolete, replaced by BOOTP and DHCP.
DHCP: configuring a host
The Dynamic Host Configuration Protocol lets a host that has just joined obtain an IP address, a subnet mask, a default gateway and the address of a DNS server from a server, for a limited lease. It runs over UDP: the server uses port 67, the client port 68. Because the client has no address yet, its first messages are broadcasts with source address 0.0.0.0. The four messages ("DORA"):
- DISCOVER: client to 255.255.255.255:67, "is there a server?";
- OFFER: a server proposes an address (and lease, mask, gateway, DNS);
- REQUEST: the client chooses one offer and asks for it (broadcast, so that the other servers see that theirs was refused);
- ACK: the server confirms; the lease starts.
A server on another subnet is reached through a relay agent (usually the router), which forwards the broadcast as a unicast. The message is the old BOOTP format: 236 fixed bytes, a 4-byte magic cookie, and a list of options (the message type is option 53; 255 ends the list).
Lease timers. A lease of length : at the client tries to renew with the same server (unicast REQUEST); if that fails, at it tries to rebind with any server (broadcast REQUEST); at the lease expires and the client must stop using the address and start over with DISCOVER. A server may refuse a request with a NAK.
How it works
A real ping. The script sent an ICMP echo request to 127.0.0.1 and read the reply; the table shows both messages byte by byte. The reply is the request with the type changed to 0 and the checksum recomputed.
A real ping: an ICMP echo request to 127.0.0.1 and the reply the kernel sent back (observed on this machine): start
Computed by a script, not typed| field | request (built here) | reply (received) |
|---|---|---|
| type | ||
| code | ||
| checksum | ||
| identifier | ||
| sequence number | ||
| data | ||
| IP protocol / TTL of the reply |
Step 0
The request was built with struct, sent through an unprivileged ICMP datagram socket and the reply read back; the 'copied' fields and the checksum were checked by the script. The TTL of the reply depends on the operating system (this machine's kernel).
traceroute. The TTL grows by one for each round of probes; each router that makes it zero answers with time exceeded.
traceroute: probes with TTL 1, 2, 3, ... through three routers: start
Computed by a script, not typed| probe | answered by | ICMP message | result |
|---|---|---|---|
| probe with TTL 1 | |||
| probe with TTL 2 | |||
| probe with TTL 3 | |||
| probe with TTL 4 |
Step 0
A simulation of the algorithm (the addresses are made up): the TTL is raised by one for each round of probes until the destination answers.
An ARP request inside an Ethernet frame, field by field, with the padding.
An ARP request for 192.168.1.1, field by field, inside an Ethernet frame: start
Computed by a script, not typed| field | bytes | meaning |
|---|---|---|
| hardware type | ||
| protocol type | ||
| hardware / protocol address length | ||
| operation | ||
| sender hardware address | ||
| sender protocol address | ||
| target hardware address | ||
| target protocol address | ||
| Ethernet destination | ||
| Ethernet source | ||
| EtherType | ||
| padding | ||
| FCS (CRC) | ||
| frame on the wire |
Step 0
Built with struct.pack; the sizes are measured on the bytes, not typed.
A packet crossing a router. Host A (192.168.1.10) sends to B (10.0.0.5) through router R, all caches empty. Watch the MAC and IP columns: the IP addresses never change, the MAC addresses are different on each side of R, and the second packet needs no ARP.
A packet from A (192.168.1.10) to B (10.0.0.5) through router R: the addresses in each frame: start
Computed by a script, not typed| frame | source MAC | destination MAC | source IP | destination IP |
|---|---|---|---|---|
| 1. ARP request | ||||
| 2. ARP reply | ||||
| 3. IP packet | ||||
| 4. ARP request | ||||
| 5. ARP reply | ||||
| 6. IP packet | ||||
| 7. IP packet (second packet) | ||||
| 8. IP packet (second packet) |
Step 0
Host A, router R (192.168.1.1 on one LAN, 10.0.0.1 on the other) and host B, all caches empty at the start. The IP addresses stay the same all the way; the MAC addresses change at every router. A simulation of the rules of ARP.
DHCP. The four messages with their addresses, ports and sizes.
DHCP: Discover, Offer, Request, Acknowledge: start
Computed by a script, not typed| message | from → to (IP address : UDP port) | DHCP message | IP packet | your address (yiaddr) |
|---|---|---|---|---|
| DISCOVER | ||||
| OFFER | ||||
| REQUEST | ||||
| ACK |
Step 0
Built and decoded with struct. The messages are broadcast at the link layer in this variant; a server may also unicast the reply to the client's MAC address. Real clients usually pad messages to at least 300 bytes (BOOTP compatibility).
The lease timers.
DHCP lease timers: renewal at 50 per cent, rebinding at 87.5 per cent: start
Computed by a script, not typed| lease | T1 (renew, unicast) | T2 (rebind, broadcast) | expires |
|---|---|---|---|
| lease of 1 hour | |||
| lease of 8 hours | |||
| lease of 24 hours | |||
| lease of 7 days |
Step 0
The fractions 1/2 and 7/8 are the defaults of the DHCP standard; a server may send other values.
Worked examples
EX 1Which protocol?
EasyA router cannot forward a datagram because its TTL reached 0: ICMP (time exceeded, type 11). A host wants the MAC address belonging to 192.168.1.1: ARP. A laptop joins the Wi-Fi and gets 192.168.1.50: DHCP. ping and traceroute: ICMP. A UDP datagram arrives for a port that nobody listens on: the host sends ICMP destination unreachable, port unreachable (type 3, code 3). A datagram larger than the MTU with the Don't Fragment bit set: the router drops it and sends ICMP type 3, code 4. Which protocol is carried directly in an IP datagram and has no ports? ICMP (and OSPF).
EX 2An ARP request, byte by byte
MediumThe program builds the ARP request of the table (sender 00:11:22:33:44:55, 192.168.1.10; asking for 192.168.1.1) inside an Ethernet frame, prints the bytes, and measures the sizes.
#include <stdio.h>
#include <string.h>
int main(void) {
unsigned char arp[28] = {0, 1, /* hardware type: Ethernet */
8, 0, /* protocol type: IPv4 */
6, 4, /* address lengths */
0, 1, /* operation: request */
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 192, 168, 1, 10, /* sender MAC and IP */
0, 0, 0, 0, 0, 0, 192, 168, 1, 1}; /* target MAC (unknown) and IP */
unsigned char frame[64];
memset(frame, 0, sizeof frame);
memset(frame, 0xFF, 6); /* destination: broadcast */
memcpy(frame + 6, arp + 8, 6); /* source: the sender's MAC */
frame[12] = 0x08;
frame[13] = 0x06; /* type: ARP */
memcpy(frame + 14, arp, sizeof arp);
int header = 14, data = (int)sizeof arp, pad = 46 - data, fcs = 4;
printf("ARP packet: %d bytes\n", data);
printf("Ethernet header %d + ARP %d + padding %d + CRC %d = %d bytes\n", header, data, pad, fcs, header + data + pad + fcs);
for (int i = 0; i < 14 + 28; i++) printf("%02x%c", frame[i], (i % 14 == 13 || i == 41) ? '\n' : ' ');
return 0;
}ARP packet: 28 bytes
Ethernet header 14 + ARP 28 + padding 18 + CRC 4 = 64 bytes
ff ff ff ff ff ff 00 11 22 33 44 55 08 06
00 01 08 00 06 04 00 01 00 11 22 33 44 55
c0 a8 01 0a 00 00 00 00 00 00 c0 a8 01 01Reading it. The frame starts with the broadcast destination (six ff bytes), the sender's MAC and the type 0x0806. The 28-byte ARP packet follows: hardware type 0001, protocol type 0800, lengths 06 and 04, operation 0001 (request), the sender's MAC and IP, a zero target MAC (the unknown), and the target IP. The ARP packet is 28 bytes but an Ethernet data field has at least 46, so 18 bytes of padding are added: bytes, the minimum frame. A question that asks "the size of an ARP frame" wants this 64 (or 60 without the CRC); "the size of an ARP packet" wants 28.
EX 3The ICMP echo checksum
MediumThe checksum of an echo request with identifier 0x1234, sequence number 1 and data abcdefgh, computed and then verified by adding the whole message.
#include <stdint.h>
#include <stdio.h>
static uint32_t sum_words(const uint8_t *p, int n) {
uint32_t s = 0;
for (int i = 0; i < n; i += 2) {
s += (uint32_t)(p[i] << 8 | (i + 1 < n ? p[i + 1] : 0));
s = (s & 0xFFFF) + (s >> 16);
}
return s;
}
int main(void) {
uint8_t msg[16] = {8, 0, 0, 0, 0x12, 0x34, 0x00, 0x01, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
uint16_t c = (uint16_t)~sum_words(msg, 16);
msg[2] = (uint8_t)(c >> 8);
msg[3] = (uint8_t)c;
printf("type 8 code 0 id 0x1234 seq 1: checksum 0x%04X\n", c);
printf("receiver adds all 16 bytes: 0x%04X -> %s\n", (unsigned)sum_words(msg, 16), sum_words(msg, 16) == 0xFFFF ? "valid" : "corrupt");
msg[0] = 0; /* the reply: type 0, checksum recomputed */
msg[2] = msg[3] = 0;
c = (uint16_t)~sum_words(msg, 16);
printf("the echo reply (type 0) has checksum 0x%04X\n", c);
return 0;
}type 8 code 0 id 0x1234 seq 1: checksum 0x5435
receiver adds all 16 bytes: 0xFFFF -> valid
the echo reply (type 0) has checksum 0x5C35Reading it. The checksum is the same ones' complement algorithm as the UDP and IP checksums, over the whole ICMP message (no pseudo header). The first word is (type 8, code 0). The receiver's sum over all words, checksum included, is 0xFFFF. Changing the type to 0 changes the checksum, which is why the reply carries a different (but also valid) value, as the table of the real ping shows.
EX 4Which addresses are in each frame?
GATE levelHost A (192.168.1.10) sends an IP packet to host B (10.0.0.5) on another subnet through router R (192.168.1.1 on A's side, 10.0.0.1 on B's side). In the frame A sends, the destination MAC is R's MAC address on A's LAN (found by ARP for 192.168.1.1), the destination IP is B's address 10.0.0.5. In the frame R sends to B, the source MAC is R's address on B's LAN, the destination MAC is B's, and the IP addresses are still 192.168.1.10 and 10.0.0.5. So: IP addresses are end to end and change only if a NAT rewrites them; MAC addresses are per hop and change at every router. A would not ARP for B's address (B is not on its subnet), only for the gateway's. With empty caches the whole trip needs two ARP exchanges (A for R, R for B) and a second packet needs none.
EX 5DHCP: messages, ports and the lease
GATE levelA client has no address. Its DISCOVER goes from 0.0.0.0, UDP port 68, to 255.255.255.255, UDP port 67: a broadcast because it does not know where the server is, and with source 0.0.0.0 because it has no address. The OFFER and the ACK come from the server's address, port 67, to port 68. The client's REQUEST is also a broadcast. A lease of 8 hours: h (renew with the same server by unicast), h (rebind with any server by broadcast), expiry at 8 h. A successful exchange takes four messages.
#include <stdio.h>
int main(void) {
long leases[4] = {3600, 8 * 3600, 24 * 3600, 7 * 86400};
for (int i = 0; i < 4; i++) {
long L = leases[i];
printf("lease %6ld s: T1 (renew) at %7.1f s, T2 (rebind) at %8.1f s\n", L, L / 2.0, L * 7 / 8.0);
}
int discover = 236 + 4 + 3 + (2 + 4) + 1; /* fixed part, magic cookie, option 53, option 55 with 4 requested items, end */
printf("a DISCOVER with the usual four requested options is %d bytes of DHCP data, %d bytes of IP packet\n", discover, discover + 8 + 20);
return 0;
}lease 3600 s: T1 (renew) at 1800.0 s, T2 (rebind) at 3150.0 s
lease 28800 s: T1 (renew) at 14400.0 s, T2 (rebind) at 25200.0 s
lease 86400 s: T1 (renew) at 43200.0 s, T2 (rebind) at 75600.0 s
lease 604800 s: T1 (renew) at 302400.0 s, T2 (rebind) at 529200.0 s
a DISCOVER with the usual four requested options is 250 bytes of DHCP data, 278 bytes of IP packetCheat box
Cheat box
- ICMP: IP protocol 1, no ports; type, code, checksum; echo 8 / 0; unreachable 3 (code 3 port, code 4 fragmentation needed and DF); time exceeded 11 (TTL). ping and traceroute use it.
- ARP: IP MAC on one LAN; request broadcast, reply unicast; packet 28 bytes, frame 64 bytes (18 padding); type 0x0806.
- Across a router: IP addresses constant, MAC addresses change per hop; ARP is for the next hop (the gateway), never for a host on another subnet.
- DHCP: UDP 67 (server) and 68 (client); DISCOVER, OFFER, REQUEST, ACK; messages broadcast; renew, rebind.
- RARP is obsolete (DHCP replaced it).
Traps and GATE patterns
Connections
Across subjects
No cross-subject links yet.
All three live beside IP: ICMP reports what went wrong with fragmentation (and the TTL), ARP fills in the Ethernet frames of Ethernet, and DHCP, a client of UDP, hands out the addresses and masks of the subnets. A switch forwards the ARP broadcast to every port, which is why broadcasts are what VLANs contain.
PYQs
7 previous year questions from your book. I re-solved each one myself (0 by running or simulating, 7 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the following statements: (i) Address Resolution Protocol (ARP) provides a mapping from an IP address to the corresponding hardware (link-layer) address. (ii) A single TCP segment from a sender S to a receiver R cannot carry both data from S to R and acknowledgment for a segment from R to S. Which ONE of the following is CORRECT?
- (a)Both (i) and (ii) are TRUE
- (b)(i) is TRUE and (ii) is FALSE
- (c)(i) is FALSE and (ii) is TRUE
- (d)Both (i) and (ii) are FALSE
Node X has a TCP connection open to node Y. The packets from X to Y go through an intermediate IP router R. Ethernet switch S is the first switch on the network path between X and R. Consider a packet sent from X to Y over this connection. Which of the following statements is/are TRUE about the destination IP and MAC addresses on this packet at the time it leaves X?
- (a)The destination IP address is the IP address of Y
- (b)The destination MAC address is the MAC address of Y
- (c)The destination MAC address is the MAC address of S
- (d)The destination IP address is the IP address of R COMPUTER NETWORK
Consider the following two statements: S1: Destination MAC address of an ARP reply is a broadcast address. S2: Destination MAC address of an ARP request is a broadcast address. Which one of the following choices is correct?
- (a)S1 is false and S2 is true.
- (b)Both S1 and S2 are false.
- (c)Both S1 and S2 are true.
- (d)S1 is true and S2 is false.
Suppose that in an IP-over-Ethernet network, a machine X wishes to find the MAC address of another machine Y in its subnet. Which one of the following techniques can be used for this?
- (a)X sends an ARP request packet with broadcast IP address in its local subnet
- (b)X sends an ARP request packet to the local gateway's MAC address which then finds the MAC address of Y and sends to X
- (c)X sends an ARP request packet with broadcast MAC address in its local subnet
- (d)X sends an ARP request packet to the local gateway's IP address which then finds the MAC address of Y and sends to X
Which one of the following protocols is NOT used to resolve one form of address to another one?
- (a)DNS
- (b)ARP
- (c)DHCP
- (d)RARP
The address resolution protocol (ARP) is used for:
- (a)Finding the IP address from the DNS
- (b)Finding the IP address of the default gateway
- (c)Finding the IP address that corresponds to a MAC address
- (d)Finding the MAC address that corresponds to an IP address
Which one of the following protocols may need to broadcast some of its messages?
- (a)SMTP
- (b)FTP
- (c)DHCP
- (d)HTTP
Self-check
Question 1
Which of ICMP, ARP and DHCP is carried in UDP?
Show answerHide
DHCP (ports 67 and 68). ICMP is carried directly in IP, ARP directly in Ethernet frames.
Question 2
A host on 10.0.1.0/24 sends to 10.0.2.7 through gateway 10.0.1.1. Whose MAC address is the destination of the frame it sends?
Show answerHide
The gateway's (10.0.1.1), found by ARP; the destination IP is 10.0.2.7.
Question 3
The lease of a DHCP address is 2 hours. When does the client first try to renew, and when does it start to rebind?
Show answerHide
hour (renew, unicast to the same server), hours (rebind, broadcast to any server).
Question 4
A traceroute shows the answers of 3 routers and then the destination. How many probes (with different TTL) were needed, and with which ICMP message did the destination answer to a UDP probe?
Show answerHide
4 probes (TTL 1 to 4). The destination answers destination unreachable, port unreachable (type 3, code 3).
Question 5
How many bytes does an ARP request frame have on the wire, and why not 42?
Show answerHide
64 bytes: , padded by 18 to the minimum data size of 46, plus the 4-byte CRC.
Revision card
One-screen revision
- ICMP: IP protocol 1; echo 8 / 0; unreachable 3 (port 3, frag needed 4); time exceeded 11; ping, traceroute.
- ARP: broadcast request, unicast reply; 28-byte packet in a 64-byte frame; only for the next hop; MACs change per hop, IPs do not.
- DHCP: UDP 67 / 68; DISCOVER, OFFER, REQUEST, ACK; broadcast from 0.0.0.0; , .
References
- ·Kurose, Ross, Computer Networking: A Top-Down Approach (8th edition), Chapter 4, Sections 4.3.3 (DHCP) and 4.4 / 5.4.1 (ICMP; link-layer addressing and ARP)
- ·Tanenbaum, Wetherall, Computer Networks (5th edition), Chapter 5, Section 5.6 (Internet control protocols: ICMP, ARP, DHCP)
- ·Forouzan, Data Communications and Networking (5th edition), Chapters 8 and 19 (ARP, ICMP) and the DHCP section of Chapter 18
Verification
Messages are built and decoded byte by byte with struct (scripts/cn_t2.py). table-icmp-echo records a REAL exchange: an ICMP echo request to 127.0.0.1 through an unprivileged ICMP datagram socket of the machine that generated the tables (macOS here) and the reply read back, with the checksum of both verified; scripts/enum-checks/cn_t2_check.py repeats it with other data. The same script checks 2000 random echo checksums against arithmetic modulo 65535, the 28-byte ARP packet against a hand-written byte list (and the 64-byte frame with 18 bytes of padding), routed delivery over chains of 1 to 4 routers (IP addresses constant, MAC addresses changing at every hop, one ARP exchange per hop, none the second time), and 500 random DHCP messages decoded by hand-written offsets; tests/cn-t2-traces.test.ts recomputes the echo checksum from its fields. The traceroute and DHCP tables are simulations of the protocols with made-up addresses. The ICMP message types and codes, the rules about when ICMP errors are not sent, the ARP cache timeout, and the default DHCP timers (T1 at 50 per cent and T2 at 87.5 per cent of the lease) are quoted from the RFCs from memory and need verification. The C programs on the page are compiled and run by npm run verify:c. Textbook chapter titles are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (CRC remainders, binomial tail, checksums); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)