Make "dissector_add()", "dissector_delete()", and "dissector_change()"
[obnox/wireshark/wip.git] / packet-bootp.c
1 /* packet-bootp.c
2  * Routines for BOOTP/DHCP packet disassembly
3  * Gilbert Ramirez <gram@alumni.rice.edu>
4  *
5  * $Id: packet-bootp.c,v 1.58 2001/12/03 03:59:33 guy Exp $
6  *
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  * RFC 3118: Authentication for DHCP Messages
15  * BOOTP and DHCP Parameters
16  *     http://www.iana.org/assignments/bootp-dhcp-parameters
17  *
18  * Ethereal - Network traffic analyzer
19  * By Gerald Combs <gerald@ethereal.com>
20  * Copyright 1998 Gerald Combs
21  * 
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.
26  * 
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.
31  * 
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.
35  */
36
37 #ifdef HAVE_CONFIG_H
38 # include "config.h"
39 #endif
40
41 #ifdef HAVE_SYS_TYPES_H
42 # include <sys/types.h>
43 #endif
44
45 #include <string.h>
46 #include <glib.h>
47 #include "int-64bit.h"
48 #include "packet.h"
49 #include "packet-arp.h"
50
51 static int proto_bootp = -1;
52 static int hf_bootp_type = -1;
53 static int hf_bootp_hw_type = -1;
54 static int hf_bootp_hw_len = -1;
55 static int hf_bootp_hops = -1;
56 static int hf_bootp_id = -1;
57 static int hf_bootp_secs = -1;
58 static int hf_bootp_flag = -1;
59 static int hf_bootp_ip_client = -1;
60 static int hf_bootp_ip_your = -1;
61 static int hf_bootp_ip_server = -1;
62 static int hf_bootp_ip_relay = -1;
63 static int hf_bootp_hw_addr = -1;
64 static int hf_bootp_server = -1;
65 static int hf_bootp_file = -1;
66 static int hf_bootp_cookie = -1;
67 static int hf_bootp_dhcp = -1;
68
69 static guint ett_bootp = -1;
70 static guint ett_bootp_option = -1;
71
72 #define UDP_PORT_BOOTPS  67
73
74 enum field_type { none, ipv4, string, toggle, yes_no, special, opaque,
75         time_in_secs,
76         val_u_byte, val_u_short, val_u_le_short, val_u_long,
77         val_s_long };
78
79 struct opt_info {
80         char    *text;
81         enum field_type ftype;
82 };
83
84 #define NUM_OPT_INFOS 211
85 #define NUM_O63_SUBOPTS 11
86
87 static int dissect_vendor_pxeclient_suboption(proto_tree *v_tree, tvbuff_t *tvb,
88     int optp);
89 static int dissect_netware_ip_suboption(proto_tree *v_tree, tvbuff_t *tvb,
90     int optp);
91 static int bootp_dhcp_decode_agent_info(proto_tree *v_tree, tvbuff_t *tvb,
92     int optp);
93
94 static const char *
95 get_dhcp_type(guint8 byte)
96 {
97         static const char       *opt53_text[] = {
98                 "Unknown Message Type",
99                 "Discover",
100                 "Offer",
101                 "Request",
102                 "Decline",
103                 "ACK",
104                 "NAK",
105                 "Release",
106                 "Inform"
107         };
108         int i;
109
110         if (byte > 0 && byte < (sizeof opt53_text / sizeof opt53_text[0]))
111                 i = byte;
112         else
113                 i = 0;
114         return opt53_text[i];
115 }
116
117 /* DHCP Authentication protocols */
118 #define AUTHEN_PROTO_CONFIG_TOKEN       0
119 #define AUTHEN_PROTO_DELAYED_AUTHEN     1
120
121 /* DHCP Authentication algorithms for delayed authentication */
122 #define AUTHEN_DELAYED_ALGO_HMAC_MD5    1
123
124 /* DHCP Authentication Replay Detection Methods */
125 #define AUTHEN_RDM_MONOTONIC_COUNTER    0x00
126
127 /* Returns the number of bytes consumed by this option. */
128 static int
129 bootp_option(tvbuff_t *tvb, proto_tree *bp_tree, int voff, int eoff,
130     gboolean first_pass, const char **dhcp_type_p,
131     const guint8 **vendor_class_id_p)
132 {
133         char                    *text;
134         enum field_type         ftype;
135         u_char                  code = tvb_get_guint8(tvb, voff);
136         int                     vlen;
137         u_char                  byte;
138         int                     i,optp, consumed;
139         u_long                  time_secs;
140         proto_tree              *v_tree;
141         proto_item              *vti;
142         guint8                  protocol;
143         guint8                  algorithm;
144         guint8                  rdm;
145
146         static const value_string nbnt_vals[] = {
147             {0x1,   "B-node" },
148             {0x2,   "P-node" },
149             {0x4,   "M-node" },
150             {0x8,   "H-node" },
151             {0,     NULL     } };
152
153         static const value_string authen_protocol_vals[] = {
154             {AUTHEN_PROTO_CONFIG_TOKEN,   "configuration token" },
155             {AUTHEN_PROTO_DELAYED_AUTHEN, "delayed authentication" },
156             {0,                           NULL     } };
157
158         static const value_string authen_da_algo_vals[] = {
159             {AUTHEN_DELAYED_ALGO_HMAC_MD5, "HMAC_MD5" },
160             {0,                            NULL     } };
161
162         static const value_string authen_rdm_vals[] = {
163             {AUTHEN_RDM_MONOTONIC_COUNTER, "Monotonically-increasing counter" },
164             {0,                            NULL     } };
165
166         static struct opt_info opt[] = {
167                 /*   0 */ { "Padding",                                                          none },
168                 /*   1 */ { "Subnet Mask",                                                      ipv4 },
169                 /*   2 */ { "Time Offset",                                                      val_s_long },
170                 /*   3 */ { "Router",                                                           ipv4 },
171                 /*   4 */ { "Time Server",                                                      ipv4 },
172                 /*   5 */ { "Name Server",                                                      ipv4 },
173                 /*   6 */ { "Domain Name Server",                                       ipv4 },
174                 /*   7 */ { "Log Server",                                                       ipv4 },
175                 /*   8 */ { "Cookie Server",                                            ipv4 },
176                 /*   9 */ { "LPR Server",                                                       ipv4 },
177                 /*  10 */ { "Impress Server",                                           ipv4 },
178                 /*  11 */ { "Resource Location Server",                         ipv4 },
179                 /*  12 */ { "Host Name",                                                        string },
180                 /*  13 */ { "Boot File Size",                                           val_u_short },
181                 /*  14 */ { "Merit Dump File",                                          string },
182                 /*  15 */ { "Domain Name",                                                      string },
183                 /*  16 */ { "Swap Server",                                                      ipv4 },
184                 /*  17 */ { "Root Path",                                                        string },
185                 /*  18 */ { "Extensions Path",                                          string },
186                 /*  19 */ { "IP Forwarding",                                            toggle },
187                 /*  20 */ { "Non-Local Source Routing",                         toggle },
188                 /*  21 */ { "Policy Filter",                                            special },
189                 /*  22 */ { "Maximum Datagram Reassembly Size",         val_u_short },
190                 /*  23 */ { "Default IP Time-to-Live",                          val_u_byte },
191                 /*  24 */ { "Path MTU Aging Timeout",                           time_in_secs },
192                 /*  25 */ { "Path MTU Plateau Table",                           val_u_short },
193                 /*  26 */ { "Interface MTU",                                            val_u_short },
194                 /*  27 */ { "All Subnets are Local",                            yes_no },
195                 /*  28 */ { "Broadcast Address",                                        ipv4 },
196                 /*  29 */ { "Perform Mask Discovery",                           toggle },
197                 /*  30 */ { "Mask Supplier",                                            yes_no },
198                 /*  31 */ { "Perform Router Discover",                          toggle },
199                 /*  32 */ { "Router Solicitation Address",                      ipv4 },
200                 /*  33 */ { "Static Route",                                                     special },
201                 /*  34 */ { "Trailer Encapsulation",                            toggle },
202                 /*  35 */ { "ARP Cache Timeout",                                        time_in_secs },
203                 /*  36 */ { "Ethernet Encapsulation",                           toggle },
204                 /*  37 */ { "TCP Default TTL",                                          val_u_byte },
205                 /*  38 */ { "TCP Keepalive Interval",                           time_in_secs },
206                 /*  39 */ { "TCP Keepalive Garbage",                            toggle },
207                 /*  40 */ { "Network Information Service Domain",       string },
208                 /*  41 */ { "Network Information Service Servers",      ipv4 },
209                 /*  42 */ { "Network Time Protocol Servers",            ipv4 },
210                 /*  43 */ { "Vendor-Specific Information",                      special },
211                 /*  44 */ { "NetBIOS over TCP/IP Name Server",          ipv4 },
212                 /*  45 */ { "NetBIOS over TCP/IP Datagram Distribution Name Server", ipv4 },
213                 /*  46 */ { "NetBIOS over TCP/IP Node Type",            special },
214                 /*  47 */ { "NetBIOS over TCP/IP Scope",                        string },
215                 /*  48 */ { "X Window System Font Server",                      ipv4 },
216                 /*  49 */ { "X Window System Display Manager",          ipv4 },
217                 /*  50 */ { "Requested IP Address",                                     ipv4 },
218                 /*  51 */ { "IP Address Lease Time",                            time_in_secs },
219                 /*  52 */ { "Option Overload",                                          special },
220                 /*  53 */ { "DHCP Message Type",                                        special },
221                 /*  54 */ { "Server Identifier",                                        ipv4 },
222                 /*  55 */ { "Parameter Request List",                           special },
223                 /*  56 */ { "Message",                                                          string },
224                 /*  57 */ { "Maximum DHCP Message Size",                        val_u_short },
225                 /*  58 */ { "Renewal Time Value",                                       time_in_secs },
226                 /*  59 */ { "Rebinding Time Value",                                     time_in_secs },
227                 /*  60 */ { "Vendor class identifier",                          special },
228                 /*  61 */ { "Client identifier",                                        special },
229                 /*  62 */ { "Novell/Netware IP domain",                                 string },
230                 /*  63 */ { "Novell Options",   special },
231                 /*  64 */ { "Network Information Service+ Domain",      string },
232                 /*  65 */ { "Network Information Service+ Servers",     ipv4 },
233                 /*  66 */ { "TFTP Server Name",                                         string },
234                 /*  67 */ { "Bootfile name",                                            string },
235                 /*  68 */ { "Mobile IP Home Agent",                                     ipv4 },
236                 /*  69 */ { "SMTP Server",                                                      ipv4 },
237                 /*  70 */ { "POP3 Server",                                                      ipv4 },
238                 /*  71 */ { "NNTP Server",                                                      ipv4 },
239                 /*  72 */ { "Default WWW Server",                                       ipv4 },
240                 /*  73 */ { "Default Finger Server",                            ipv4 },
241                 /*  74 */ { "Default IRC Server",                                       ipv4 },
242                 /*  75 */ { "StreetTalk Server",                                        ipv4 },
243                 /*  76 */ { "StreetTalk Directory Assistance Server", ipv4 },
244                 /*  77 */ { "User Class Information",                           opaque },
245                 /*  78 */ { "Directory Agent Information",                      opaque },
246                 /*  79 */ { "Service Location Agent Scope",                     opaque },
247                 /*  80 */ { "Naming Authority",                                         opaque },
248                 /*  81 */ { "Client Fully Qualified Domain Name",       opaque },
249                 /*  82 */ { "Agent Information Option",                 special },
250                 /*  83 */ { "Unassigned",                               opaque },
251                 /*  84 */ { "Unassigned",                               opaque },
252                 /*  85 */ { "Novell Directory Services Servers",        opaque },
253                 /*  86 */ { "Novell Directory Services Tree Name",      opaque },
254                 /*  87 */ { "Novell Directory Services Context",        opaque },
255                 /*  88 */ { "IEEE 1003.1 POSIX Timezone",                       opaque },
256                 /*  89 */ { "Fully Qualified Domain Name",                      opaque },
257                 /*  90 */ { "Authentication",                           special },
258                 /*  91 */ { "Vines TCP/IP Server Option",                       opaque },
259                 /*  92 */ { "Server Selection Option",                          opaque },
260                 /*  93 */ { "Client System Architecture",                       opaque },
261                 /*  94 */ { "Client Network Device Interface",          opaque },
262                 /*  95 */ { "Lightweight Directory Access Protocol",    opaque },
263                 /*  96 */ { "IPv6 Transitions",                                         opaque },
264                 /*  97 */ { "UUID/GUID-based Client Identifier",        opaque },
265                 /*  98 */ { "Open Group's User Authentication",         opaque },
266                 /*  99 */ { "Unassigned",                                                       opaque },
267                 /* 100 */ { "Printer Name",                                                     opaque },
268                 /* 101 */ { "MDHCP multicast address",                          opaque },
269                 /* 102 */ { "Removed/unassigned",                                       opaque },
270                 /* 103 */ { "Removed/unassigned",                                       opaque },
271                 /* 104 */ { "Removed/unassigned",                                       opaque },
272                 /* 105 */ { "Removed/unassigned",                                       opaque },
273                 /* 106 */ { "Removed/unassigned",                                       opaque },
274                 /* 107 */ { "Removed/unassigned",                                       opaque },
275                 /* 108 */ { "Swap Path Option",                                         opaque },
276                 /* 109 */ { "Unassigned",                                                       opaque },
277                 /* 110 */ { "IPX Compability",                                          opaque },
278                 /* 111 */ { "Unassigned",                                                       opaque },
279                 /* 112 */ { "Netinfo Parent Server Address",            opaque },
280                 /* 113 */ { "Netinfo Parent Server Tag",                        opaque },
281                 /* 114 */ { "URL",                                                                      opaque },
282                 /* 115 */ { "DHCP Failover Protocol",                           opaque },
283                 /* 116 */ { "DHCP Auto-Configuration",                          opaque },
284                 /* 117 */ { "Unassigned",                                                       opaque },
285                 /* 118 */ { "Unassigned",                                                       opaque },
286                 /* 119 */ { "Unassigned",                                                       opaque },
287                 /* 120 */ { "Unassigned",                                                       opaque },
288                 /* 121 */ { "Unassigned",                                                       opaque },
289                 /* 122 */ { "Unassigned",                                                       opaque },
290                 /* 123 */ { "Unassigned",                                                       opaque },
291                 /* 124 */ { "Unassigned",                                                       opaque },
292                 /* 125 */ { "Unassigned",                                                       opaque },
293                 /* 126 */ { "Extension",                                                        opaque },
294                 /* 127 */ { "Extension",                                                        opaque },
295                 /* 128 */ { "Private",                                  opaque },
296                 /* 129 */ { "Private",                                  opaque },
297                 /* 130 */ { "Private",                                  opaque },
298                 /* 131 */ { "Private",                                  opaque },
299                 /* 132 */ { "Private",                                  opaque },
300                 /* 133 */ { "Private",                                  opaque },
301                 /* 134 */ { "Private",                                  opaque },
302                 /* 135 */ { "Private",                                  opaque },
303                 /* 136 */ { "Private",                                  opaque },
304                 /* 137 */ { "Private",                                  opaque },
305                 /* 138 */ { "Private",                                  opaque },
306                 /* 139 */ { "Private",                                  opaque },
307                 /* 140 */ { "Private",                                  opaque },
308                 /* 141 */ { "Private",                                  opaque },
309                 /* 142 */ { "Private",                                  opaque },
310                 /* 143 */ { "Private",                                  opaque },
311                 /* 144 */ { "Private",                                  opaque },
312                 /* 145 */ { "Private",                                  opaque },
313                 /* 146 */ { "Private",                                  opaque },
314                 /* 147 */ { "Private",                                  opaque },
315                 /* 148 */ { "Private",                                  opaque },
316                 /* 149 */ { "Private",                                  opaque },
317                 /* 150 */ { "Private",                                  opaque },
318                 /* 151 */ { "Private",                                  opaque },
319                 /* 152 */ { "Private",                                  opaque },
320                 /* 153 */ { "Private",                                  opaque },
321                 /* 154 */ { "Private",                                  opaque },
322                 /* 155 */ { "Private",                                  opaque },
323                 /* 156 */ { "Private",                                  opaque },
324                 /* 157 */ { "Private",                                  opaque },
325                 /* 158 */ { "Private",                                  opaque },
326                 /* 159 */ { "Private",                                  opaque },
327                 /* 160 */ { "Private",                                  opaque },
328                 /* 161 */ { "Private",                                  opaque },
329                 /* 162 */ { "Private",                                  opaque },
330                 /* 163 */ { "Private",                                  opaque },
331                 /* 164 */ { "Private",                                  opaque },
332                 /* 165 */ { "Private",                                  opaque },
333                 /* 166 */ { "Private",                                  opaque },
334                 /* 167 */ { "Private",                                  opaque },
335                 /* 168 */ { "Private",                                  opaque },
336                 /* 169 */ { "Private",                                  opaque },
337                 /* 170 */ { "Private",                                  opaque },
338                 /* 171 */ { "Private",                                  opaque },
339                 /* 172 */ { "Private",                                  opaque },
340                 /* 173 */ { "Private",                                  opaque },
341                 /* 174 */ { "Private",                                  opaque },
342                 /* 175 */ { "Private",                                  opaque },
343                 /* 176 */ { "Private",                                  opaque },
344                 /* 177 */ { "Private",                                  opaque },
345                 /* 178 */ { "Private",                                  opaque },
346                 /* 179 */ { "Private",                                  opaque },
347                 /* 180 */ { "Private",                                  opaque },
348                 /* 181 */ { "Private",                                  opaque },
349                 /* 182 */ { "Private",                                  opaque },
350                 /* 183 */ { "Private",                                  opaque },
351                 /* 184 */ { "Private",                                  opaque },
352                 /* 185 */ { "Private",                                  opaque },
353                 /* 186 */ { "Private",                                  opaque },
354                 /* 187 */ { "Private",                                  opaque },
355                 /* 188 */ { "Private",                                  opaque },
356                 /* 189 */ { "Private",                                  opaque },
357                 /* 190 */ { "Private",                                  opaque },
358                 /* 191 */ { "Private",                                  opaque },
359                 /* 192 */ { "Private",                                  opaque },
360                 /* 193 */ { "Private",                                  opaque },
361                 /* 194 */ { "Private",                                  opaque },
362                 /* 195 */ { "Private",                                  opaque },
363                 /* 196 */ { "Private",                                  opaque },
364                 /* 197 */ { "Private",                                  opaque },
365                 /* 198 */ { "Private",                                  opaque },
366                 /* 199 */ { "Private",                                  opaque },
367                 /* 200 */ { "Private",                                  opaque },
368                 /* 201 */ { "Private",                                  opaque },
369                 /* 202 */ { "Private",                                  opaque },
370                 /* 203 */ { "Private",                                  opaque },
371                 /* 204 */ { "Private",                                  opaque },
372                 /* 205 */ { "Private",                                  opaque },
373                 /* 206 */ { "Private",                                  opaque },
374                 /* 207 */ { "Private",                                  opaque },
375                 /* 208 */ { "Private",                                  opaque },
376                 /* 209 */ { "Private",                                  opaque },
377                 /* 210 */ { "Authentication",                           special }
378         };
379
380         /* Options whose length isn't "vlen + 2". */
381         switch (code) {
382
383         case 0:         /* Padding */
384                 /* check how much padding we have */
385                 for (i = voff + 1; i < eoff; i++ ) {
386                         if (tvb_get_guint8(tvb, i) != 0) {
387                                 break;
388                         }
389                 }
390                 i = i - voff;
391                 if (!first_pass) {
392                         if (bp_tree != NULL) {
393                                 proto_tree_add_text(bp_tree, tvb, voff, i,
394                                     "Padding");
395                         }
396                 }
397                 consumed = i;
398                 return consumed;
399                 break;
400
401         case 255:       /* End Option */
402                 if (!first_pass) {
403                         if (bp_tree != NULL) {
404                                 proto_tree_add_text(bp_tree, tvb, voff, 1,
405                                     "End Option");
406                         }
407                 }
408                 consumed = 1;
409                 return consumed;
410         }
411
412         /*
413          * Get the length of the option, and the number of bytes it
414          * consumes (the length doesn't include the option code or
415          * length bytes).
416          */
417         vlen = tvb_get_guint8(tvb, voff+1);
418         consumed = vlen + 2;
419
420         /*
421          * In the first pass, we don't put anything into the protocol
422          * tree; we just check for some options we have to look at
423          * in order to properly process the packet:
424          *
425          *      53 (DHCP message type) - if this is present, this is DHCP
426          *
427          *      60 (Vendor class identifier) - we need this in order to
428          *         interpret the vendor-specific info
429          */
430         if (first_pass) {
431                 switch (code) {
432
433                 case 53:
434                         *dhcp_type_p =
435                             get_dhcp_type(tvb_get_guint8(tvb, voff+2));
436                         break;
437
438                 case 60:
439                         *vendor_class_id_p =
440                             tvb_get_ptr(tvb, voff+2, consumed-2);
441                         break;
442                 }
443
444                 /*
445                  * We don't do anything else here.
446                  */
447                 return consumed;
448         }
449
450         /*
451          * This is the second pass - if there's a protocol tree to be
452          * built, we put stuff into it, otherwise we just return.
453          */
454         if (bp_tree == NULL) {
455                 /* Don't put anything in the protocol tree. */
456                 return consumed;
457         }
458
459         text = opt[code].text;
460         /* Special cases */
461         switch (code) {
462
463         case 21:        /* Policy Filter */
464                 if (vlen == 8) {
465                         /* one IP address pair */
466                         proto_tree_add_text(bp_tree, tvb, voff, consumed,
467                                 "Option %d: %s = %s/%s", code, text,
468                                 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)),
469                                 ip_to_str(tvb_get_ptr(tvb, voff+6, 4)));
470                 } else {
471                         /* > 1 IP address pair. Let's make a sub-tree */
472                         vti = proto_tree_add_text(bp_tree, tvb, voff,
473                                 consumed, "Option %d: %s", code, text);
474                         v_tree = proto_item_add_subtree(vti, ett_bootp_option);
475                         for (i = voff + 2; i < voff + consumed; i += 8) {
476                                 proto_tree_add_text(v_tree, tvb, i, 8, "IP Address/Mask: %s/%s",
477                                         ip_to_str(tvb_get_ptr(tvb, i, 4)),
478                                         ip_to_str(tvb_get_ptr(tvb, i+4, 4)));
479                         }
480                 }
481                 break;
482
483         case 33:        /* Static Route */
484                 if (vlen == 8) {
485                         /* one IP address pair */
486                         proto_tree_add_text(bp_tree, tvb, voff, consumed,
487                                 "Option %d: %s = %s/%s", code, text,
488                                 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)),
489                                 ip_to_str(tvb_get_ptr(tvb, voff+6, 4)));
490                 } else {
491                         /* > 1 IP address pair. Let's make a sub-tree */
492                         vti = proto_tree_add_text(bp_tree, tvb, voff,
493                                 consumed, "Option %d: %s", code, text);
494                         v_tree = proto_item_add_subtree(vti, ett_bootp_option);
495                         for (i = voff + 2; i < voff + consumed; i += 8) {
496                                 proto_tree_add_text(v_tree, tvb, i, 8,
497                                         "Destination IP Address/Router: %s/%s",
498                                         ip_to_str(tvb_get_ptr(tvb, i, 4)),
499                                         ip_to_str(tvb_get_ptr(tvb, i+4, 4)));
500                         }
501                 }
502                 break;
503
504         case 43:        /* Vendor-Specific Info */
505                 /* PXE protocol 2.1 as described in the intel specs */
506                 if (*vendor_class_id_p != NULL &&
507                     strncmp(*vendor_class_id_p, "PXEClient", strlen("PXEClient")) == 0) {
508                         vti = proto_tree_add_text(bp_tree, tvb, voff,
509                                 consumed, "Option %d: %s (PXEClient)", code, text);
510                         v_tree = proto_item_add_subtree(vti, ett_bootp_option);
511
512                         optp = voff+2;
513                         while (optp < voff+consumed) {
514                                 optp = dissect_vendor_pxeclient_suboption(v_tree,
515                                         tvb, optp);
516                         }
517                 } else {
518                         proto_tree_add_text(bp_tree, tvb, voff, consumed,
519                                 "Option %d: %s (%d bytes)", code, text, vlen);
520                 }
521                 break;
522
523         case 46:        /* NetBIOS-over-TCP/IP Node Type */
524                 byte = tvb_get_guint8(tvb, voff+2);
525                 proto_tree_add_text(bp_tree, tvb, voff, consumed,
526                                 "Option %d: %s = %s", code, text,
527                                 val_to_str(byte, nbnt_vals,
528                                     "Unknown (0x%02x)"));
529                 break;
530                                 
531         case 53:        /* DHCP Message Type */
532                 proto_tree_add_text(bp_tree, tvb, voff, 3, "Option %d: %s = DHCP %s",
533                         code, text, get_dhcp_type(tvb_get_guint8(tvb, voff+2)));
534                 break;
535
536         case 55:        /* Parameter Request List */
537                 vti = proto_tree_add_text(bp_tree, tvb, voff,
538                         vlen + 2, "Option %d: %s", code, text);
539                 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
540                 for (i = 0; i < vlen; i++) {
541                         byte = tvb_get_guint8(tvb, voff+2+i);
542                         if (byte < NUM_OPT_INFOS) {
543                                 proto_tree_add_text(v_tree, tvb, voff+2+i, 1, "%d = %s",
544                                                 byte, opt[byte].text);
545                         } else {
546                                 proto_tree_add_text(vti, tvb, voff+2+i, 1,
547                                         "Unknown Option Code: %d", byte);
548                         }
549                 }
550                 break;
551
552         case 60:        /* Vendor class identifier */
553                 proto_tree_add_text(bp_tree, tvb, voff, consumed,
554                         "Option %d: %s = \"%.*s\"", code, text, vlen,
555                         tvb_get_ptr(tvb, voff+2, consumed-2));
556                 break;
557
558         case 61:        /* Client Identifier */
559                 /* We *MAY* use hwtype/hwaddr. If we have 7 bytes, I'll
560                    guess that the first is the hwtype, and the last 6
561                    are the hw addr */
562                 if (vlen == 7) {
563                         guint8 htype;
564
565                         vti = proto_tree_add_text(bp_tree, tvb, voff,
566                                 consumed, "Option %d: %s", code, text);
567                         v_tree = proto_item_add_subtree(vti, ett_bootp_option);
568                         htype = tvb_get_guint8(tvb, voff+2);
569                         proto_tree_add_text(v_tree, tvb, voff+2, 1,
570                                 "Hardware type: %s",
571                                 arphrdtype_to_str(htype,
572                                         "Unknown (0x%02x)"));
573                         proto_tree_add_text(v_tree, tvb, voff+3, 6,
574                                 "Client hardware address: %s",
575                                 arphrdaddr_to_str(tvb_get_ptr(tvb, voff+3, 6),
576                                         6, htype));
577                 } else {
578                         /* otherwise, it's opaque data */
579                         proto_tree_add_text(bp_tree, tvb, voff, consumed,
580                                 "Option %d: %s (%d bytes)", code, text, vlen);
581                 }
582                 break;
583
584         case 63:        /* NetWare/IP options */
585                 vti = proto_tree_add_text(bp_tree, tvb, voff,
586                     consumed, "Option %d: %s", code, text);
587                 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
588
589                 optp = voff+2;
590                 while (optp < voff+consumed)
591                         optp = dissect_netware_ip_suboption(v_tree, tvb, optp);
592                 break;
593
594         case 82:        /* Relay Agent Information Option */
595                 vti = proto_tree_add_text(bp_tree, tvb, voff, consumed,
596                                           "Option %d: %s (%d bytes)",
597                                           code, text, vlen);
598                 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
599                 optp = voff+2;
600                 while (optp < voff+consumed) {
601                         optp = bootp_dhcp_decode_agent_info(v_tree, tvb, optp);
602                 }
603                 break;
604
605         case 90:        /* DHCP Authentication */
606         case 210:       /* Was this used for authentication at one time? */
607                 vti = proto_tree_add_text(bp_tree, tvb, voff,
608                         vlen + 2, "Option %d: %s", code, text);
609                 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
610
611                 protocol = tvb_get_guint8(tvb, voff+2);
612                 proto_tree_add_text(v_tree, tvb, voff+2, 1, "Protocol: %s (%u)", 
613                                     val_to_str(protocol, authen_protocol_vals, "Unknown"),
614                                     protocol);
615
616                 algorithm = tvb_get_guint8(tvb, voff+3);
617                 switch (protocol) {
618
619                 case AUTHEN_PROTO_DELAYED_AUTHEN:
620                         proto_tree_add_text(v_tree, tvb, voff+3, 1,
621                                     "Algorithm: %s (%u)",
622                                     val_to_str(algorithm, authen_da_algo_vals, "Unknown"),
623                                     algorithm);
624                         break;
625
626                 default:
627                         proto_tree_add_text(v_tree, tvb, voff+3, 1,
628                                     "Algorithm: %u", algorithm);
629                         break;
630                 }
631
632                 rdm = tvb_get_guint8(tvb, voff+4);
633                 proto_tree_add_text(v_tree, tvb, voff+4, 1,
634                                     "Replay Detection Method: %s (%u)",
635                                     val_to_str(rdm, authen_rdm_vals, "Unknown"),
636                                     rdm);
637
638                 switch (rdm) {
639
640                 case AUTHEN_RDM_MONOTONIC_COUNTER:
641                         proto_tree_add_text(v_tree, tvb, voff+5, 8,
642                                     "Replay Detection Value: %s", 
643                                     u64toh(tvb_get_ptr(tvb, voff+5, 8)));
644                         break;
645
646                 default:
647                         proto_tree_add_text(v_tree, tvb, voff+5, 8,
648                                     "Replay Detection Value: %s", 
649                                     tvb_bytes_to_str(tvb, voff+5, 8));
650                         break;
651                 }
652
653                 switch (protocol) {
654
655                 case AUTHEN_PROTO_DELAYED_AUTHEN:
656                         switch (algorithm) {
657
658                         case AUTHEN_DELAYED_ALGO_HMAC_MD5:
659                                 proto_tree_add_text(v_tree, tvb, voff+13, 4,
660                                         "Secret ID: 0x%08x", 
661                                         tvb_get_ntohl(tvb, voff+13));
662                                 proto_tree_add_text(v_tree, tvb, voff+17, 16,
663                                         "HMAC MD5 Hash: %s",
664                                         tvb_bytes_to_str(tvb, voff+17, 16));
665                                 break;
666
667                         default:
668                                 proto_tree_add_text(v_tree, tvb, voff+13, vlen-11,
669                                         "Authentication Information: %s",
670                                         tvb_bytes_to_str(tvb, voff+17, vlen-11));
671                                 break;
672                         }
673                         break;
674
675                 default:
676                         proto_tree_add_text(v_tree, tvb, voff+13, vlen-11,
677                                 "Authentication Information: %s",
678                                 tvb_bytes_to_str(tvb, voff+17, vlen-11));
679                         break;
680                 }
681                 break;
682
683         default:        /* not special */
684                 break;
685         }
686
687         /* Normal cases */
688         if (code < NUM_OPT_INFOS) {
689                 text = opt[code].text;
690                 ftype = opt[code].ftype;
691
692                 switch (ftype) {
693
694                 case special:
695                         return consumed;
696
697                 case ipv4:
698                         if (vlen == 4) {
699                                 /* one IP address */
700                                 proto_tree_add_text(bp_tree, tvb, voff, consumed,
701                                         "Option %d: %s = %s", code, text,
702                                         ip_to_str(tvb_get_ptr(tvb, voff+2, 4)));
703                         } else {
704                                 /* > 1 IP addresses. Let's make a sub-tree */
705                                 vti = proto_tree_add_text(bp_tree, tvb, voff,
706                                         consumed, "Option %d: %s", code, text);
707                                 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
708                                 for (i = voff + 2; i < voff + consumed; i += 4) {
709                                         proto_tree_add_text(v_tree, tvb, i, 4, "IP Address: %s",
710                                                 ip_to_str(tvb_get_ptr(tvb, i, 4)));
711                                 }
712                         }
713                         break;
714
715                 case string:
716                         /* Fix for non null-terminated string supplied by
717                          * John Lines <John.Lines@aeat.co.uk>
718                          */
719                         proto_tree_add_text(bp_tree, tvb, voff, consumed,
720                                         "Option %d: %s = \"%.*s\"", code, text, vlen,
721                                         tvb_get_ptr(tvb, voff+2, consumed-2));
722                         break;
723
724                 case opaque:
725                         proto_tree_add_text(bp_tree, tvb, voff, consumed,
726                                         "Option %d: %s (%d bytes)",
727                                         code, text, vlen);
728                         break;
729
730                 case val_u_short:
731                         if (vlen == 2) {
732                                 /* one u_short */
733                                 proto_tree_add_text(bp_tree, tvb, voff, consumed,
734                                                 "Option %d: %s = %d", code, text,
735                                                 tvb_get_ntohs(tvb, voff+2));
736                         } else {
737                                 /* > 1 u_short */
738                                 vti = proto_tree_add_text(bp_tree, tvb, voff,
739                                         consumed, "Option %d: %s", code, text);
740                                 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
741                                 for (i = voff + 2; i < voff + consumed; i += 2) {
742                                         proto_tree_add_text(v_tree, tvb, i, 4, "Value: %d",
743                                                 tvb_get_ntohs(tvb, i));
744                                 }
745                         }
746                         break;
747
748                 case val_u_long:
749                         proto_tree_add_text(bp_tree, tvb, voff, consumed,
750                                         "Option %d: %s = %d", code, text,
751                                         tvb_get_ntohl(tvb, voff+2));
752                         break;
753
754                 case val_u_byte:
755                         proto_tree_add_text(bp_tree, tvb, voff, consumed,
756                                         "Option %d: %s = %d", code, text,
757                                         tvb_get_guint8(tvb, voff+2));
758                         break;
759
760                 case toggle:
761                         i = tvb_get_guint8(tvb, voff+2);
762                         if (i != 0 && i != 1) {
763                                 proto_tree_add_text(bp_tree, tvb, voff, consumed,
764                                                 "Option %d: %s = Invalid Value %d", code, text,
765                                                 i);
766                         } else {
767                                 proto_tree_add_text(bp_tree, tvb, voff, consumed,
768                                                 "Option %d: %s = %s", code, text,
769                                                 i == 0 ? "Disabled" : "Enabled");
770                         }
771                         break;
772
773                 case yes_no:
774                         i = tvb_get_guint8(tvb, voff+2);
775                         if (i != 0 && i != 1) {
776                                 proto_tree_add_text(bp_tree, tvb, voff, consumed,
777                                                 "Option %d: %s = Invalid Value %d", code, text,
778                                                 i);
779                         } else {
780                                 proto_tree_add_text(bp_tree, tvb, voff, consumed,
781                                                 "Option %d: %s = %s", code, text,
782                                                 i == 0 ? "No" : "Yes");
783                         }
784                         break;
785
786                 case time_in_secs:
787                         time_secs = tvb_get_ntohl(tvb, voff+2);
788                         proto_tree_add_text(bp_tree, tvb, voff, consumed,
789                                 "Option %d: %s = %s", code, text,
790                                 ((time_secs == 0xffffffff) ?
791                                     "infinity" :
792                                     time_secs_to_str(time_secs)));
793                         break;
794
795                 default:
796                         proto_tree_add_text(bp_tree, tvb, voff, consumed,
797                                         "Option %d: %s (%d bytes)", code, text, vlen);
798                 }
799         } else {
800                 proto_tree_add_text(bp_tree, tvb, voff, consumed,
801                                 "Unknown Option Code: %d (%d bytes)", code, vlen);
802         }
803
804         return consumed;
805 }
806
807 static int
808 bootp_dhcp_decode_agent_info(proto_tree *v_tree, tvbuff_t *tvb, int optp)
809 {
810         guint8 subopt;
811         guint8 subopt_len;
812         
813         subopt = tvb_get_guint8(tvb, optp);
814         subopt_len = tvb_get_guint8(tvb, optp+1);
815         switch (subopt) {
816         case 1:
817                 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
818                                     "Agent Circuit ID (%d bytes)", subopt_len);
819                 break;
820         case 2:
821                 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
822                                     "Agent Remote ID (%d bytes)", subopt_len);
823                 break;
824         default:
825                 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
826                                     "Unknown agent option: %d", subopt);
827                 break;
828         }
829         optp += (subopt_len + 2);
830         return optp;
831 }
832
833 static int
834 dissect_vendor_pxeclient_suboption(proto_tree *v_tree, tvbuff_t *tvb, int optp)
835 {
836         guint8 subopt;
837         guint8 subopt_len;
838         int slask;
839         proto_tree *o43pxeclient_v_tree;
840         proto_item *vti;
841
842         struct o43pxeclient_opt_info { 
843                 char    *text;
844                 enum field_type ft;
845         };
846
847         static struct o43pxeclient_opt_info o43pxeclient_opt[]= {
848                 /* 0 */ {"nop", special},       /* dummy */
849                 /* 1 */ {"PXE mtftp IP", ipv4},
850                 /* 2 */ {"PXE mtftp client port", val_u_le_short},
851                 /* 3 */ {"PXE mtftp server port",val_u_le_short},
852                 /* 4 */ {"PXE mtftp timeout", val_u_byte},
853                 /* 5 */ {"PXE mtftp delay", val_u_byte},
854                 /* 6 */ {"PXE discovery control", val_u_byte},
855                         /*
856                          * Correct: b0 (lsb): disable broadcast discovery
857                          *      b1: disable multicast discovery
858                          *      b2: only use/accept servers in boot servers
859                          *      b3: download bootfile without prompt/menu/disc
860                          */
861                 /* 7 */ {"PXE multicast address", ipv4},
862                 /* 8 */ {"PXE boot servers", special},
863                 /* 9 */ {"PXE boot menu", special},
864                 /* 10 */ {"PXE menu prompt", special},
865                 /* 11 */ {"PXE multicast address alloc", special},
866                 /* 12 */ {"PXE credential types", special},
867                 /* 71 {"PXE boot item", special} */
868                 /* 255 {"PXE end options", special} */
869         };
870 #define NUM_O43PXECLIENT_SUBOPTS (12)
871                 
872         subopt = tvb_get_guint8(tvb, optp);
873
874         if (subopt == 0 ) {
875                 proto_tree_add_text(v_tree, tvb, optp, 1, "Padding");
876                 return (optp+1);
877         } else if (subopt == 255) {     /* End Option */
878                 proto_tree_add_text(v_tree, tvb, optp, 1, "End PXEClient option");
879                 /* Make sure we skip any junk left this option */
880                 return (optp+255);
881         }
882
883         subopt_len = tvb_get_guint8(tvb, optp+1);
884
885         if ( subopt == 71 ) {   /* 71 {"PXE boot item", special} */ 
886                 /* case special */
887                 /* I may need to decode that properly one day */
888                 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
889                         "Suboption %d: %s (%d byte%s)" ,
890                         subopt, "PXE boot item",
891                         subopt_len, (subopt_len != 1)?"s":"");
892         } else if ( (subopt < 1 ) || (subopt > NUM_O43PXECLIENT_SUBOPTS) ) {
893                 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
894                         "Unknown suboption %d (%d byte%s)", subopt, subopt_len,
895                         (subopt_len != 1)?"s":"");
896         } else {
897                 switch (o43pxeclient_opt[subopt].ft) {
898
899 /* XXX          case string:
900                         proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
901                                 "Suboption %d: %s", subopt, o43pxeclient_opt[subopt].text);
902                         break;
903    XXX */
904                 case special:   
905                         /* I may need to decode that properly one day */
906                         proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
907                                 "Suboption %d: %s (%d byte%s)" ,
908                                 subopt, o43pxeclient_opt[subopt].text,
909                                 subopt_len, (subopt_len != 1)?"s":"");
910                         break;
911
912                 case val_u_le_short:
913                         proto_tree_add_text(v_tree, tvb, optp, 4, "Suboption %d: %s = %u",
914                             subopt, o43pxeclient_opt[subopt].text,
915                             tvb_get_letohs(tvb, optp+2));
916                         break;
917                                                         
918                 case val_u_byte:
919                         proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s = %u",
920                             subopt, o43pxeclient_opt[subopt].text,
921                             tvb_get_guint8(tvb, optp+2));
922                         break;
923                                                         
924                 case ipv4:
925                         if (subopt_len == 4) {
926                                 /* one IP address */
927                                 proto_tree_add_text(v_tree, tvb, optp, 6,
928                                     "Suboption %d : %s = %s",
929                                     subopt, o43pxeclient_opt[subopt].text,
930                                     ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
931                         } else {
932                                 /* > 1 IP addresses. Let's make a sub-tree */
933                                 vti = proto_tree_add_text(v_tree, tvb, optp,
934                                     subopt_len+2, "Suboption %d: %s",
935                                     subopt, o43pxeclient_opt[subopt].text);
936                                 o43pxeclient_v_tree = proto_item_add_subtree(vti, ett_bootp_option);
937                                 for (slask = optp + 2 ; slask < optp+subopt_len; slask += 4) {
938                                         proto_tree_add_text(o43pxeclient_v_tree, tvb, slask, 4, "IP Address: %s",
939                                             ip_to_str(tvb_get_ptr(tvb, slask, 4)));
940                                 }
941                         }
942                         break;
943                 default:
944                         proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,"ERROR, please report: Unknown subopt type handler %d", subopt);
945                         break;
946                 }
947         }
948         optp += (subopt_len + 2);
949         return optp;
950 }
951
952 static int
953 dissect_netware_ip_suboption(proto_tree *v_tree, tvbuff_t *tvb, int optp)
954 {
955         guint8 subopt;
956         guint8 subopt_len;
957         int slask;
958         proto_tree *o63_v_tree;
959         proto_item *vti;
960
961         struct o63_opt_info { 
962                 char    *truet;
963                 char    *falset;
964                 enum field_type ft;
965         };
966
967         static struct o63_opt_info o63_opt[]= {
968                 /* 0 */ {"","",none},
969                 /* 1 */ {"NWIP does not exist on subnet","",string},
970                 /* 2 */ {"NWIP exist in options area","",string},
971                 /* 3 */ {"NWIP exists in sname/file","",string},
972                 /* 4 */ {"NWIP exists, but too big","",string},
973                 /* 5 */ {"Broadcast for nearest Netware server","Do NOT Broadcast for nearest Netware server",yes_no}, 
974                 /* 6 */ {"Preferred DSS server","",ipv4},
975                 /* 7 */ {"Nearest NWIP server","",ipv4},
976                 /* 8 */ {"Autoretries","",val_u_short},
977                 /* 9 */ {"Autoretry delay, secs ","",val_u_short},
978                 /* 10*/ {"Support NetWare/IP v1.1","Do NOT support NetWare/IP v1.1",yes_no},
979                 /* 11*/ {"Primary DSS ", "" , special}
980         };
981                 
982         subopt = tvb_get_guint8(tvb, optp);
983         if (subopt > NUM_O63_SUBOPTS) {
984                 proto_tree_add_text(v_tree, tvb,optp,1,"Unknown suboption %d", subopt);
985                 optp++;
986         } else {
987                 switch (o63_opt[subopt].ft) {
988
989                 case string:
990                         proto_tree_add_text(v_tree, tvb, optp, 2, "Suboption %d: %s", subopt, o63_opt[subopt].truet);
991                         optp+=2;
992                         break;
993
994                 case yes_no:
995                         if (tvb_get_guint8(tvb, optp+2)==1) {
996                                 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s", subopt, o63_opt[subopt].truet);
997                         } else {
998                                 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s" , subopt, o63_opt[subopt].falset);
999                         }
1000                         optp+=3;
1001                         break;
1002
1003                 case special:   
1004                         proto_tree_add_text(v_tree, tvb, optp, 6,
1005                             "Suboption %d: %s = %s" ,
1006                             subopt, o63_opt[subopt].truet,
1007                             ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
1008                         optp=optp+6;
1009                         break;
1010
1011                 case val_u_short:
1012                         proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s = %u",
1013                             subopt, o63_opt[subopt].truet,
1014                             tvb_get_guint8(tvb, optp+2));       /* XXX - 1 byte? */
1015                         optp+=3;
1016                         break;
1017                                                         
1018                 case ipv4:
1019                         subopt_len = tvb_get_guint8(tvb, optp+1);
1020                         if (subopt_len == 4) {
1021                                 /* one IP address */
1022                                 proto_tree_add_text(v_tree, tvb, optp, 6,
1023                                     "Suboption %d : %s = %s",
1024                                     subopt, o63_opt[subopt].truet,
1025                                     ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
1026                                 optp=optp+6;
1027                         } else {
1028                                 /* > 1 IP addresses. Let's make a sub-tree */
1029                                 vti = proto_tree_add_text(v_tree, tvb, optp,
1030                                     subopt_len+2, "Suboption %d: %s",
1031                                     subopt, o63_opt[subopt].truet);
1032                                 o63_v_tree = proto_item_add_subtree(vti, ett_bootp_option);
1033                                 for (slask = optp + 2 ; slask < optp+subopt_len; slask += 4) {
1034                                         proto_tree_add_text(o63_v_tree, tvb, slask, 4, "IP Address: %s",
1035                                             ip_to_str(tvb_get_ptr(tvb, slask, 4)));
1036                                 }
1037                                 optp=slask;
1038                         }
1039                         break;
1040                 default:
1041                         proto_tree_add_text(v_tree, tvb,optp,1,"Unknown suboption %d", subopt);
1042                         optp++;
1043                         break;
1044                 }
1045         }
1046         return optp;
1047 }
1048
1049 #define BOOTREQUEST     1
1050 #define BOOTREPLY       2
1051
1052 static const value_string op_vals[] = {
1053         { BOOTREQUEST,  "Boot Request" },
1054         { BOOTREPLY,    "Boot Reply" },
1055         { 0,            NULL }
1056 };
1057
1058 static void
1059 dissect_bootp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1060 {
1061         proto_tree      *bp_tree = NULL;
1062         proto_item      *ti;
1063         guint8          op;
1064         guint8          htype, hlen;
1065         const guint8    *haddr;
1066         int             voff, eoff, tmpvoff; /* vendor offset, end offset */
1067         guint32         ip_addr;
1068         const char      *dhcp_type = NULL;
1069         const guint8    *vendor_class_id = NULL;
1070
1071         if (check_col(pinfo->fd, COL_PROTOCOL))
1072                 col_set_str(pinfo->fd, COL_PROTOCOL, "BOOTP");
1073         if (check_col(pinfo->fd, COL_INFO)) {
1074                 /*
1075                  * In case we throw an exception fetching the opcode, etc.
1076                  */
1077                 col_clear(pinfo->fd, COL_INFO);
1078         }
1079
1080         op = tvb_get_guint8(tvb, 0);
1081         htype = tvb_get_guint8(tvb, 1);
1082         hlen = tvb_get_guint8(tvb, 2);
1083         if (check_col(pinfo->fd, COL_INFO)) {
1084                 switch (op) {
1085
1086                 case BOOTREQUEST:
1087                         col_add_fstr(pinfo->fd, COL_INFO, "Boot Request from %s",
1088                                 arphrdaddr_to_str(tvb_get_ptr(tvb, 28, hlen),
1089                                         hlen, htype));
1090                         break;
1091
1092                 case BOOTREPLY:
1093                         col_set_str(pinfo->fd, COL_INFO, "Boot Reply");
1094                         break;
1095
1096                 default:
1097                         col_add_fstr(pinfo->fd, COL_INFO, "Unknown BOOTP message type (%u)",
1098                             op);
1099                         break;
1100                 }
1101         }
1102
1103         if (tree) {
1104                 ti = proto_tree_add_item(tree, proto_bootp, tvb, 0,
1105                     tvb_length(tvb), FALSE);
1106                 bp_tree = proto_item_add_subtree(ti, ett_bootp);
1107
1108                 proto_tree_add_uint(bp_tree, hf_bootp_type, tvb, 
1109                                            0, 1,
1110                                            op);
1111                 proto_tree_add_uint_format(bp_tree, hf_bootp_hw_type, tvb,
1112                                            1, 1,
1113                                            htype,
1114                                            "Hardware type: %s",
1115                                            arphrdtype_to_str(htype,
1116                                                              "Unknown (0x%02x)"));
1117                 proto_tree_add_uint(bp_tree, hf_bootp_hw_len, tvb,
1118                                     2, 1, hlen);
1119                 proto_tree_add_item(bp_tree, hf_bootp_hops, tvb,
1120                                     3, 1, FALSE);
1121                 proto_tree_add_item(bp_tree, hf_bootp_id, tvb,
1122                                     4, 4, FALSE);
1123                 proto_tree_add_item(bp_tree, hf_bootp_secs, tvb,
1124                                     8, 2, FALSE);
1125                 proto_tree_add_uint(bp_tree, hf_bootp_flag, tvb,
1126                                     10, 2, tvb_get_ntohs(tvb, 10) & 0x8000);
1127
1128                 proto_tree_add_item(bp_tree, hf_bootp_ip_client, tvb, 
1129                                     12, 4, FALSE);
1130                 proto_tree_add_item(bp_tree, hf_bootp_ip_your, tvb, 
1131                                     16, 4, FALSE);
1132                 proto_tree_add_item(bp_tree, hf_bootp_ip_server, tvb,
1133                                     20, 4, FALSE);
1134                 proto_tree_add_item(bp_tree, hf_bootp_ip_relay, tvb,
1135                                     24, 4, FALSE);
1136
1137                 if (hlen > 0) {
1138                         haddr = tvb_get_ptr(tvb, 28, hlen);
1139                         proto_tree_add_bytes_format(bp_tree, hf_bootp_hw_addr, tvb, 
1140                                                    28, hlen,
1141                                                    haddr,
1142                                                    "Client hardware address: %s",
1143                                                    arphrdaddr_to_str(haddr,
1144                                                                      hlen,
1145                                                                      htype));
1146                 }
1147                 else {
1148                         proto_tree_add_text(bp_tree,  tvb,
1149                                                    28, 0, "Client address not given");
1150                 }
1151
1152                 /* The server host name is optional */
1153                 if (tvb_get_guint8(tvb, 44) != '\0') {
1154                         proto_tree_add_item(bp_tree, hf_bootp_server, tvb,
1155                                                    44, 64, FALSE);
1156                 }
1157                 else {
1158                         proto_tree_add_string_format(bp_tree, hf_bootp_server, tvb,
1159                                                    44, 64,
1160                                                    tvb_get_ptr(tvb, 44, 1),
1161                                                    "Server host name not given");
1162                 }
1163
1164                 /* Boot file */
1165                 if (tvb_get_guint8(tvb, 108) != '\0') {
1166                         proto_tree_add_item(bp_tree, hf_bootp_file, tvb,
1167                                                    108, 128, FALSE);
1168                 }
1169                 else {
1170                         proto_tree_add_string_format(bp_tree, hf_bootp_file, tvb,
1171                                                    108, 128,
1172                                                    tvb_get_ptr(tvb, 108, 1),
1173                                                    "Boot file name not given");
1174                 }
1175
1176                 tvb_memcpy(tvb, (void *)&ip_addr, 236, sizeof(ip_addr));
1177                 if (tvb_get_ntohl(tvb, 236) == 0x63825363) {
1178                         proto_tree_add_ipv4_format(bp_tree, hf_bootp_cookie, tvb,
1179                                             236, 4, ip_addr,
1180                                             "Magic cookie: (OK)");
1181                 }
1182                 else {
1183                         proto_tree_add_ipv4(bp_tree, hf_bootp_cookie, tvb,
1184                                             236, 4, ip_addr);
1185                 }
1186         }
1187
1188         voff = 240;
1189         eoff = tvb_reported_length(tvb);
1190
1191         /*
1192          * In the first pass, we just look for the DHCP message type
1193          * and Vendor class identifier options.
1194          */
1195         tmpvoff = voff;
1196         while (tmpvoff < eoff) {
1197                 tmpvoff += bootp_option(tvb, 0, tmpvoff, eoff, TRUE,
1198                     &dhcp_type, &vendor_class_id);
1199         }
1200
1201         /*
1202          * If there was a DHCP message type option, flag this packet
1203          * as DHCP.
1204          */
1205         if (dhcp_type != NULL) {
1206                 /*
1207                  * Yes, this is a DHCP packet, and "dhcp_type" is the
1208                  * packet type.
1209                  */
1210                 if (check_col(pinfo->fd, COL_PROTOCOL))
1211                         col_set_str(pinfo->fd, COL_PROTOCOL, "DHCP");
1212                 if (check_col(pinfo->fd, COL_INFO))
1213                         col_add_fstr(pinfo->fd, COL_INFO, "DHCP %-8s - Transaction ID 0x%x",
1214                             dhcp_type, tvb_get_ntohl(tvb, 4));
1215                 if (tree)
1216                         proto_tree_add_boolean_hidden(bp_tree, hf_bootp_dhcp,
1217                             tvb, 0, 0, 1);
1218         }
1219
1220         /*
1221          * If we're not building the protocol tree, we don't need to
1222          * make a second pass.
1223          */
1224         if (tree == NULL)
1225                 return;
1226
1227         /*
1228          * OK, now build the protocol tree.
1229          */
1230         while (voff < eoff) {
1231                 voff += bootp_option(tvb, bp_tree, voff, eoff, FALSE,
1232                     &dhcp_type, &vendor_class_id);
1233         }
1234 }
1235
1236 void
1237 proto_register_bootp(void)
1238 {
1239   static hf_register_info hf[] = {
1240     { &hf_bootp_dhcp,
1241       { "Frame is DHCP",                "bootp.dhcp",    FT_BOOLEAN,
1242         BASE_NONE,                      NULL,            0x0,
1243         "", HFILL }},                            
1244                       
1245     { &hf_bootp_type,
1246       { "Message type",                 "bootp.type",    FT_UINT8,
1247          BASE_DEC,                      VALS(op_vals),   0x0,
1248         "", HFILL }},
1249
1250     { &hf_bootp_hw_type,
1251       { "Hardware type",                "bootp.hw.type", FT_UINT8,
1252         BASE_HEX,                       NULL,            0x0,
1253         "", HFILL }},
1254
1255     { &hf_bootp_hw_len,
1256       { "Hardware address length",      "bootp.hw.len",  FT_UINT8,
1257         BASE_DEC,                       NULL,            0x0,
1258         "", HFILL }},
1259
1260     { &hf_bootp_hops,
1261       { "Hops",                         "bootp.hops",    FT_UINT8,
1262         BASE_DEC,                       NULL,            0x0,
1263         "", HFILL }},
1264
1265     { &hf_bootp_id,
1266       { "Transaction ID",               "bootp.id",      FT_UINT32,
1267         BASE_HEX,                        NULL,           0x0,
1268         "", HFILL }},
1269
1270     { &hf_bootp_secs,
1271       { "Seconds elapsed",              "bootp.secs",    FT_UINT16,
1272         BASE_DEC,                        NULL,           0x0,
1273         "", HFILL }},
1274
1275     { &hf_bootp_flag,
1276       { "Broadcast flag",               "bootp.flag",    FT_UINT16,
1277         BASE_HEX,                       NULL,            0x0,
1278         "", HFILL }},
1279
1280     { &hf_bootp_ip_client,
1281       { "Client IP address",            "bootp.ip.client",FT_IPv4,
1282         BASE_NONE,                      NULL,             0x0,
1283         "", HFILL }},
1284
1285     { &hf_bootp_ip_your,
1286       { "Your (client) IP address",     "bootp.ip.your",  FT_IPv4,
1287         BASE_NONE,                      NULL,             0x0,
1288         "", HFILL }},
1289
1290     { &hf_bootp_ip_server,
1291       { "Next server IP address",       "bootp.ip.server",FT_IPv4,
1292         BASE_NONE,                      NULL,             0x0,
1293         "", HFILL }},
1294
1295     { &hf_bootp_ip_relay,
1296       { "Relay agent IP address",       "bootp.ip.relay", FT_IPv4,
1297         BASE_NONE,                      NULL,             0x0,
1298         "", HFILL }},
1299
1300     { &hf_bootp_hw_addr,
1301       { "Client hardware address",      "bootp.hw.addr", FT_BYTES,
1302         BASE_NONE,                      NULL,            0x0,
1303         "", HFILL }},
1304
1305     { &hf_bootp_server,
1306       { "Server host name",             "bootp.server",  FT_STRING,
1307         BASE_NONE,                      NULL,            0x0,
1308         "", HFILL }},
1309
1310     { &hf_bootp_file,
1311       { "Boot file name",               "bootp.file",    FT_STRING,
1312         BASE_NONE,                      NULL,            0x0,
1313         "", HFILL }},
1314
1315     { &hf_bootp_cookie,
1316       { "Magic cookie",                 "bootp.cookie",  FT_IPv4,
1317          BASE_NONE,                     NULL,            0x0,
1318         "", HFILL }},
1319   };
1320   static gint *ett[] = {
1321     &ett_bootp,
1322     &ett_bootp_option,
1323   };
1324   
1325   proto_bootp = proto_register_protocol("Bootstrap Protocol", "BOOTP/DHCP",
1326                                         "bootp");
1327   proto_register_field_array(proto_bootp, hf, array_length(hf));
1328   proto_register_subtree_array(ett, array_length(ett));
1329 }
1330
1331 void
1332 proto_reg_handoff_bootp(void)
1333 {
1334   dissector_handle_t bootp_handle;
1335
1336   bootp_handle = create_dissector_handle(dissect_bootp, proto_bootp);
1337   dissector_add("udp.port", UDP_PORT_BOOTPS, bootp_handle);
1338 }