2 * Routines for BOOTP/DHCP packet disassembly
3 * Gilbert Ramirez <gram@verdict.uthscsa.edu>
5 * $Id: packet-bootp.c,v 1.3 1998/09/17 03:29:26 gram Exp $
7 * The information used comes from:
8 * RFC 2132: DHCP Options and BOOTP Vendor Extensions
9 * RFC 1542: Clarifications and Extensions for the Bootstrap Protocol
10 * RFC 2131: Dynamic Host Configuration Protocol
12 * Ethereal - Network traffic analyzer
13 * By Gerald Combs <gerald@unicom.net>
14 * Copyright 1998 Gerald Combs
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
44 #ifdef HAVE_NETINET_IN_H
45 # include <netinet/in.h>
54 enum field_type { none, ipv4, string, toggle, yes_no, special, opaque,
55 val_u_byte, val_u_short, val_u_long,
60 enum field_type ftype;
63 #define NUM_OPT_INFOS 77
65 /* returns the number of bytes consumed by this option */
67 bootp_option(const u_char *pd, GtkWidget *bp_tree, int voff, int eoff)
70 enum field_type ftype;
71 u_char code = pd[voff];
72 int vlen = pd[voff+1];
74 GtkWidget *vti, *v_tree;
76 char *opt53_text[] = {
77 "Unknown Message Type",
88 static struct opt_info opt[] = {
89 /* 0 */ { "Padding", none },
90 /* 1 */ { "Subnet Mask", ipv4 },
91 /* 2 */ { "Time Offset", val_s_long },
92 /* 3 */ { "Router", ipv4 },
93 /* 4 */ { "Time Server", ipv4 },
94 /* 5 */ { "Name Server", ipv4 },
95 /* 6 */ { "Domain Name Server", ipv4 },
96 /* 7 */ { "Log Server", ipv4 },
97 /* 8 */ { "Cookie Server", ipv4 },
98 /* 9 */ { "LPR Server", ipv4 },
99 /* 10 */ { "Impress Server", ipv4 },
100 /* 11 */ { "Resource Location Server", ipv4 },
101 /* 12 */ { "Host Name", string },
102 /* 13 */ { "Boot File Size", val_u_short },
103 /* 14 */ { "Merit Dump File", string },
104 /* 15 */ { "Domain Name", string },
105 /* 16 */ { "Swap Server", ipv4 },
106 /* 17 */ { "Root Path", string },
107 /* 18 */ { "Extensions Path", string },
108 /* 19 */ { "IP Forwarding", toggle },
109 /* 20 */ { "Non-Local Source Routing", toggle },
110 /* 21 */ { "Policy Filter", special },
111 /* 22 */ { "Maximum Datagram Reassembly Size", val_u_short },
112 /* 23 */ { "Default IP Time-to-Live", val_u_byte },
113 /* 24 */ { "Path MTU Aging Timeout", val_u_long },
114 /* 25 */ { "Path MTU Plateau Table", val_u_short },
115 /* 26 */ { "Interface MTU", val_u_short },
116 /* 27 */ { "All Subnets are Local", yes_no },
117 /* 28 */ { "Broadcast Address", ipv4 },
118 /* 29 */ { "Perform Mask Discovery", toggle },
119 /* 30 */ { "Mask Supplier", yes_no },
120 /* 31 */ { "Perform Router Discover", toggle },
121 /* 32 */ { "Router Solicitation Address", ipv4 },
122 /* 33 */ { "Static Route", special },
123 /* 34 */ { "Trailer Encapsulation", toggle },
124 /* 35 */ { "ARP Cache Timeout", val_u_long },
125 /* 36 */ { "Ethernet Encapsulation", toggle },
126 /* 37 */ { "TCP Default TTL", val_u_byte },
127 /* 38 */ { "TCP Keepalive Interval", val_u_long },
128 /* 39 */ { "TCP Keepalive Garbage", toggle },
129 /* 40 */ { "Network Information Service Domain", string },
130 /* 41 */ { "Network Information Service Servers", ipv4 },
131 /* 42 */ { "Network Time Protocol Servers", ipv4 },
132 /* 43 */ { "Vendor-Specific Information", special },
133 /* 44 */ { "NetBIOS over TCP/IP Name Server", ipv4 },
134 /* 45 */ { "NetBIOS over TCP/IP Datagram Distribution Name Server", ipv4 },
135 /* 46 */ { "NetBIOS over TCP/IP Node Type", special },
136 /* 47 */ { "NetBIOS over TCP/IP Scope", string },
137 /* 48 */ { "X Window System Font Server", ipv4 },
138 /* 49 */ { "X Window System Display Manager", ipv4 },
139 /* 50 */ { "Requested IP Address", ipv4 },
140 /* 51 */ { "IP Address Lease Time", val_u_long },
141 /* 52 */ { "Option Overload", special },
142 /* 53 */ { "DHCP Message Type", special },
143 /* 54 */ { "Server Identifier", ipv4 },
144 /* 55 */ { "Parameter Request List", opaque },
145 /* 56 */ { "Message", string },
146 /* 57 */ { "Maximum DHCP Message Size", val_u_short },
147 /* 58 */ { "Renewal Time Value", val_u_long },
148 /* 59 */ { "Rebinding Time Value", val_u_long },
149 /* 60 */ { "Vendor class identifier", opaque },
150 /* 61 */ { "Client identifier", special },
151 /* 64 */ { "Network Information Service+ Domain", string },
152 /* 65 */ { "Network Information Service+ Servers", ipv4 },
153 /* 66 */ { "TFTP Server Name", string },
154 /* 67 */ { "Bootfile name", string },
155 /* 68 */ { "Mobile IP Home Agent", ipv4 },
156 /* 69 */ { "SMTP Server", ipv4 },
157 /* 70 */ { "POP3 Server", ipv4 },
158 /* 71 */ { "NNTP Server", ipv4 },
159 /* 72 */ { "Default WWW Server", ipv4 },
160 /* 73 */ { "Default Finger Server", ipv4 },
161 /* 74 */ { "Default IRC Server", ipv4 },
162 /* 75 */ { "StreetTalk Server", ipv4 },
163 /* 76 */ { "StreetTalk Directory Assistance Server", ipv4 }
166 text = opt[code].text;
171 /* check how much padding we have */
172 for (i = voff + 1; i < eoff; i++ ) {
178 add_item_to_tree(bp_tree, voff, i, "Padding");
184 /* one IP address pair */
186 add_item_to_tree(bp_tree, voff, consumed,
187 "Option %d: %s = %s/%s", code, text,
188 ip_to_str((guint8*)&pd[voff+2]),
189 ip_to_str((guint8*)&pd[voff+6]));
191 /* > 1 IP address pair. Let's make a sub-tree */
194 vti = add_item_to_tree(GTK_WIDGET(bp_tree), voff,
195 consumed, "Option %d: %s", code, text);
196 v_tree = gtk_tree_new();
197 add_subtree(vti, v_tree, ETT_BOOTP_OPTION);
198 for (i = voff + 2; i < voff + consumed; i += 8) {
199 add_item_to_tree(v_tree, i, 4, "IP Address/Mask: %s/%s",
200 ip_to_str((guint8*)&pd[i]),
201 ip_to_str((guint8*)&pd[i+4]));
207 /* one IP address pair */
209 add_item_to_tree(bp_tree, voff, consumed,
210 "Option %d: %s = %s/%s", code, text,
211 ip_to_str((guint8*)&pd[voff+2]),
212 ip_to_str((guint8*)&pd[voff+6]));
214 /* > 1 IP address pair. Let's make a sub-tree */
217 vti = add_item_to_tree(GTK_WIDGET(bp_tree), voff,
218 consumed, "Option %d: %s", code, text);
219 v_tree = gtk_tree_new();
220 add_subtree(vti, v_tree, ETT_BOOTP_OPTION);
221 for (i = voff + 2; i < voff + consumed; i += 8) {
222 add_item_to_tree(v_tree, i, 4,
223 "Destination IP Address/Router: %s/%s",
224 ip_to_str((guint8*)&pd[i]),
225 ip_to_str((guint8*)&pd[i+4]));
229 /* DHCP Message Type */
231 if (pd[voff+2] > 0 && pd[voff+2] < 9) {
237 add_item_to_tree(bp_tree, voff, 3, "Option %d: %s = DHCP %s",
238 code, text, opt53_text[i]);
241 /* Client Identifier */
244 /* We *MAY* use hwtype/hwaddr. If we have 7 bytes, I'll
245 guess that the first is the hwtype, and the last 6 are
247 if (pd[voff+1] == 7) {
248 vti = add_item_to_tree(GTK_WIDGET(bp_tree), voff,
249 consumed, "Option %d: %s", code, text);
250 v_tree = gtk_tree_new();
251 add_subtree(vti, v_tree, ETT_BOOTP_OPTION);
252 add_item_to_tree(v_tree, voff+2, 1,
253 "Hardware type: 0x%02x", pd[voff+2]);
254 add_item_to_tree(v_tree, voff+3, 6,
255 "Client hardware address: %s",
256 ether_to_str((guint8*)&pd[voff+3]));
258 /* otherwise, it's opaque data */
260 add_item_to_tree(bp_tree, voff, consumed,
261 "Option %d: %s (%d bytes)", code, text, vlen);
267 add_item_to_tree(bp_tree, voff, 1, "End Option", code);
276 if (code < NUM_OPT_INFOS) {
278 text = opt[code].text;
279 ftype = opt[code].ftype;
285 add_item_to_tree(bp_tree, voff, consumed,
286 "Option %d: %s = %s", code, text,
287 ip_to_str((guint8*)&pd[voff+2]));
289 /* > 1 IP addresses. Let's make a sub-tree */
292 vti = add_item_to_tree(GTK_WIDGET(bp_tree), voff,
293 consumed, "Option %d: %s", code, text);
294 v_tree = gtk_tree_new();
295 add_subtree(vti, v_tree, ETT_BOOTP_OPTION);
296 for (i = voff + 2; i < voff + consumed; i += 4) {
297 add_item_to_tree(v_tree, i, 4, "IP Address: %s",
298 ip_to_str((guint8*)&pd[i]));
304 add_item_to_tree(bp_tree, voff, consumed,
305 "Option %d: %s = %s", code, text, &pd[voff+2]);
309 add_item_to_tree(bp_tree, voff, consumed,
310 "Option %d: %s (%d bytes)",
317 add_item_to_tree(bp_tree, voff, consumed,
318 "Option %d: %s = %d", code, text,
319 pntohs(&pd[voff+2]));
323 vti = add_item_to_tree(GTK_WIDGET(bp_tree), voff,
324 consumed, "Option %d: %s", code, text);
325 v_tree = gtk_tree_new();
326 add_subtree(vti, v_tree, ETT_BOOTP_OPTION);
327 for (i = voff + 2; i < voff + consumed; i += 2) {
328 add_item_to_tree(v_tree, i, 4, "Value: %d",
335 add_item_to_tree(bp_tree, voff, consumed,
336 "Option %d: %s = %d", code, text,
337 pntohl(&pd[voff+2]));
341 add_item_to_tree(bp_tree, voff, consumed,
342 "Option %d: %s = %d", code, text, pd[voff+2]);
347 if (i != 0 && i != 1) {
348 add_item_to_tree(bp_tree, voff, consumed,
349 "Option %d: %s = Invalid Value %d", code, text,
353 add_item_to_tree(bp_tree, voff, consumed,
354 "Option %d: %s = %s", code, text,
355 pd[voff+2] == 0 ? "Disabled" : "Enabled");
361 if (i != 0 && i != 1) {
362 add_item_to_tree(bp_tree, voff, consumed,
363 "Option %d: %s = Invalid Value %d", code, text,
367 add_item_to_tree(bp_tree, voff, consumed,
368 "Option %d: %s = %s", code, text,
369 pd[voff+2] == 0 ? "No" : "Yes");
374 add_item_to_tree(bp_tree, voff, consumed, "Option %d: %s",
379 add_item_to_tree(bp_tree, voff, 1, "Unknown Option Code: %d", code);
386 dissect_bootp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree)
388 GtkWidget *bp_tree, *ti;
389 int voff, eoff; /* vender offset, end offset */
392 if (fd->win_info[0]) {
393 strcpy(fd->win_info[3], "BOOTP");
395 /* if hwaddr is 6 bytes, assume MAC */
396 if (pd[offset] == 1 && pd[offset+2] == 6) {
397 sprintf(fd->win_info[4], "Boot Request from %s",
398 ether_to_str((guint8*)&pd[offset+28]));
401 strcpy(fd->win_info[4], pd[offset] == 1 ? "Boot Request" :
407 ti = add_item_to_tree(GTK_WIDGET(tree), offset, fd->cap_len - offset,
408 "Bootstrap Protocol");
409 bp_tree = gtk_tree_new();
410 add_subtree(ti, bp_tree, ETT_BOOTP);
412 add_item_to_tree(bp_tree, offset, 1, pd[offset] == 1 ?
413 "Boot Request" : "Boot Reply");
414 add_item_to_tree(bp_tree, offset + 1, 1,
415 "Hardware type: 0x%02x", pd[offset+1]);
416 add_item_to_tree(bp_tree, offset + 2, 1,
417 "Hardware address length: %d", pd[offset+2]);
418 add_item_to_tree(bp_tree, offset + 3, 1,
419 "Hops: %d", pd[offset+3]);
420 add_item_to_tree(bp_tree, offset + 4, 4,
421 "Transaction ID: 0x%08x", pntohl(&pd[offset+4]));
422 add_item_to_tree(bp_tree, offset + 8, 2,
423 "Seconds elapsed: %d", pntohs(&pd[offset+8]));
424 add_item_to_tree(bp_tree, offset + 10, 2,
425 "Broadcast flag: %d", pd[offset+10] & 1);
426 add_item_to_tree(bp_tree, offset + 12, 4,
427 "Client IP address: %s", ip_to_str((guint8*)&pd[offset+12]));
428 add_item_to_tree(bp_tree, offset + 16, 4,
429 "Your (client) IP address: %s", ip_to_str((guint8*)&pd[offset+16]));
430 add_item_to_tree(bp_tree, offset + 20, 4,
431 "Next server IP address: %s", ip_to_str((guint8*)&pd[offset+20]));
432 add_item_to_tree(bp_tree, offset + 24, 4,
433 "Relay agent IP address: %s", ip_to_str((guint8*)&pd[offset+24]));
435 /* If HW address is 6 bytes, assume MAC. */
436 if (pd[offset+2] == 6) {
437 add_item_to_tree(bp_tree, offset + 28, 6,
438 "Client hardware address: %s",
439 ether_to_str((guint8*)&pd[offset+28]));
442 add_item_to_tree(bp_tree, offset + 28, 16,
443 "Client hardware address: %02x:%02x%02x:%02x:%02x:%02x:%02x:%02x%02x:%02x%02x:%02x:%02x:%02x:%02x:%02x",
444 pd[offset+28], pd[offset+29], pd[offset+30], pd[offset+31],
445 pd[offset+32], pd[offset+33], pd[offset+34], pd[offset+35],
446 pd[offset+36], pd[offset+37], pd[offset+38], pd[offset+39],
447 pd[offset+40], pd[offset+41], pd[offset+42], pd[offset+43]);
450 /* The server host name is optional */
452 add_item_to_tree(bp_tree, offset + 44, 64,
453 "Server host name: %s", &pd[offset+44]);
456 add_item_to_tree(bp_tree, offset + 44, 64,
457 "Server host name not given");
461 if (pd[offset+108]) {
462 add_item_to_tree(bp_tree, offset + 108, 128,
463 "Boot file nme: %s", &pd[offset+108]);
466 add_item_to_tree(bp_tree, offset + 108, 128,
467 "Boot file name not given");
470 if (pntohl(&pd[offset+236]) == 0x63538263) {
471 add_item_to_tree(bp_tree, offset + 236, 4,
472 "Magic cookie: %s (generic)",
473 ip_to_str((guint8*)&pd[offset+236]));
476 add_item_to_tree(bp_tree, offset + 236, 4,
478 ip_to_str((guint8*)&pd[offset+236]));
484 while (voff < eoff) {
485 voff += bootp_option(pd, bp_tree, voff, eoff);