2 * Routines for BOOTP/DHCP packet disassembly
3 * Gilbert Ramirez <gram@xiexie.org>
5 * $Id: packet-bootp.c,v 1.48 2001/03/13 21:34:23 gram Exp $
7 * The information used comes from:
8 * RFC 951: Bootstrap Protocol
9 * RFC 1542: Clarifications and Extensions for the Bootstrap Protocol
10 * RFC 2131: Dynamic Host Configuration Protocol
11 * RFC 2132: DHCP Options and BOOTP Vendor Extensions
12 * RFC 2489: Procedure for Defining New DHCP Options
13 * RFC 3046: DHCP Relay Agent Information Option
14 * BOOTP and DHCP Parameters
15 * http://www.isi.edu/in-notes/iana/assignments/bootp-dhcp-parameters
17 * Ethereal - Network traffic analyzer
18 * By Gerald Combs <gerald@zing.org>
19 * Copyright 1998 Gerald Combs
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * as published by the Free Software Foundation; either version 2
25 * of the License, or (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 #ifdef HAVE_SYS_TYPES_H
42 # include <sys/types.h>
48 #include "packet-arp.h"
50 static int proto_bootp = -1;
51 static int hf_bootp_type = -1;
52 static int hf_bootp_hw_type = -1;
53 static int hf_bootp_hw_len = -1;
54 static int hf_bootp_hops = -1;
55 static int hf_bootp_id = -1;
56 static int hf_bootp_secs = -1;
57 static int hf_bootp_flag = -1;
58 static int hf_bootp_ip_client = -1;
59 static int hf_bootp_ip_your = -1;
60 static int hf_bootp_ip_server = -1;
61 static int hf_bootp_ip_relay = -1;
62 static int hf_bootp_hw_addr = -1;
63 static int hf_bootp_server = -1;
64 static int hf_bootp_file = -1;
65 static int hf_bootp_cookie = -1;
66 static int hf_bootp_dhcp = -1;
68 static guint ett_bootp = -1;
69 static guint ett_bootp_option = -1;
71 #define UDP_PORT_BOOTPS 67
73 enum field_type { none, ipv4, string, toggle, yes_no, special, opaque,
75 val_u_byte, val_u_short, val_u_long,
80 enum field_type ftype;
83 #define NUM_OPT_INFOS 128
84 #define NUM_O63_SUBOPTS 11
86 static int dissect_netware_ip_suboption(proto_tree *v_tree, tvbuff_t *tvb,
88 static int bootp_dhcp_decode_agent_info(proto_tree *v_tree, tvbuff_t *tvb,
92 get_dhcp_type(guint8 byte)
94 static const char *opt53_text[] = {
95 "Unknown Message Type",
107 if (byte > 0 && byte < (sizeof opt53_text / sizeof opt53_text[0]))
111 return opt53_text[i];
114 /* Returns the number of bytes consumed by this option. */
116 bootp_option(tvbuff_t *tvb, proto_tree *bp_tree, int voff, int eoff)
119 enum field_type ftype;
120 u_char code = tvb_get_guint8(tvb, voff);
123 int i,optp, consumed;
128 static const value_string nbnt_vals[] = {
135 static struct opt_info opt[] = {
136 /* 0 */ { "Padding", none },
137 /* 1 */ { "Subnet Mask", ipv4 },
138 /* 2 */ { "Time Offset", val_s_long },
139 /* 3 */ { "Router", ipv4 },
140 /* 4 */ { "Time Server", ipv4 },
141 /* 5 */ { "Name Server", ipv4 },
142 /* 6 */ { "Domain Name Server", ipv4 },
143 /* 7 */ { "Log Server", ipv4 },
144 /* 8 */ { "Cookie Server", ipv4 },
145 /* 9 */ { "LPR Server", ipv4 },
146 /* 10 */ { "Impress Server", ipv4 },
147 /* 11 */ { "Resource Location Server", ipv4 },
148 /* 12 */ { "Host Name", string },
149 /* 13 */ { "Boot File Size", val_u_short },
150 /* 14 */ { "Merit Dump File", string },
151 /* 15 */ { "Domain Name", string },
152 /* 16 */ { "Swap Server", ipv4 },
153 /* 17 */ { "Root Path", string },
154 /* 18 */ { "Extensions Path", string },
155 /* 19 */ { "IP Forwarding", toggle },
156 /* 20 */ { "Non-Local Source Routing", toggle },
157 /* 21 */ { "Policy Filter", special },
158 /* 22 */ { "Maximum Datagram Reassembly Size", val_u_short },
159 /* 23 */ { "Default IP Time-to-Live", val_u_byte },
160 /* 24 */ { "Path MTU Aging Timeout", time_in_secs },
161 /* 25 */ { "Path MTU Plateau Table", val_u_short },
162 /* 26 */ { "Interface MTU", val_u_short },
163 /* 27 */ { "All Subnets are Local", yes_no },
164 /* 28 */ { "Broadcast Address", ipv4 },
165 /* 29 */ { "Perform Mask Discovery", toggle },
166 /* 30 */ { "Mask Supplier", yes_no },
167 /* 31 */ { "Perform Router Discover", toggle },
168 /* 32 */ { "Router Solicitation Address", ipv4 },
169 /* 33 */ { "Static Route", special },
170 /* 34 */ { "Trailer Encapsulation", toggle },
171 /* 35 */ { "ARP Cache Timeout", time_in_secs },
172 /* 36 */ { "Ethernet Encapsulation", toggle },
173 /* 37 */ { "TCP Default TTL", val_u_byte },
174 /* 38 */ { "TCP Keepalive Interval", time_in_secs },
175 /* 39 */ { "TCP Keepalive Garbage", toggle },
176 /* 40 */ { "Network Information Service Domain", string },
177 /* 41 */ { "Network Information Service Servers", ipv4 },
178 /* 42 */ { "Network Time Protocol Servers", ipv4 },
179 /* 43 */ { "Vendor-Specific Information", special },
180 /* 44 */ { "NetBIOS over TCP/IP Name Server", ipv4 },
181 /* 45 */ { "NetBIOS over TCP/IP Datagram Distribution Name Server", ipv4 },
182 /* 46 */ { "NetBIOS over TCP/IP Node Type", special },
183 /* 47 */ { "NetBIOS over TCP/IP Scope", string },
184 /* 48 */ { "X Window System Font Server", ipv4 },
185 /* 49 */ { "X Window System Display Manager", ipv4 },
186 /* 50 */ { "Requested IP Address", ipv4 },
187 /* 51 */ { "IP Address Lease Time", time_in_secs },
188 /* 52 */ { "Option Overload", special },
189 /* 53 */ { "DHCP Message Type", special },
190 /* 54 */ { "Server Identifier", ipv4 },
191 /* 55 */ { "Parameter Request List", special },
192 /* 56 */ { "Message", string },
193 /* 57 */ { "Maximum DHCP Message Size", val_u_short },
194 /* 58 */ { "Renewal Time Value", time_in_secs },
195 /* 59 */ { "Rebinding Time Value", time_in_secs },
196 /* 60 */ { "Vendor class identifier", opaque },
197 /* 61 */ { "Client identifier", special },
198 /* 62 */ { "Novell/Netware IP domain", string },
199 /* 63 */ { "Novell Options", special },
200 /* 64 */ { "Network Information Service+ Domain", string },
201 /* 65 */ { "Network Information Service+ Servers", ipv4 },
202 /* 66 */ { "TFTP Server Name", string },
203 /* 67 */ { "Bootfile name", string },
204 /* 68 */ { "Mobile IP Home Agent", ipv4 },
205 /* 69 */ { "SMTP Server", ipv4 },
206 /* 70 */ { "POP3 Server", ipv4 },
207 /* 71 */ { "NNTP Server", ipv4 },
208 /* 72 */ { "Default WWW Server", ipv4 },
209 /* 73 */ { "Default Finger Server", ipv4 },
210 /* 74 */ { "Default IRC Server", ipv4 },
211 /* 75 */ { "StreetTalk Server", ipv4 },
212 /* 76 */ { "StreetTalk Directory Assistance Server", ipv4 },
213 /* 77 */ { "User Class Information", opaque },
214 /* 78 */ { "Directory Agent Information", opaque },
215 /* 79 */ { "Service Location Agent Scope", opaque },
216 /* 80 */ { "Naming Authority", opaque },
217 /* 81 */ { "Client Fully Qualified Domain Name", opaque },
218 /* 82 */ { "Agent Information Option", special },
219 /* 83 */ { "Unassigned", opaque },
220 /* 84 */ { "Unassigned", opaque },
221 /* 85 */ { "Novell Directory Services Servers", opaque },
222 /* 86 */ { "Novell Directory Services Tree Name", opaque },
223 /* 87 */ { "Novell Directory Services Context", opaque },
224 /* 88 */ { "IEEE 1003.1 POSIX Timezone", opaque },
225 /* 89 */ { "Fully Qualified Domain Name", opaque },
226 /* 90 */ { "Authentication", opaque },
227 /* 91 */ { "Vines TCP/IP Server Option", opaque },
228 /* 92 */ { "Server Selection Option", opaque },
229 /* 93 */ { "Client System Architecture", opaque },
230 /* 94 */ { "Client Network Device Interface", opaque },
231 /* 95 */ { "Lightweight Directory Access Protocol", opaque },
232 /* 96 */ { "IPv6 Transitions", opaque },
233 /* 97 */ { "UUID/GUID-based Client Identifier", opaque },
234 /* 98 */ { "Open Group's User Authentication", opaque },
235 /* 99 */ { "Unassigned", opaque },
236 /* 100 */ { "Printer Name", opaque },
237 /* 101 */ { "MDHCP multicast address", opaque },
238 /* 102 */ { "Removed/unassigned", opaque },
239 /* 103 */ { "Removed/unassigned", opaque },
240 /* 104 */ { "Removed/unassigned", opaque },
241 /* 105 */ { "Removed/unassigned", opaque },
242 /* 106 */ { "Removed/unassigned", opaque },
243 /* 107 */ { "Removed/unassigned", opaque },
244 /* 108 */ { "Swap Path Option", opaque },
245 /* 109 */ { "Unassigned", opaque },
246 /* 110 */ { "IPX Compability", opaque },
247 /* 111 */ { "Unassigned", opaque },
248 /* 112 */ { "Netinfo Parent Server Address", opaque },
249 /* 113 */ { "Netinfo Parent Server Tag", opaque },
250 /* 114 */ { "URL", opaque },
251 /* 115 */ { "DHCP Failover Protocol", opaque },
252 /* 116 */ { "DHCP Auto-Configuration", opaque },
253 /* 117 */ { "Unassigned", opaque },
254 /* 118 */ { "Unassigned", opaque },
255 /* 119 */ { "Unassigned", opaque },
256 /* 120 */ { "Unassigned", opaque },
257 /* 121 */ { "Unassigned", opaque },
258 /* 122 */ { "Unassigned", opaque },
259 /* 123 */ { "Unassigned", opaque },
260 /* 124 */ { "Unassigned", opaque },
261 /* 125 */ { "Unassigned", opaque },
262 /* 126 */ { "Extension", opaque },
263 /* 127 */ { "Extension", opaque }
266 /* Options whose length isn't "vlen + 2". */
269 case 0: /* Padding */
270 /* check how much padding we have */
271 for (i = voff + 1; i < eoff; i++ ) {
272 if (tvb_get_guint8(tvb, i) != 0) {
278 proto_tree_add_text(bp_tree, tvb, voff, i, "Padding");
283 case 255: /* End Option */
285 proto_tree_add_text(bp_tree, tvb, voff, 1, "End Option");
291 * Get the length of the option, and the number of bytes it
292 * consumes (the length doesn't include the option code or
295 vlen = tvb_get_guint8(tvb, voff+1);
297 if (bp_tree == NULL) {
298 /* Don't put anything in the protocol tree. */
302 text = opt[code].text;
306 case 21: /* Policy Filter */
308 /* one IP address pair */
309 proto_tree_add_text(bp_tree, tvb, voff, consumed,
310 "Option %d: %s = %s/%s", code, text,
311 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)),
312 ip_to_str(tvb_get_ptr(tvb, voff+6, 4)));
314 /* > 1 IP address pair. Let's make a sub-tree */
315 vti = proto_tree_add_text(bp_tree, tvb, voff,
316 consumed, "Option %d: %s", code, text);
317 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
318 for (i = voff + 2; i < voff + consumed; i += 8) {
319 proto_tree_add_text(v_tree, tvb, i, 8, "IP Address/Mask: %s/%s",
320 ip_to_str(tvb_get_ptr(tvb, i, 4)),
321 ip_to_str(tvb_get_ptr(tvb, i+4, 4)));
326 case 33: /* Static Route */
328 /* one IP address pair */
329 proto_tree_add_text(bp_tree, tvb, voff, consumed,
330 "Option %d: %s = %s/%s", code, text,
331 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)),
332 ip_to_str(tvb_get_ptr(tvb, voff+6, 4)));
334 /* > 1 IP address pair. Let's make a sub-tree */
335 vti = proto_tree_add_text(bp_tree, tvb, voff,
336 consumed, "Option %d: %s", code, text);
337 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
338 for (i = voff + 2; i < voff + consumed; i += 8) {
339 proto_tree_add_text(v_tree, tvb, i, 8,
340 "Destination IP Address/Router: %s/%s",
341 ip_to_str(tvb_get_ptr(tvb, i, 4)),
342 ip_to_str(tvb_get_ptr(tvb, i+4, 4)));
347 case 43: /* Vendor-Specific Info */
348 proto_tree_add_text(bp_tree, tvb, voff, consumed,
349 "Option %d: %s", code, text);
352 case 46: /* NetBIOS-over-TCP/IP Node Type */
353 byte = tvb_get_guint8(tvb, voff+2);
354 proto_tree_add_text(bp_tree, tvb, voff, consumed,
355 "Option %d: %s = %s", code, text,
356 val_to_str(byte, nbnt_vals,
357 "Unknown (0x%02x)"));
360 case 53: /* DHCP Message Type */
361 proto_tree_add_text(bp_tree, tvb, voff, 3, "Option %d: %s = DHCP %s",
362 code, text, get_dhcp_type(tvb_get_guint8(tvb, voff+2)));
365 case 55: /* Parameter Request List */
366 vti = proto_tree_add_text(bp_tree, tvb, voff,
367 vlen + 2, "Option %d: %s", code, text);
368 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
369 for (i = 0; i < vlen; i++) {
370 byte = tvb_get_guint8(tvb, voff+2+i);
371 if (byte < NUM_OPT_INFOS) {
372 proto_tree_add_text(v_tree, tvb, voff+2+i, 1, "%d = %s",
373 byte, opt[byte].text);
375 proto_tree_add_text(vti, tvb, voff+2+i, 1,
376 "Unknown Option Code: %d", byte);
381 case 61: /* Client Identifier */
382 /* We *MAY* use hwtype/hwaddr. If we have 7 bytes, I'll
383 guess that the first is the hwtype, and the last 6
388 vti = proto_tree_add_text(bp_tree, tvb, voff,
389 consumed, "Option %d: %s", code, text);
390 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
391 htype = tvb_get_guint8(tvb, voff+2);
392 proto_tree_add_text(v_tree, tvb, voff+2, 1,
394 arphrdtype_to_str(htype,
395 "Unknown (0x%02x)"));
396 proto_tree_add_text(v_tree, tvb, voff+3, 6,
397 "Client hardware address: %s",
398 arphrdaddr_to_str(tvb_get_ptr(tvb, voff+3, 6),
401 /* otherwise, it's opaque data */
402 proto_tree_add_text(bp_tree, tvb, voff, consumed,
403 "Option %d: %s (%d bytes)", code, text, vlen);
407 case 63: /* NetWare/IP options */
408 vti = proto_tree_add_text(bp_tree, tvb, voff,
409 consumed, "Option %d: %s", code, text);
410 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
413 while (optp < voff+consumed)
414 optp = dissect_netware_ip_suboption(v_tree, tvb, optp);
417 case 82: /* Relay Agent Information Option */
418 vti = proto_tree_add_text(bp_tree, tvb, voff, consumed,
419 "Option %d: %s (%d bytes)",
421 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
423 while (optp < voff+consumed) {
424 optp = bootp_dhcp_decode_agent_info(v_tree, tvb, optp);
428 default: /* not special */
433 if (code < NUM_OPT_INFOS) {
434 text = opt[code].text;
435 ftype = opt[code].ftype;
445 proto_tree_add_text(bp_tree, tvb, voff, consumed,
446 "Option %d: %s = %s", code, text,
447 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)));
449 /* > 1 IP addresses. Let's make a sub-tree */
450 vti = proto_tree_add_text(bp_tree, tvb, voff,
451 consumed, "Option %d: %s", code, text);
452 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
453 for (i = voff + 2; i < voff + consumed; i += 4) {
454 proto_tree_add_text(v_tree, tvb, i, 4, "IP Address: %s",
455 ip_to_str(tvb_get_ptr(tvb, i, 4)));
461 /* Fix for non null-terminated string supplied by
462 * John Lines <John.Lines@aeat.co.uk>
464 proto_tree_add_text(bp_tree, tvb, voff, consumed,
465 "Option %d: %s = %.*s", code, text, vlen,
466 tvb_get_ptr(tvb, voff+2, consumed-2));
470 proto_tree_add_text(bp_tree, tvb, voff, consumed,
471 "Option %d: %s (%d bytes)",
478 proto_tree_add_text(bp_tree, tvb, voff, consumed,
479 "Option %d: %s = %d", code, text,
480 tvb_get_ntohs(tvb, voff+2));
483 vti = proto_tree_add_text(bp_tree, tvb, voff,
484 consumed, "Option %d: %s", code, text);
485 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
486 for (i = voff + 2; i < voff + consumed; i += 2) {
487 proto_tree_add_text(v_tree, tvb, i, 4, "Value: %d",
488 tvb_get_ntohs(tvb, i));
494 proto_tree_add_text(bp_tree, tvb, voff, consumed,
495 "Option %d: %s = %d", code, text,
496 tvb_get_ntohl(tvb, voff+2));
500 proto_tree_add_text(bp_tree, tvb, voff, consumed,
501 "Option %d: %s = %d", code, text,
502 tvb_get_guint8(tvb, voff+2));
506 i = tvb_get_guint8(tvb, voff+2);
507 if (i != 0 && i != 1) {
508 proto_tree_add_text(bp_tree, tvb, voff, consumed,
509 "Option %d: %s = Invalid Value %d", code, text,
512 proto_tree_add_text(bp_tree, tvb, voff, consumed,
513 "Option %d: %s = %s", code, text,
514 i == 0 ? "Disabled" : "Enabled");
519 i = tvb_get_guint8(tvb, voff+2);
520 if (i != 0 && i != 1) {
521 proto_tree_add_text(bp_tree, tvb, voff, consumed,
522 "Option %d: %s = Invalid Value %d", code, text,
525 proto_tree_add_text(bp_tree, tvb, voff, consumed,
526 "Option %d: %s = %s", code, text,
527 i == 0 ? "No" : "Yes");
532 time_secs = tvb_get_ntohl(tvb, voff+2);
533 proto_tree_add_text(bp_tree, tvb, voff, consumed,
534 "Option %d: %s = %s", code, text,
535 ((time_secs == 0xffffffff) ?
537 time_secs_to_str(time_secs)));
541 proto_tree_add_text(bp_tree, tvb, voff, consumed,
542 "Option %d: %s (%d bytes)", code, text, vlen);
545 proto_tree_add_text(bp_tree, tvb, voff, consumed,
546 "Unknown Option Code: %d (%d bytes)", code, vlen);
553 bootp_dhcp_decode_agent_info(proto_tree *v_tree, tvbuff_t *tvb, int optp)
558 subopt = tvb_get_guint8(tvb, optp);
559 subopt_len = tvb_get_guint8(tvb, optp+1);
562 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
563 "Agent Circuit ID (%d bytes)", subopt_len);
566 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
567 "Agent Remote ID (%d bytes)", subopt_len);
570 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
571 "Unknown agent option: %d", subopt);
574 optp += (subopt_len + 2);
579 dissect_netware_ip_suboption(proto_tree *v_tree, tvbuff_t *tvb, int optp)
584 proto_tree *o63_v_tree;
587 struct o63_opt_info {
593 static struct o63_opt_info o63_opt[]= {
594 /* 0 */ {"","",none},
595 /* 1 */ {"NWIP does not exist on subnet","",string},
596 /* 2 */ {"NWIP exist in options area","",string},
597 /* 3 */ {"NWIP exists in sname/file","",string},
598 /* 4 */ {"NWIP exists, but too big","",string},
599 /* 5 */ {"Broadcast for nearest Netware server","Do NOT Broadcast for nearest Netware server",yes_no},
600 /* 6 */ {"Preferred DSS server","",ipv4},
601 /* 7 */ {"Nearest NWIP server","",ipv4},
602 /* 8 */ {"Autoretries","",val_u_short},
603 /* 9 */ {"Autoretry delay, secs ","",val_u_short},
604 /* 10*/ {"Support NetWare/IP v1.1","Do NOT support NetWare/IP v1.1",yes_no},
605 /* 11*/ {"Primary DSS ", "" , special}
608 subopt = tvb_get_guint8(tvb, optp);
609 if (subopt > NUM_O63_SUBOPTS) {
610 proto_tree_add_text(v_tree, tvb,optp,1,"Unknown suboption %d", subopt);
613 switch (o63_opt[subopt].ft) {
616 proto_tree_add_text(v_tree, tvb, optp, 2, "Suboption %d: %s", subopt, o63_opt[subopt].truet);
621 if (tvb_get_guint8(tvb, optp+2)==1) {
622 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s", subopt, o63_opt[subopt].truet);
624 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s" , subopt, o63_opt[subopt].falset);
630 proto_tree_add_text(v_tree, tvb, optp, 6,
631 "Suboption %d: %s = %s" ,
632 subopt, o63_opt[subopt].truet,
633 ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
638 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s = %u",
639 subopt, o63_opt[subopt].truet,
640 tvb_get_guint8(tvb, optp+2)); /* XXX - 1 byte? */
645 subopt_len = tvb_get_guint8(tvb, optp+1);
646 if (subopt_len == 4) {
648 proto_tree_add_text(v_tree, tvb, optp, 6,
649 "Suboption %d : %s = %s",
650 subopt, o63_opt[subopt].truet,
651 ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
654 /* > 1 IP addresses. Let's make a sub-tree */
655 vti = proto_tree_add_text(v_tree, tvb, optp,
656 subopt_len+2, "Suboption %d: %s",
657 subopt, o63_opt[subopt].truet);
658 o63_v_tree = proto_item_add_subtree(vti, ett_bootp_option);
659 for (slask = optp + 2 ; slask < optp+subopt_len; slask += 4) {
660 proto_tree_add_text(o63_v_tree, tvb, slask, 4, "IP Address: %s",
661 ip_to_str(tvb_get_ptr(tvb, slask, 4)));
667 proto_tree_add_text(v_tree, tvb,optp,1,"Unknown suboption %d", subopt);
675 #define BOOTREQUEST 1
678 static const value_string op_vals[] = {
679 { BOOTREQUEST, "Boot Request" },
680 { BOOTREPLY, "Boot Reply" },
685 dissect_bootp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
687 proto_tree *bp_tree = NULL;
692 int voff, eoff; /* vender offset, end offset */
694 gboolean is_dhcp = FALSE;
695 const char *dhcp_type;
697 if (check_col(pinfo->fd, COL_PROTOCOL))
698 col_set_str(pinfo->fd, COL_PROTOCOL, "BOOTP");
699 if (check_col(pinfo->fd, COL_INFO)) {
701 * In case we throw an exception fetching the opcode, etc.
703 col_clear(pinfo->fd, COL_INFO);
706 op = tvb_get_guint8(tvb, 0);
707 htype = tvb_get_guint8(tvb, 1);
708 hlen = tvb_get_guint8(tvb, 2);
709 if (check_col(pinfo->fd, COL_INFO)) {
713 col_add_fstr(pinfo->fd, COL_INFO, "Boot Request from %s",
714 arphrdaddr_to_str(tvb_get_ptr(tvb, 28, hlen),
719 col_set_str(pinfo->fd, COL_INFO, "Boot Reply");
723 col_add_fstr(pinfo->fd, COL_INFO, "Unknown BOOTP message type (%u)",
730 ti = proto_tree_add_item(tree, proto_bootp, tvb, 0,
731 tvb_length(tvb), FALSE);
732 bp_tree = proto_item_add_subtree(ti, ett_bootp);
734 proto_tree_add_uint(bp_tree, hf_bootp_type, tvb,
737 proto_tree_add_uint_format(bp_tree, hf_bootp_hw_type, tvb,
741 arphrdtype_to_str(htype,
742 "Unknown (0x%02x)"));
743 proto_tree_add_uint(bp_tree, hf_bootp_hw_len, tvb,
745 proto_tree_add_item(bp_tree, hf_bootp_hops, tvb,
747 proto_tree_add_item(bp_tree, hf_bootp_id, tvb,
749 proto_tree_add_item(bp_tree, hf_bootp_secs, tvb,
751 proto_tree_add_uint(bp_tree, hf_bootp_flag, tvb,
752 10, 2, tvb_get_ntohs(tvb, 10) & 0x8000);
754 proto_tree_add_item(bp_tree, hf_bootp_ip_client, tvb,
756 proto_tree_add_item(bp_tree, hf_bootp_ip_your, tvb,
758 proto_tree_add_item(bp_tree, hf_bootp_ip_server, tvb,
760 proto_tree_add_item(bp_tree, hf_bootp_ip_relay, tvb,
764 haddr = tvb_get_ptr(tvb, 28, hlen);
765 proto_tree_add_bytes_format(bp_tree, hf_bootp_hw_addr, tvb,
768 "Client hardware address: %s",
769 arphrdaddr_to_str(haddr,
774 proto_tree_add_text(bp_tree, tvb,
775 28, 0, "Client address not given");
778 /* The server host name is optional */
779 if (tvb_get_guint8(tvb, 44) != '\0') {
780 proto_tree_add_item(bp_tree, hf_bootp_server, tvb,
784 proto_tree_add_string_format(bp_tree, hf_bootp_server, tvb,
786 tvb_get_ptr(tvb, 44, 1),
787 "Server host name not given");
791 if (tvb_get_guint8(tvb, 108) != '\0') {
792 proto_tree_add_item(bp_tree, hf_bootp_file, tvb,
796 proto_tree_add_string_format(bp_tree, hf_bootp_file, tvb,
798 tvb_get_ptr(tvb, 108, 1),
799 "Boot file name not given");
802 tvb_memcpy(tvb, (void *)&ip_addr, 236, sizeof(ip_addr));
803 if (tvb_get_ntohl(tvb, 236) == 0x63825363) {
804 proto_tree_add_ipv4_format(bp_tree, hf_bootp_cookie, tvb,
806 "Magic cookie: (OK)");
809 proto_tree_add_ipv4(bp_tree, hf_bootp_cookie, tvb,
815 eoff = tvb_reported_length(tvb);
816 while (voff < eoff) {
817 /* Handle the DHCP option specially here, so that we
818 can flag DHCP packets as such. */
819 if (!is_dhcp && tvb_get_guint8(tvb, voff) == 53) {
821 * We haven't already seen a DHCP Type option, and
822 * this is a DHCP Type option, so flag this packet
825 dhcp_type = get_dhcp_type(tvb_get_guint8(tvb, voff+2));
826 if (check_col(pinfo->fd, COL_PROTOCOL))
827 col_set_str(pinfo->fd, COL_PROTOCOL, "DHCP");
828 if (check_col(pinfo->fd, COL_INFO))
829 col_add_fstr(pinfo->fd, COL_INFO, "DHCP %-8s - Transaction ID 0x%x",
830 dhcp_type, tvb_get_ntohl(tvb, 4));
832 proto_tree_add_boolean_hidden(bp_tree, hf_bootp_dhcp,
836 voff += bootp_option(tvb, bp_tree, voff, eoff);
841 proto_register_bootp(void)
843 static hf_register_info hf[] = {
845 { "Frame is DHCP", "bootp.dhcp", FT_BOOLEAN,
846 BASE_NONE, NULL, 0x0,
850 { "Message type", "bootp.type", FT_UINT8,
851 BASE_DEC, VALS(op_vals), 0x0,
855 { "Hardware type", "bootp.hw.type", FT_UINT8,
860 { "Hardware address length", "bootp.hw.len", FT_UINT8,
865 { "Hops", "bootp.hops", FT_UINT8,
870 { "Transaction ID", "bootp.id", FT_UINT32,
875 { "Seconds elapsed", "bootp.secs", FT_UINT16,
880 { "Broadcast flag", "bootp.flag", FT_UINT16,
884 { &hf_bootp_ip_client,
885 { "Client IP address", "bootp.ip.client",FT_IPv4,
886 BASE_NONE, NULL, 0x0,
890 { "Your (client) IP address", "bootp.ip.your", FT_IPv4,
891 BASE_NONE, NULL, 0x0,
894 { &hf_bootp_ip_server,
895 { "Next server IP address", "bootp.ip.server",FT_IPv4,
896 BASE_NONE, NULL, 0x0,
899 { &hf_bootp_ip_relay,
900 { "Relay agent IP address", "bootp.ip.relay", FT_IPv4,
901 BASE_NONE, NULL, 0x0,
905 { "Client hardware address", "bootp.hw.addr", FT_BYTES,
906 BASE_NONE, NULL, 0x0,
910 { "Server host name", "bootp.server", FT_STRING,
911 BASE_NONE, NULL, 0x0,
915 { "Boot file name", "bootp.file", FT_STRING,
916 BASE_NONE, NULL, 0x0,
920 { "Magic cookie", "bootp.cookie", FT_IPv4,
921 BASE_NONE, NULL, 0x0,
924 static gint *ett[] = {
929 proto_bootp = proto_register_protocol("Bootstrap Protocol", "BOOTP/DHCP",
931 proto_register_field_array(proto_bootp, hf, array_length(hf));
932 proto_register_subtree_array(ett, array_length(ett));
936 proto_reg_handoff_bootp(void)
938 dissector_add("udp.port", UDP_PORT_BOOTPS, dissect_bootp, proto_bootp);