2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * Format and print bootp packets.
26 static const char rcsid[] _U_ =
27 "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.78.2.2 2005/05/06 04:19:39 guy Exp $ (LBL)";
34 #include <tcpdump-stdinc.h>
39 #include "interface.h"
40 #include "addrtoname.h"
45 static void rfc1048_print(const u_char *);
46 static void cmu_print(const u_char *);
48 static char tstr[] = " [|bootp]";
50 static const struct tok bootp_flag_values[] = {
51 { 0x8000, "Broadcast" },
55 static const struct tok bootp_op_values[] = {
56 { BOOTPREQUEST, "Request" },
57 { BOOTPREPLY, "Reply" },
62 * Print bootp requests
65 bootp_print(register const u_char *cp, u_int length)
67 register const struct bootp *bp;
68 static const u_char vm_cmu[4] = VM_CMU;
69 static const u_char vm_rfc1048[4] = VM_RFC1048;
71 bp = (const struct bootp *)cp;
74 printf("BOOTP/DHCP, %s",
75 tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op));
77 if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
78 TCHECK2(bp->bp_chaddr[0], 6);
79 printf(" from %s", etheraddr_string(bp->bp_chaddr));
82 printf(", length: %u", length);
89 /* The usual hardware address type is 1 (10Mb Ethernet) */
90 if (bp->bp_htype != 1)
91 printf(", htype-#%d", bp->bp_htype);
93 /* The usual length for 10Mb Ethernet address is 6 bytes */
94 if (bp->bp_htype != 1 || bp->bp_hlen != 6)
95 printf(", hlen:%d", bp->bp_hlen);
97 /* Only print interesting fields */
99 printf(", hops:%d", bp->bp_hops);
101 printf(", xid:0x%x", EXTRACT_32BITS(&bp->bp_xid));
103 printf(", secs:%d", EXTRACT_16BITS(&bp->bp_secs));
105 printf(", flags: [%s]",
106 bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags)));
108 printf( " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags));
110 /* Client's ip address */
111 TCHECK(bp->bp_ciaddr);
112 if (bp->bp_ciaddr.s_addr)
113 printf("\n\t Client IP: %s", ipaddr_string(&bp->bp_ciaddr));
115 /* 'your' ip address (bootp client) */
116 TCHECK(bp->bp_yiaddr);
117 if (bp->bp_yiaddr.s_addr)
118 printf("\n\t Your IP: %s", ipaddr_string(&bp->bp_yiaddr));
120 /* Server's ip address */
121 TCHECK(bp->bp_siaddr);
122 if (bp->bp_siaddr.s_addr)
123 printf("\n\t Server IP: %s", ipaddr_string(&bp->bp_siaddr));
125 /* Gateway's ip address */
126 TCHECK(bp->bp_giaddr);
127 if (bp->bp_giaddr.s_addr)
128 printf("\n\t Gateway IP: %s", ipaddr_string(&bp->bp_giaddr));
130 /* Client's Ethernet address */
131 if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
132 TCHECK2(bp->bp_chaddr[0], 6);
133 printf("\n\t Client Ethernet Address: %s", etheraddr_string(bp->bp_chaddr));
136 TCHECK2(bp->bp_sname[0], 1); /* check first char only */
138 printf("\n\t sname \"");
139 if (fn_print(bp->bp_sname, snapend)) {
141 fputs(tstr + 1, stdout);
146 TCHECK2(bp->bp_file[0], 1); /* check first char only */
148 printf("\n\t file \"");
149 if (fn_print(bp->bp_file, snapend)) {
151 fputs(tstr + 1, stdout);
157 /* Decode the vendor buffer */
158 TCHECK(bp->bp_vend[0]);
159 if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
160 sizeof(u_int32_t)) == 0)
161 rfc1048_print(bp->bp_vend);
162 else if (memcmp((const char *)bp->bp_vend, vm_cmu,
163 sizeof(u_int32_t)) == 0)
164 cmu_print(bp->bp_vend);
168 ul = EXTRACT_32BITS(&bp->bp_vend);
170 printf("\n\t Vendor-#0x%x", ul);
179 * The first character specifies the format to print:
180 * i - ip address (32 bits)
181 * p - ip address pairs (32 bits + 32 bits)
183 * L - unsigned long (32 bits)
184 * s - short (16 bits)
185 * b - period-seperated decimal bytes (variable length)
186 * x - colon-seperated hex bytes (variable length)
187 * a - ascii string (variable length)
188 * B - on/off (8 bits)
189 * $ - special (explicit code to handle)
191 static struct tok tag2str[] = {
194 { TAG_SUBNET_MASK, "iSM" }, /* subnet mask (RFC950) */
195 { TAG_TIME_OFFSET, "LTZ" }, /* seconds from UTC */
196 { TAG_GATEWAY, "iDG" }, /* default gateway */
197 { TAG_TIME_SERVER, "iTS" }, /* time servers (RFC868) */
198 { TAG_NAME_SERVER, "iIEN" }, /* IEN name servers (IEN116) */
199 { TAG_DOMAIN_SERVER, "iNS" }, /* domain name (RFC1035) */
200 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
201 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
202 { TAG_LPR_SERVER, "iLPR" }, /* lpr server (RFC1179) */
203 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
204 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
205 { TAG_HOSTNAME, "aHN" }, /* ascii hostname */
206 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
209 { TAG_DUMPPATH, "aDP" },
210 { TAG_DOMAINNAME, "aDN" },
211 { TAG_SWAP_SERVER, "iSS" },
212 { TAG_ROOTPATH, "aRP" },
213 { TAG_EXTPATH, "aEP" },
215 { TAG_IP_FORWARD, "BIPF" },
216 { TAG_NL_SRCRT, "BSRT" },
217 { TAG_PFILTERS, "pPF" },
218 { TAG_REASS_SIZE, "sRSZ" },
219 { TAG_DEF_TTL, "bTTL" },
220 { TAG_MTU_TIMEOUT, "lMA" },
221 { TAG_MTU_TABLE, "sMT" },
222 { TAG_INT_MTU, "sMTU" },
223 { TAG_LOCAL_SUBNETS, "BLSN" },
224 { TAG_BROAD_ADDR, "iBR" },
225 { TAG_DO_MASK_DISC, "BMD" },
226 { TAG_SUPPLY_MASK, "BMS" },
227 { TAG_DO_RDISC, "BRD" },
228 { TAG_RTR_SOL_ADDR, "iRSA" },
229 { TAG_STATIC_ROUTE, "pSR" },
230 { TAG_USE_TRAILERS, "BUT" },
231 { TAG_ARP_TIMEOUT, "lAT" },
232 { TAG_ETH_ENCAP, "BIE" },
233 { TAG_TCP_TTL, "bTT" },
234 { TAG_TCP_KEEPALIVE, "lKI" },
235 { TAG_KEEPALIVE_GO, "BKG" },
236 { TAG_NIS_DOMAIN, "aYD" },
237 { TAG_NIS_SERVERS, "iYS" },
238 { TAG_NTP_SERVERS, "iNTP" },
239 { TAG_VENDOR_OPTS, "bVO" },
240 { TAG_NETBIOS_NS, "iWNS" },
241 { TAG_NETBIOS_DDS, "iWDD" },
242 { TAG_NETBIOS_NODE, "$WNT" },
243 { TAG_NETBIOS_SCOPE, "aWSC" },
244 { TAG_XWIN_FS, "iXFS" },
245 { TAG_XWIN_DM, "iXDM" },
246 { TAG_NIS_P_DOMAIN, "sN+D" },
247 { TAG_NIS_P_SERVERS, "iN+S" },
248 { TAG_MOBILE_HOME, "iMH" },
249 { TAG_SMPT_SERVER, "iSMTP" },
250 { TAG_POP3_SERVER, "iPOP3" },
251 { TAG_NNTP_SERVER, "iNNTP" },
252 { TAG_WWW_SERVER, "iWWW" },
253 { TAG_FINGER_SERVER, "iFG" },
254 { TAG_IRC_SERVER, "iIRC" },
255 { TAG_STREETTALK_SRVR, "iSTS" },
256 { TAG_STREETTALK_STDA, "iSTDA" },
257 { TAG_REQUESTED_IP, "iRQ" },
258 { TAG_IP_LEASE, "lLT" },
259 { TAG_OPT_OVERLOAD, "$OO" },
260 { TAG_TFTP_SERVER, "aTFTP" },
261 { TAG_BOOTFILENAME, "aBF" },
262 { TAG_DHCP_MESSAGE, " DHCP" },
263 { TAG_SERVER_ID, "iSID" },
264 { TAG_PARM_REQUEST, "bPR" },
265 { TAG_MESSAGE, "aMSG" },
266 { TAG_MAX_MSG_SIZE, "sMSZ" },
267 { TAG_RENEWAL_TIME, "lRN" },
268 { TAG_REBIND_TIME, "lRB" },
269 { TAG_VENDOR_CLASS, "aVC" },
270 { TAG_CLIENT_ID, "$CID" },
272 { TAG_OPEN_GROUP_UAP, "aUAP" },
274 { TAG_DISABLE_AUTOCONF, "BNOAUTO" },
276 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */
277 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */
279 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */
281 { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
282 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
283 { TAG_USER_CLASS, "aCLASS" },
284 { TAG_SLP_NAMING_AUTH, "aSLP-NA" },
285 { TAG_CLIENT_FQDN, "$FQDN" },
286 { TAG_AGENT_CIRCUIT, "bACKT" },
287 { TAG_AGENT_REMOTE, "bARMT" },
288 { TAG_AGENT_MASK, "bAMSK" },
289 { TAG_TZ_STRING, "aTZSTR" },
290 { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */
291 { TAG_AUTH, "bAUTH" }, /* XXX 'b' */
292 { TAG_VINES_SERVERS, "iVINES" },
293 { TAG_SERVER_RANK, "sRANK" },
294 { TAG_CLIENT_ARCH, "sARCH" },
295 { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */
296 { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */
297 { TAG_LDAP_URL, "aLDAP" },
298 { TAG_6OVER4, "i6o4" },
299 { TAG_PRINTER_NAME, "aPRTR" },
300 { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */
301 { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */
302 { TAG_NETINFO_PARENT, "iNI" },
303 { TAG_NETINFO_PARENT_TAG, "aNITAG" },
305 { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */
308 /* 2-byte extended tags */
309 static struct tok xtag2str[] = {
313 /* DHCP "options overload" types */
314 static struct tok oo2str[] = {
321 /* NETBIOS over TCP/IP node type options */
322 static struct tok nbo2str[] = {
330 /* ARP Hardware types, for Client-ID option */
331 static struct tok arp2str[] = {
337 { 0x18, "ieee1394" },
342 rfc1048_print(register const u_char *bp)
344 register u_int16_t tag;
345 register u_int len, size;
346 register const char *cp;
353 printf("\n\t Vendor-rfc1048:");
355 /* Step over magic cookie */
356 bp += sizeof(int32_t);
358 /* Loop while we there is a tag left in the buffer */
359 while (bp + 1 < snapend) {
365 if (tag == TAG_EXTENDED_OPTION) {
366 TCHECK2(*(bp + 1), 2);
367 tag = EXTRACT_16BITS(bp + 1);
368 /* XXX we don't know yet if the IANA will
369 * preclude overlap of 1-byte and 2-byte spaces.
370 * If not, we need to offset tag after this step.
372 cp = tok2str(xtag2str, "?xT%u", tag);
374 cp = tok2str(tag2str, "?T%u", tag);
376 printf("\n\t %s:", cp);
378 /* Get the length; check for truncation */
379 if (bp + 1 >= snapend) {
384 if (bp + len >= snapend) {
385 printf("[|bootp %u]", len);
389 if (tag == TAG_DHCP_MESSAGE && len == 1) {
392 case DHCPDISCOVER: printf("DISCOVER"); break;
393 case DHCPOFFER: printf("OFFER"); break;
394 case DHCPREQUEST: printf("REQUEST"); break;
395 case DHCPDECLINE: printf("DECLINE"); break;
396 case DHCPACK: printf("ACK"); break;
397 case DHCPNAK: printf("NACK"); break;
398 case DHCPRELEASE: printf("RELEASE"); break;
399 case DHCPINFORM: printf("INFORM"); break;
400 default: printf("%u", uc); break;
405 if (tag == TAG_PARM_REQUEST) {
409 cp = tok2str(tag2str, "?T%u", uc);
412 printf("%s", cp + 1);
417 if (tag == TAG_EXTENDED_REQUEST) {
421 us = EXTRACT_16BITS(bp);
423 cp = tok2str(xtag2str, "?xT%u", us);
426 printf("%s", cp + 1);
435 /* Base default formats for unknown tags on data size */
449 if (fn_printn(bp, size, snapend)) {
461 /* ip addresses/32-bit words */
462 while (size >= sizeof(ul)) {
465 ul = EXTRACT_32BITS(bp);
468 printf("%s", ipaddr_string(&ul));
480 /* IP address pairs */
481 while (size >= 2*sizeof(ul)) {
484 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
485 printf("(%s:", ipaddr_string(&ul));
487 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
488 printf("%s)", ipaddr_string(&ul));
490 size -= 2*sizeof(ul);
497 while (size >= sizeof(us)) {
500 us = EXTRACT_16BITS(bp);
536 putchar(c == 'x' ? ':' : '.');
548 /* Guys we can't handle with one of the usual cases */
551 case TAG_NETBIOS_NODE:
554 fputs(tok2str(nbo2str, NULL, tag), stdout);
557 case TAG_OPT_OVERLOAD:
560 fputs(tok2str(oo2str, NULL, tag), stdout);
563 case TAG_CLIENT_FQDN:
564 /* option 81 should be at least 4 bytes long */
566 printf("ERROR: options 81 len %u < 4 bytes", len);
572 printf("%u/%u/", *bp, *(bp+1));
575 if (fn_printn(bp, size - 3, snapend)) {
589 if (fn_printn(bp, size, snapend)) {
598 printf("[%s]", tok2str(arp2str, "type-%d", type));
612 printf("[unknown special tag %u, size %u]",
620 /* Data left over? */
622 printf("[len %u]", len);
628 printf("|[rfc1048]");
632 cmu_print(register const u_char *bp)
634 register const struct cmu_vend *cmu;
636 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
637 if (cmu->m.s_addr != 0) \
638 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
641 cmu = (const struct cmu_vend *)bp;
643 /* Only print if there are unknown bits */
644 TCHECK(cmu->v_flags);
645 if ((cmu->v_flags & ~(VF_SMASK)) != 0)
646 printf(" F:0x%x", cmu->v_flags);
647 PRINTCMUADDR(v_dgate, "DG");
648 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
649 PRINTCMUADDR(v_dns1, "NS1");
650 PRINTCMUADDR(v_dns2, "NS2");
651 PRINTCMUADDR(v_ins1, "IEN1");
652 PRINTCMUADDR(v_ins2, "IEN2");
653 PRINTCMUADDR(v_ts1, "TS1");
654 PRINTCMUADDR(v_ts2, "TS2");