2 * Routines for BOOTP/DHCP packet disassembly
3 * Gilbert Ramirez <gram@xiexie.org>
5 * $Id: packet-bootp.c,v 1.44 2001/01/03 22:49:06 guy 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 * BOOTP and DHCP Parameters
14 * http://www.isi.edu/in-notes/iana/assignments/bootp-dhcp-parameters
16 * Ethereal - Network traffic analyzer
17 * By Gerald Combs <gerald@zing.org>
18 * Copyright 1998 Gerald Combs
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU General Public License
23 * as published by the Free Software Foundation; either version 2
24 * of the License, or (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
47 #include "packet-arp.h"
49 static int proto_bootp = -1;
50 static int hf_bootp_type = -1;
51 static int hf_bootp_hw_type = -1;
52 static int hf_bootp_hw_len = -1;
53 static int hf_bootp_hops = -1;
54 static int hf_bootp_id = -1;
55 static int hf_bootp_secs = -1;
56 static int hf_bootp_flag = -1;
57 static int hf_bootp_ip_client = -1;
58 static int hf_bootp_ip_your = -1;
59 static int hf_bootp_ip_server = -1;
60 static int hf_bootp_ip_relay = -1;
61 static int hf_bootp_hw_addr = -1;
62 static int hf_bootp_server = -1;
63 static int hf_bootp_file = -1;
64 static int hf_bootp_cookie = -1;
65 static int hf_bootp_dhcp = -1;
67 static guint ett_bootp = -1;
68 static guint ett_bootp_option = -1;
70 #define UDP_PORT_BOOTPS 67
72 enum field_type { none, ipv4, string, toggle, yes_no, special, opaque,
74 val_u_byte, val_u_short, val_u_long,
79 enum field_type ftype;
82 #define NUM_OPT_INFOS 128
83 #define NUM_O63_SUBOPTS 11
85 static int dissect_netware_ip_suboption(proto_tree *v_tree, tvbuff_t *tvb,
89 get_dhcp_type(guint8 byte)
91 static const char *opt53_text[] = {
92 "Unknown Message Type",
104 if (byte > 0 && byte < (sizeof opt53_text / sizeof opt53_text[0]))
108 return opt53_text[i];
111 /* Returns the number of bytes consumed by this option. */
113 bootp_option(tvbuff_t *tvb, proto_tree *bp_tree, int voff, int eoff)
116 enum field_type ftype;
117 u_char code = tvb_get_guint8(tvb, voff);
120 int i,optp, consumed;
125 static const value_string nbnt_vals[] = {
132 static struct opt_info opt[] = {
133 /* 0 */ { "Padding", none },
134 /* 1 */ { "Subnet Mask", ipv4 },
135 /* 2 */ { "Time Offset", val_s_long },
136 /* 3 */ { "Router", ipv4 },
137 /* 4 */ { "Time Server", ipv4 },
138 /* 5 */ { "Name Server", ipv4 },
139 /* 6 */ { "Domain Name Server", ipv4 },
140 /* 7 */ { "Log Server", ipv4 },
141 /* 8 */ { "Cookie Server", ipv4 },
142 /* 9 */ { "LPR Server", ipv4 },
143 /* 10 */ { "Impress Server", ipv4 },
144 /* 11 */ { "Resource Location Server", ipv4 },
145 /* 12 */ { "Host Name", string },
146 /* 13 */ { "Boot File Size", val_u_short },
147 /* 14 */ { "Merit Dump File", string },
148 /* 15 */ { "Domain Name", string },
149 /* 16 */ { "Swap Server", ipv4 },
150 /* 17 */ { "Root Path", string },
151 /* 18 */ { "Extensions Path", string },
152 /* 19 */ { "IP Forwarding", toggle },
153 /* 20 */ { "Non-Local Source Routing", toggle },
154 /* 21 */ { "Policy Filter", special },
155 /* 22 */ { "Maximum Datagram Reassembly Size", val_u_short },
156 /* 23 */ { "Default IP Time-to-Live", val_u_byte },
157 /* 24 */ { "Path MTU Aging Timeout", time_in_secs },
158 /* 25 */ { "Path MTU Plateau Table", val_u_short },
159 /* 26 */ { "Interface MTU", val_u_short },
160 /* 27 */ { "All Subnets are Local", yes_no },
161 /* 28 */ { "Broadcast Address", ipv4 },
162 /* 29 */ { "Perform Mask Discovery", toggle },
163 /* 30 */ { "Mask Supplier", yes_no },
164 /* 31 */ { "Perform Router Discover", toggle },
165 /* 32 */ { "Router Solicitation Address", ipv4 },
166 /* 33 */ { "Static Route", special },
167 /* 34 */ { "Trailer Encapsulation", toggle },
168 /* 35 */ { "ARP Cache Timeout", time_in_secs },
169 /* 36 */ { "Ethernet Encapsulation", toggle },
170 /* 37 */ { "TCP Default TTL", val_u_byte },
171 /* 38 */ { "TCP Keepalive Interval", time_in_secs },
172 /* 39 */ { "TCP Keepalive Garbage", toggle },
173 /* 40 */ { "Network Information Service Domain", string },
174 /* 41 */ { "Network Information Service Servers", ipv4 },
175 /* 42 */ { "Network Time Protocol Servers", ipv4 },
176 /* 43 */ { "Vendor-Specific Information", special },
177 /* 44 */ { "NetBIOS over TCP/IP Name Server", ipv4 },
178 /* 45 */ { "NetBIOS over TCP/IP Datagram Distribution Name Server", ipv4 },
179 /* 46 */ { "NetBIOS over TCP/IP Node Type", special },
180 /* 47 */ { "NetBIOS over TCP/IP Scope", string },
181 /* 48 */ { "X Window System Font Server", ipv4 },
182 /* 49 */ { "X Window System Display Manager", ipv4 },
183 /* 50 */ { "Requested IP Address", ipv4 },
184 /* 51 */ { "IP Address Lease Time", time_in_secs },
185 /* 52 */ { "Option Overload", special },
186 /* 53 */ { "DHCP Message Type", special },
187 /* 54 */ { "Server Identifier", ipv4 },
188 /* 55 */ { "Parameter Request List", special },
189 /* 56 */ { "Message", string },
190 /* 57 */ { "Maximum DHCP Message Size", val_u_short },
191 /* 58 */ { "Renewal Time Value", time_in_secs },
192 /* 59 */ { "Rebinding Time Value", time_in_secs },
193 /* 60 */ { "Vendor class identifier", opaque },
194 /* 61 */ { "Client identifier", special },
195 /* 62 */ { "Novell/Netware IP domain", string },
196 /* 63 */ { "Novell Options", special },
197 /* 64 */ { "Network Information Service+ Domain", string },
198 /* 65 */ { "Network Information Service+ Servers", ipv4 },
199 /* 66 */ { "TFTP Server Name", string },
200 /* 67 */ { "Bootfile name", string },
201 /* 68 */ { "Mobile IP Home Agent", ipv4 },
202 /* 69 */ { "SMTP Server", ipv4 },
203 /* 70 */ { "POP3 Server", ipv4 },
204 /* 71 */ { "NNTP Server", ipv4 },
205 /* 72 */ { "Default WWW Server", ipv4 },
206 /* 73 */ { "Default Finger Server", ipv4 },
207 /* 74 */ { "Default IRC Server", ipv4 },
208 /* 75 */ { "StreetTalk Server", ipv4 },
209 /* 76 */ { "StreetTalk Directory Assistance Server", ipv4 },
210 /* 77 */ { "User Class Information", opaque },
211 /* 78 */ { "Directory Agent Information", opaque },
212 /* 79 */ { "Service Location Agent Scope", opaque },
213 /* 80 */ { "Naming Authority", opaque },
214 /* 81 */ { "Client Fully Qualified Domain Name", opaque },
215 /* 82 */ { "Agent Circuit ID", opaque },
216 /* 83 */ { "Agent Remote ID", opaque },
217 /* 84 */ { "Agent Subnet Mask", opaque },
218 /* 85 */ { "Novell Directory Services Servers", opaque },
219 /* 86 */ { "Novell Directory Services Tree Name", opaque },
220 /* 87 */ { "Novell Directory Services Context", opaque },
221 /* 88 */ { "IEEE 1003.1 POSIX Timezone", opaque },
222 /* 89 */ { "Fully Qualified Domain Name", opaque },
223 /* 90 */ { "Authentication", opaque },
224 /* 91 */ { "Vines TCP/IP Server Option", opaque },
225 /* 92 */ { "Server Selection Option", opaque },
226 /* 93 */ { "Client System Architecture", opaque },
227 /* 94 */ { "Client Network Device Interface", opaque },
228 /* 95 */ { "Lightweight Directory Access Protocol", opaque },
229 /* 96 */ { "IPv6 Transitions", opaque },
230 /* 97 */ { "UUID/GUID-based Client Identifier", opaque },
231 /* 98 */ { "Open Group's User Authentication", opaque },
232 /* 99 */ { "Unassigned", opaque },
233 /* 100 */ { "Printer Name", opaque },
234 /* 101 */ { "MDHCP multicast address", opaque },
235 /* 102 */ { "Removed/unassigned", opaque },
236 /* 103 */ { "Removed/unassigned", opaque },
237 /* 104 */ { "Removed/unassigned", opaque },
238 /* 105 */ { "Removed/unassigned", opaque },
239 /* 106 */ { "Removed/unassigned", opaque },
240 /* 107 */ { "Removed/unassigned", opaque },
241 /* 108 */ { "Swap Path Option", opaque },
242 /* 109 */ { "Unassigned", opaque },
243 /* 110 */ { "IPX Compability", opaque },
244 /* 111 */ { "Unassigned", opaque },
245 /* 112 */ { "Netinfo Parent Server Address", opaque },
246 /* 113 */ { "Netinfo Parent Server Tag", opaque },
247 /* 114 */ { "URL", opaque },
248 /* 115 */ { "DHCP Failover Protocol", opaque },
249 /* 116 */ { "DHCP Auto-Configuration", opaque },
250 /* 117 */ { "Unassigned", opaque },
251 /* 118 */ { "Unassigned", opaque },
252 /* 119 */ { "Unassigned", opaque },
253 /* 120 */ { "Unassigned", opaque },
254 /* 121 */ { "Unassigned", opaque },
255 /* 122 */ { "Unassigned", opaque },
256 /* 123 */ { "Unassigned", opaque },
257 /* 124 */ { "Unassigned", opaque },
258 /* 125 */ { "Unassigned", opaque },
259 /* 126 */ { "Extension", opaque },
260 /* 127 */ { "Extension", opaque }
263 /* Options whose length isn't "vlen + 2". */
266 case 0: /* Padding */
267 /* check how much padding we have */
268 for (i = voff + 1; i < eoff; i++ ) {
269 if (tvb_get_guint8(tvb, i) != 0) {
275 proto_tree_add_text(bp_tree, tvb, voff, i, "Padding");
280 case 255: /* End Option */
282 proto_tree_add_text(bp_tree, tvb, voff, 1, "End Option");
288 * Get the length of the option, and the number of bytes it
289 * consumes (the length doesn't include the option code or
292 vlen = tvb_get_guint8(tvb, voff+1);
294 if (bp_tree == NULL) {
295 /* Don't put anything in the protocol tree. */
299 text = opt[code].text;
303 case 21: /* Policy Filter */
305 /* one IP address pair */
306 proto_tree_add_text(bp_tree, tvb, voff, consumed,
307 "Option %d: %s = %s/%s", code, text,
308 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)),
309 ip_to_str(tvb_get_ptr(tvb, voff+6, 4)));
311 /* > 1 IP address pair. Let's make a sub-tree */
312 vti = proto_tree_add_text(bp_tree, tvb, voff,
313 consumed, "Option %d: %s", code, text);
314 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
315 for (i = voff + 2; i < voff + consumed; i += 8) {
316 proto_tree_add_text(v_tree, tvb, i, 8, "IP Address/Mask: %s/%s",
317 ip_to_str(tvb_get_ptr(tvb, i, 4)),
318 ip_to_str(tvb_get_ptr(tvb, i+4, 4)));
323 case 33: /* Static Route */
325 /* one IP address pair */
326 proto_tree_add_text(bp_tree, tvb, voff, consumed,
327 "Option %d: %s = %s/%s", code, text,
328 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)),
329 ip_to_str(tvb_get_ptr(tvb, voff+6, 4)));
331 /* > 1 IP address pair. Let's make a sub-tree */
332 vti = proto_tree_add_text(bp_tree, tvb, voff,
333 consumed, "Option %d: %s", code, text);
334 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
335 for (i = voff + 2; i < voff + consumed; i += 8) {
336 proto_tree_add_text(v_tree, tvb, i, 8,
337 "Destination IP Address/Router: %s/%s",
338 ip_to_str(tvb_get_ptr(tvb, i, 4)),
339 ip_to_str(tvb_get_ptr(tvb, i+4, 4)));
344 case 43: /* Vendor-Specific Info */
345 proto_tree_add_text(bp_tree, tvb, voff, consumed,
346 "Option %d: %s", code, text);
349 case 46: /* NetBIOS-over-TCP/IP Node Type */
350 byte = tvb_get_guint8(tvb, voff+2);
351 proto_tree_add_text(bp_tree, tvb, voff, consumed,
352 "Option %d: %s = %s", code, text,
353 val_to_str(byte, nbnt_vals,
354 "Unknown (0x%02x)"));
357 case 53: /* DHCP Message Type */
358 proto_tree_add_text(bp_tree, tvb, voff, 3, "Option %d: %s = DHCP %s",
359 code, text, get_dhcp_type(tvb_get_guint8(tvb, voff+2)));
362 case 55: /* Parameter Request List */
363 vti = proto_tree_add_text(bp_tree, tvb, voff,
364 vlen + 2, "Option %d: %s", code, text);
365 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
366 for (i = 0; i < vlen; i++) {
367 byte = tvb_get_guint8(tvb, voff+2+i);
368 if (byte < NUM_OPT_INFOS) {
369 proto_tree_add_text(v_tree, tvb, voff+2+i, 1, "%d = %s",
370 byte, opt[byte].text);
372 proto_tree_add_text(vti, tvb, voff+2+i, 1,
373 "Unknown Option Code: %d", byte);
378 case 61: /* Client Identifier */
379 /* We *MAY* use hwtype/hwaddr. If we have 7 bytes, I'll
380 guess that the first is the hwtype, and the last 6
385 vti = proto_tree_add_text(bp_tree, tvb, voff,
386 consumed, "Option %d: %s", code, text);
387 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
388 htype = tvb_get_guint8(tvb, voff+2);
389 proto_tree_add_text(v_tree, tvb, voff+2, 1,
391 arphrdtype_to_str(htype,
392 "Unknown (0x%02x)"));
393 proto_tree_add_text(v_tree, tvb, voff+3, 6,
394 "Client hardware address: %s",
395 arphrdaddr_to_str(tvb_get_ptr(tvb, voff+3, 6),
398 /* otherwise, it's opaque data */
399 proto_tree_add_text(bp_tree, tvb, voff, consumed,
400 "Option %d: %s (%d bytes)", code, text, vlen);
404 case 63: /* NetWare/IP options */
405 vti = proto_tree_add_text(bp_tree, tvb, voff,
406 consumed, "Option %d: %s", code, text);
407 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
410 while (optp < voff+consumed)
411 optp = dissect_netware_ip_suboption(v_tree, tvb, optp);
414 default: /* not special */
419 if (code < NUM_OPT_INFOS) {
420 text = opt[code].text;
421 ftype = opt[code].ftype;
431 proto_tree_add_text(bp_tree, tvb, voff, consumed,
432 "Option %d: %s = %s", code, text,
433 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)));
435 /* > 1 IP addresses. Let's make a sub-tree */
436 vti = proto_tree_add_text(bp_tree, tvb, voff,
437 consumed, "Option %d: %s", code, text);
438 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
439 for (i = voff + 2; i < voff + consumed; i += 4) {
440 proto_tree_add_text(v_tree, tvb, i, 4, "IP Address: %s",
441 ip_to_str(tvb_get_ptr(tvb, i, 4)));
447 /* Fix for non null-terminated string supplied by
448 * John Lines <John.Lines@aeat.co.uk>
450 proto_tree_add_text(bp_tree, tvb, voff, consumed,
451 "Option %d: %s = %.*s", code, text, vlen,
452 tvb_get_ptr(tvb, voff+2, consumed-2));
456 proto_tree_add_text(bp_tree, tvb, voff, consumed,
457 "Option %d: %s (%d bytes)",
464 proto_tree_add_text(bp_tree, tvb, voff, consumed,
465 "Option %d: %s = %d", code, text,
466 tvb_get_ntohs(tvb, voff+2));
469 vti = proto_tree_add_text(bp_tree, tvb, voff,
470 consumed, "Option %d: %s", code, text);
471 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
472 for (i = voff + 2; i < voff + consumed; i += 2) {
473 proto_tree_add_text(v_tree, tvb, i, 4, "Value: %d",
474 tvb_get_ntohs(tvb, i));
480 proto_tree_add_text(bp_tree, tvb, voff, consumed,
481 "Option %d: %s = %d", code, text,
482 tvb_get_ntohl(tvb, voff+2));
486 proto_tree_add_text(bp_tree, tvb, voff, consumed,
487 "Option %d: %s = %d", code, text,
488 tvb_get_guint8(tvb, voff+2));
492 i = tvb_get_guint8(tvb, voff+2);
493 if (i != 0 && i != 1) {
494 proto_tree_add_text(bp_tree, tvb, voff, consumed,
495 "Option %d: %s = Invalid Value %d", code, text,
498 proto_tree_add_text(bp_tree, tvb, voff, consumed,
499 "Option %d: %s = %s", code, text,
500 i == 0 ? "Disabled" : "Enabled");
505 i = tvb_get_guint8(tvb, voff+2);
506 if (i != 0 && i != 1) {
507 proto_tree_add_text(bp_tree, tvb, voff, consumed,
508 "Option %d: %s = Invalid Value %d", code, text,
511 proto_tree_add_text(bp_tree, tvb, voff, consumed,
512 "Option %d: %s = %s", code, text,
513 i == 0 ? "No" : "Yes");
518 time_secs = tvb_get_ntohl(tvb, voff+2);
519 proto_tree_add_text(bp_tree, tvb, voff, consumed,
520 "Option %d: %s = %s", code, text,
521 ((time_secs == 0xffffffff) ?
523 time_secs_to_str(time_secs)));
527 proto_tree_add_text(bp_tree, tvb, voff, consumed,
528 "Option %d: %s (%d bytes)", code, text, vlen);
531 proto_tree_add_text(bp_tree, tvb, voff, consumed,
532 "Unknown Option Code: %d (%d bytes)", code, vlen);
539 dissect_netware_ip_suboption(proto_tree *v_tree, tvbuff_t *tvb, int optp)
544 proto_tree *o63_v_tree;
547 struct o63_opt_info {
553 static struct o63_opt_info o63_opt[]= {
554 /* 0 */ {"","",none},
555 /* 1 */ {"NWIP does not exist on subnet","",string},
556 /* 2 */ {"NWIP exist in options area","",string},
557 /* 3 */ {"NWIP exists in sname/file","",string},
558 /* 4 */ {"NWIP exists, but too big","",string},
559 /* 5 */ {"Broadcast for nearest Netware server","Do NOT Broadcast for nearest Netware server",yes_no},
560 /* 6 */ {"Preferred DSS server","",ipv4},
561 /* 7 */ {"Nearest NWIP server","",ipv4},
562 /* 8 */ {"Autoretries","",val_u_short},
563 /* 9 */ {"Autoretry delay, secs ","",val_u_short},
564 /* 10*/ {"Support NetWare/IP v1.1","Do NOT support NetWare/IP v1.1",yes_no},
565 /* 11*/ {"Primary DSS ", "" , special}
568 subopt = tvb_get_guint8(tvb, optp);
569 if (subopt > NUM_O63_SUBOPTS) {
570 proto_tree_add_text(v_tree, tvb,optp,1,"Unknown suboption %d", subopt);
573 switch (o63_opt[subopt].ft) {
576 proto_tree_add_text(v_tree, tvb, optp, 2, "Suboption %d: %s", subopt, o63_opt[subopt].truet);
581 if (tvb_get_guint8(tvb, optp+2)==1) {
582 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s", subopt, o63_opt[subopt].truet);
584 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s" , subopt, o63_opt[subopt].falset);
590 proto_tree_add_text(v_tree, tvb, optp, 6,
591 "Suboption %d: %s = %s" ,
592 subopt, o63_opt[subopt].truet,
593 ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
598 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s = %u",
599 subopt, o63_opt[subopt].truet,
600 tvb_get_guint8(tvb, optp+2)); /* XXX - 1 byte? */
605 subopt_len = tvb_get_guint8(tvb, optp+1);
606 if (subopt_len == 4) {
608 proto_tree_add_text(v_tree, tvb, optp, 6,
609 "Suboption %d : %s = %s",
610 subopt, o63_opt[subopt].truet,
611 ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
614 /* > 1 IP addresses. Let's make a sub-tree */
615 vti = proto_tree_add_text(v_tree, tvb, optp,
616 subopt_len+2, "Suboption %d: %s",
617 subopt, o63_opt[subopt].truet);
618 o63_v_tree = proto_item_add_subtree(vti, ett_bootp_option);
619 for (slask = optp + 2 ; slask < optp+subopt_len; slask += 4) {
620 proto_tree_add_text(o63_v_tree, tvb, slask, 4, "IP Address: %s",
621 ip_to_str(tvb_get_ptr(tvb, slask, 4)));
627 proto_tree_add_text(v_tree, tvb,optp,1,"Unknown suboption %d", subopt);
635 #define BOOTREQUEST 1
638 static const value_string op_vals[] = {
639 { BOOTREQUEST, "Boot Request" },
640 { BOOTREPLY, "Boot Reply" },
645 dissect_bootp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
647 proto_tree *bp_tree = NULL;
652 int voff, eoff; /* vender offset, end offset */
654 gboolean is_dhcp = FALSE;
655 const char *dhcp_type;
657 CHECK_DISPLAY_AS_DATA(proto_bootp, tvb, pinfo, tree);
659 pinfo->current_proto = "BOOTP/DHCP";
661 if (check_col(pinfo->fd, COL_PROTOCOL))
662 col_set_str(pinfo->fd, COL_PROTOCOL, "BOOTP");
663 if (check_col(pinfo->fd, COL_INFO)) {
665 * In case we throw an exception fetching the opcode, etc.
667 col_clear(pinfo->fd, COL_INFO);
670 op = tvb_get_guint8(tvb, 0);
671 htype = tvb_get_guint8(tvb, 1);
672 hlen = tvb_get_guint8(tvb, 2);
673 if (check_col(pinfo->fd, COL_INFO)) {
677 col_add_fstr(pinfo->fd, COL_INFO, "Boot Request from %s",
678 arphrdaddr_to_str(tvb_get_ptr(tvb, 28, hlen),
683 col_set_str(pinfo->fd, COL_INFO, "Boot Reply");
687 col_add_fstr(pinfo->fd, COL_INFO, "Unknown BOOTP message type (%u)",
694 ti = proto_tree_add_item(tree, proto_bootp, tvb, 0,
695 tvb_length(tvb), FALSE);
696 bp_tree = proto_item_add_subtree(ti, ett_bootp);
698 proto_tree_add_uint(bp_tree, hf_bootp_type, tvb,
701 proto_tree_add_uint_format(bp_tree, hf_bootp_hw_type, tvb,
705 arphrdtype_to_str(htype,
706 "Unknown (0x%02x)"));
707 proto_tree_add_uint(bp_tree, hf_bootp_hw_len, tvb,
709 proto_tree_add_item(bp_tree, hf_bootp_hops, tvb,
711 proto_tree_add_item(bp_tree, hf_bootp_id, tvb,
713 proto_tree_add_item(bp_tree, hf_bootp_secs, tvb,
715 proto_tree_add_uint(bp_tree, hf_bootp_flag, tvb,
716 10, 2, tvb_get_ntohs(tvb, 10) & 0x8000);
718 proto_tree_add_item(bp_tree, hf_bootp_ip_client, tvb,
720 proto_tree_add_item(bp_tree, hf_bootp_ip_your, tvb,
722 proto_tree_add_item(bp_tree, hf_bootp_ip_server, tvb,
724 proto_tree_add_item(bp_tree, hf_bootp_ip_relay, tvb,
728 haddr = tvb_get_ptr(tvb, 28, hlen);
729 proto_tree_add_bytes_format(bp_tree, hf_bootp_hw_addr, tvb,
732 "Client hardware address: %s",
733 arphrdaddr_to_str(haddr,
738 proto_tree_add_text(bp_tree, tvb,
739 28, 0, "Client address not given");
742 /* The server host name is optional */
743 if (tvb_get_guint8(tvb, 44) != '\0') {
744 proto_tree_add_item(bp_tree, hf_bootp_server, tvb,
748 proto_tree_add_string_format(bp_tree, hf_bootp_server, tvb,
750 tvb_get_ptr(tvb, 44, 1),
751 "Server host name not given");
755 if (tvb_get_guint8(tvb, 108) != '\0') {
756 proto_tree_add_item(bp_tree, hf_bootp_file, tvb,
760 proto_tree_add_string_format(bp_tree, hf_bootp_file, tvb,
762 tvb_get_ptr(tvb, 108, 1),
763 "Boot file name not given");
766 tvb_memcpy(tvb, (void *)&ip_addr, 236, sizeof(ip_addr));
767 if (tvb_get_ntohl(tvb, 236) == 0x63825363) {
768 proto_tree_add_ipv4_format(bp_tree, hf_bootp_cookie, tvb,
770 "Magic cookie: (OK)");
773 proto_tree_add_ipv4(bp_tree, hf_bootp_cookie, tvb,
779 eoff = tvb_reported_length(tvb);
780 while (voff < eoff) {
781 /* Handle the DHCP option specially here, so that we
782 can flag DHCP packets as such. */
783 if (!is_dhcp && tvb_get_guint8(tvb, voff) == 53) {
785 * We haven't already seen a DHCP Type option, and
786 * this is a DHCP Type option, so flag this packet
789 dhcp_type = get_dhcp_type(tvb_get_guint8(tvb, voff+2));
790 if (check_col(pinfo->fd, COL_PROTOCOL))
791 col_set_str(pinfo->fd, COL_PROTOCOL, "DHCP");
792 if (check_col(pinfo->fd, COL_INFO))
793 col_add_fstr(pinfo->fd, COL_INFO, "DHCP %-8s - Transaction ID 0x%x",
794 dhcp_type, tvb_get_ntohl(tvb, 4));
796 proto_tree_add_boolean_hidden(bp_tree, hf_bootp_dhcp,
800 voff += bootp_option(tvb, bp_tree, voff, eoff);
805 proto_register_bootp(void)
807 static hf_register_info hf[] = {
809 { "Frame is DHCP", "bootp.dhcp", FT_BOOLEAN,
810 BASE_NONE, NULL, 0x0,
814 { "Message type", "bootp.type", FT_UINT8,
815 BASE_DEC, VALS(op_vals), 0x0,
819 { "Hardware type", "bootp.hw.type", FT_UINT8,
824 { "Hardware address length", "bootp.hw.len", FT_UINT8,
829 { "Hops", "bootp.hops", FT_UINT8,
834 { "Transaction ID", "bootp.id", FT_UINT32,
839 { "Seconds elapsed", "bootp.secs", FT_UINT16,
844 { "Broadcast flag", "bootp.flag", FT_UINT16,
848 { &hf_bootp_ip_client,
849 { "Client IP address", "bootp.ip.client",FT_IPv4,
850 BASE_NONE, NULL, 0x0,
854 { "Your (client) IP address", "bootp.ip.your", FT_IPv4,
855 BASE_NONE, NULL, 0x0,
858 { &hf_bootp_ip_server,
859 { "Next server IP address", "bootp.ip.server",FT_IPv4,
860 BASE_NONE, NULL, 0x0,
863 { &hf_bootp_ip_relay,
864 { "Relay agent IP address", "bootp.ip.relay", FT_IPv4,
865 BASE_NONE, NULL, 0x0,
869 { "Client hardware address", "bootp.hw.addr", FT_BYTES,
870 BASE_NONE, NULL, 0x0,
874 { "Server host name", "bootp.server", FT_STRING,
875 BASE_NONE, NULL, 0x0,
879 { "Boot file name", "bootp.file", FT_STRING,
880 BASE_NONE, NULL, 0x0,
884 { "Magic cookie", "bootp.cookie", FT_IPv4,
885 BASE_NONE, NULL, 0x0,
888 static gint *ett[] = {
893 proto_bootp = proto_register_protocol("Bootstrap Protocol", "BOOTP/DHCP",
895 proto_register_field_array(proto_bootp, hf, array_length(hf));
896 proto_register_subtree_array(ett, array_length(ett));
900 proto_reg_handoff_bootp(void)
902 dissector_add("udp.port", UDP_PORT_BOOTPS, dissect_bootp);