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[] =
27 "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.60 2001/09/17 21:57:56 fenner Exp $ (LBL)";
34 #include <sys/param.h>
36 #include <sys/socket.h>
41 #include <netinet/in.h>
47 #include "interface.h"
48 #include "addrtoname.h"
53 static void rfc1048_print(const u_char *);
54 static void cmu_print(const u_char *);
56 static char tstr[] = " [|bootp]";
59 * Print bootp requests
62 bootp_print(register const u_char *cp, u_int length,
63 u_short sport, u_short dport)
65 register const struct bootp *bp;
66 static const u_char vm_cmu[4] = VM_CMU;
67 static const u_char vm_rfc1048[4] = VM_RFC1048;
69 bp = (const struct bootp *)cp;
74 /* Usually, a request goes from a client to a server */
75 if (sport != IPPORT_BOOTPC || dport != IPPORT_BOOTPS)
80 /* Usually, a reply goes from a server to a client */
81 if (sport != IPPORT_BOOTPS || dport != IPPORT_BOOTPC)
86 printf(" bootp-#%d", bp->bp_op);
91 /* The usual hardware address type is 1 (10Mb Ethernet) */
92 if (bp->bp_htype != 1)
93 printf(" htype-#%d", bp->bp_htype);
95 /* The usual length for 10Mb Ethernet address is 6 bytes */
96 if (bp->bp_htype != 1 || bp->bp_hlen != 6)
97 printf(" hlen:%d", bp->bp_hlen);
99 /* Only print interesting fields */
101 printf(" hops:%d", bp->bp_hops);
103 printf(" xid:0x%x", (u_int32_t)ntohl(bp->bp_xid));
105 printf(" secs:%d", ntohs(bp->bp_secs));
107 printf(" flags:0x%x", ntohs(bp->bp_flags));
109 /* Client's ip address */
110 TCHECK(bp->bp_ciaddr);
111 if (bp->bp_ciaddr.s_addr)
112 printf(" C:%s", ipaddr_string(&bp->bp_ciaddr));
114 /* 'your' ip address (bootp client) */
115 TCHECK(bp->bp_yiaddr);
116 if (bp->bp_yiaddr.s_addr)
117 printf(" Y:%s", ipaddr_string(&bp->bp_yiaddr));
119 /* Server's ip address */
120 TCHECK(bp->bp_siaddr);
121 if (bp->bp_siaddr.s_addr)
122 printf(" S:%s", ipaddr_string(&bp->bp_siaddr));
124 /* Gateway's ip address */
125 TCHECK(bp->bp_giaddr);
126 if (bp->bp_giaddr.s_addr)
127 printf(" G:%s", ipaddr_string(&bp->bp_giaddr));
129 /* Client's Ethernet address */
130 if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
131 register const struct ether_header *eh;
132 register const char *e;
134 TCHECK2(bp->bp_chaddr[0], 6);
135 eh = (const struct ether_header *)packetp;
136 if (bp->bp_op == BOOTREQUEST)
137 e = (const char *)ESRC(eh);
138 else if (bp->bp_op == BOOTREPLY)
139 e = (const char *)EDST(eh);
142 if (e == 0 || memcmp((const char *)bp->bp_chaddr, e, 6) != 0)
143 printf(" ether %s", etheraddr_string(bp->bp_chaddr));
146 TCHECK2(bp->bp_sname[0], 1); /* check first char only */
149 if (fn_print(bp->bp_sname, snapend)) {
151 fputs(tstr + 1, stdout);
156 TCHECK2(bp->bp_sname[0], 1); /* check first char only */
159 if (fn_print(bp->bp_file, snapend)) {
161 fputs(tstr + 1, stdout);
167 /* Decode the vendor buffer */
168 TCHECK(bp->bp_vend[0]);
169 if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
170 sizeof(u_int32_t)) == 0)
171 rfc1048_print(bp->bp_vend);
172 else if (memcmp((const char *)bp->bp_vend, vm_cmu,
173 sizeof(u_int32_t)) == 0)
174 cmu_print(bp->bp_vend);
178 ul = EXTRACT_32BITS(&bp->bp_vend);
180 printf("vend-#0x%x", ul);
189 * The first character specifies the format to print:
190 * i - ip address (32 bits)
191 * p - ip address pairs (32 bits + 32 bits)
193 * L - unsigned long (32 bits)
194 * s - short (16 bits)
195 * b - period-seperated decimal bytes (variable length)
196 * x - colon-seperated hex bytes (variable length)
197 * a - ascii string (variable length)
198 * B - on/off (8 bits)
199 * $ - special (explicit code to handle)
201 static struct tok tag2str[] = {
204 { TAG_SUBNET_MASK, "iSM" }, /* subnet mask (RFC950) */
205 { TAG_TIME_OFFSET, "LTZ" }, /* seconds from UTC */
206 { TAG_GATEWAY, "iDG" }, /* default gateway */
207 { TAG_TIME_SERVER, "iTS" }, /* time servers (RFC868) */
208 { TAG_NAME_SERVER, "iIEN" }, /* IEN name servers (IEN116) */
209 { TAG_DOMAIN_SERVER, "iNS" }, /* domain name (RFC1035) */
210 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
211 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
212 { TAG_LPR_SERVER, "iLPR" }, /* lpr server (RFC1179) */
213 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
214 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
215 { TAG_HOSTNAME, "aHN" }, /* ascii hostname */
216 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
219 { TAG_DUMPPATH, "aDP" },
220 { TAG_DOMAINNAME, "aDN" },
221 { TAG_SWAP_SERVER, "iSS" },
222 { TAG_ROOTPATH, "aRP" },
223 { TAG_EXTPATH, "aEP" },
225 { TAG_IP_FORWARD, "BIPF" },
226 { TAG_NL_SRCRT, "BSRT" },
227 { TAG_PFILTERS, "pPF" },
228 { TAG_REASS_SIZE, "sRSZ" },
229 { TAG_DEF_TTL, "bTTL" },
230 { TAG_MTU_TIMEOUT, "lMA" },
231 { TAG_MTU_TABLE, "sMT" },
232 { TAG_INT_MTU, "sMTU" },
233 { TAG_LOCAL_SUBNETS, "BLSN" },
234 { TAG_BROAD_ADDR, "iBR" },
235 { TAG_DO_MASK_DISC, "BMD" },
236 { TAG_SUPPLY_MASK, "BMS" },
237 { TAG_DO_RDISC, "BRD" },
238 { TAG_RTR_SOL_ADDR, "iRSA" },
239 { TAG_STATIC_ROUTE, "pSR" },
240 { TAG_USE_TRAILERS, "BUT" },
241 { TAG_ARP_TIMEOUT, "lAT" },
242 { TAG_ETH_ENCAP, "BIE" },
243 { TAG_TCP_TTL, "bTT" },
244 { TAG_TCP_KEEPALIVE, "lKI" },
245 { TAG_KEEPALIVE_GO, "BKG" },
246 { TAG_NIS_DOMAIN, "aYD" },
247 { TAG_NIS_SERVERS, "iYS" },
248 { TAG_NTP_SERVERS, "iNTP" },
249 { TAG_VENDOR_OPTS, "bVO" },
250 { TAG_NETBIOS_NS, "iWNS" },
251 { TAG_NETBIOS_DDS, "iWDD" },
252 { TAG_NETBIOS_NODE, "$WNT" },
253 { TAG_NETBIOS_SCOPE, "aWSC" },
254 { TAG_XWIN_FS, "iXFS" },
255 { TAG_XWIN_DM, "iXDM" },
256 { TAG_NIS_P_DOMAIN, "sN+D" },
257 { TAG_NIS_P_SERVERS, "iN+S" },
258 { TAG_MOBILE_HOME, "iMH" },
259 { TAG_SMPT_SERVER, "iSMTP" },
260 { TAG_POP3_SERVER, "iPOP3" },
261 { TAG_NNTP_SERVER, "iNNTP" },
262 { TAG_WWW_SERVER, "iWWW" },
263 { TAG_FINGER_SERVER, "iFG" },
264 { TAG_IRC_SERVER, "iIRC" },
265 { TAG_STREETTALK_SRVR, "iSTS" },
266 { TAG_STREETTALK_STDA, "iSTDA" },
267 { TAG_REQUESTED_IP, "iRQ" },
268 { TAG_IP_LEASE, "lLT" },
269 { TAG_OPT_OVERLOAD, "$OO" },
270 { TAG_TFTP_SERVER, "aTFTP" },
271 { TAG_BOOTFILENAME, "aBF" },
272 { TAG_DHCP_MESSAGE, " DHCP" },
273 { TAG_SERVER_ID, "iSID" },
274 { TAG_PARM_REQUEST, "bPR" },
275 { TAG_MESSAGE, "aMSG" },
276 { TAG_MAX_MSG_SIZE, "sMSZ" },
277 { TAG_RENEWAL_TIME, "lRN" },
278 { TAG_REBIND_TIME, "lRB" },
279 { TAG_VENDOR_CLASS, "aVC" },
280 { TAG_CLIENT_ID, "$CID" },
282 { TAG_OPEN_GROUP_UAP, "aUAP" },
284 { TAG_DISABLE_AUTOCONF, "BNOAUTO" },
286 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */
287 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */
289 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */
291 { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
292 /* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */
293 { TAG_USER_CLASS, "aCLASS" },
294 { TAG_SLP_NAMING_AUTH, "aSLP-NA" },
295 { TAG_CLIENT_FQDN, "$FQDN" },
296 { TAG_AGENT_CIRCUIT, "bACKT" },
297 { TAG_AGENT_REMOTE, "bARMT" },
298 { TAG_AGENT_MASK, "bAMSK" },
299 { TAG_TZ_STRING, "aTZSTR" },
300 { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */
301 { TAG_AUTH, "bAUTH" }, /* XXX 'b' */
302 { TAG_VINES_SERVERS, "iVINES" },
303 { TAG_SERVER_RANK, "sRANK" },
304 { TAG_CLIENT_ARCH, "sARCH" },
305 { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */
306 { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */
307 { TAG_LDAP_URL, "aLDAP" },
308 { TAG_6OVER4, "i6o4" },
309 { TAG_PRINTER_NAME, "aPRTR" },
310 { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */
311 { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */
312 { TAG_NETINFO_PARENT, "iNI" },
313 { TAG_NETINFO_PARENT_TAG, "aNITAG" },
315 { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */
318 /* 2-byte extended tags */
319 static struct tok xtag2str[] = {
323 /* DHCP "options overload" types */
324 static struct tok oo2str[] = {
331 /* NETBIOS over TCP/IP node type options */
332 static struct tok nbo2str[] = {
340 /* ARP Hardware types, for Client-ID option */
341 static struct tok arp2str[] = {
347 { 0x18, "ieee1394" },
352 rfc1048_print(register const u_char *bp)
355 register u_int len, size;
356 register const char *cp;
362 printf(" vend-rfc1048");
364 /* Step over magic cookie */
365 bp += sizeof(int32_t);
367 /* Loop while we there is a tag left in the buffer */
368 while (bp + 1 < snapend) {
374 if (tag == TAG_EXTENDED_OPTION) {
375 TCHECK2(*(bp + 1), 2);
376 tag = EXTRACT_16BITS(bp + 1);
377 /* XXX we don't know yet if the IANA will
378 * preclude overlap of 1-byte and 2-byte spaces.
379 * If not, we need to offset tag after this step.
381 cp = tok2str(xtag2str, "?xT%d", tag);
383 cp = tok2str(tag2str, "?T%d", tag);
387 /* Get the length; check for truncation */
388 if (bp + 1 >= snapend) {
393 if (bp + len >= snapend) {
398 if (tag == TAG_DHCP_MESSAGE && len == 1) {
401 case DHCPDISCOVER: printf("DISCOVER"); break;
402 case DHCPOFFER: printf("OFFER"); break;
403 case DHCPREQUEST: printf("REQUEST"); break;
404 case DHCPDECLINE: printf("DECLINE"); break;
405 case DHCPACK: printf("ACK"); break;
406 case DHCPNAK: printf("NACK"); break;
407 case DHCPRELEASE: printf("RELEASE"); break;
408 case DHCPINFORM: printf("INFORM"); break;
409 default: printf("%u", c); break;
414 if (tag == TAG_PARM_REQUEST) {
418 cp = tok2str(tag2str, "?T%d", c);
421 printf("%s", cp + 1);
426 if (tag == TAG_EXTENDED_REQUEST) {
430 c = EXTRACT_16BITS(bp);
432 cp = tok2str(xtag2str, "?xT%d", c);
435 printf("%s", cp + 1);
444 /* Base default formats for unknown tags on data size */
458 (void)fn_printn(bp, size, NULL);
467 /* ip addresses/32-bit words */
468 while (size >= sizeof(ul)) {
471 ul = EXTRACT_32BITS(bp);
474 printf("%s", ipaddr_string(&ul));
486 /* IP address pairs */
487 while (size >= 2*sizeof(ul)) {
490 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
491 printf("(%s:", ipaddr_string(&ul));
493 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
494 printf("%s)", ipaddr_string(&ul));
496 size -= 2*sizeof(ul);
503 while (size >= sizeof(us)) {
506 us = EXTRACT_16BITS(bp);
542 putchar(c == 'x' ? ':' : '.');
554 /* Guys we can't handle with one of the usual cases */
557 case TAG_NETBIOS_NODE:
560 fputs(tok2str(nbo2str, NULL, tag), stdout);
563 case TAG_OPT_OVERLOAD:
566 fputs(tok2str(oo2str, NULL, tag), stdout);
569 case TAG_CLIENT_FQDN:
573 printf("%d/%d/", *bp, *(bp+1));
576 (void)fn_printn(bp, size - 3, NULL);
587 (void)fn_printn(bp, size, NULL);
591 printf("[%s]", tok2str(arp2str, "type-%d", type));
605 printf("[unknown special tag %d, size %d]",
613 /* Data left over? */
615 printf("[len %d]", len);
619 printf("|[rfc1048]");
623 cmu_print(register const u_char *bp)
625 register const struct cmu_vend *cmu;
627 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
628 if (cmu->m.s_addr != 0) \
629 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
632 cmu = (const struct cmu_vend *)bp;
634 /* Only print if there are unknown bits */
635 TCHECK(cmu->v_flags);
636 if ((cmu->v_flags & ~(VF_SMASK)) != 0)
637 printf(" F:0x%x", cmu->v_flags);
638 PRINTCMUADDR(v_dgate, "DG");
639 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
640 PRINTCMUADDR(v_dns1, "NS1");
641 PRINTCMUADDR(v_dns2, "NS2");
642 PRINTCMUADDR(v_ins1, "IEN1");
643 PRINTCMUADDR(v_ins2, "IEN2");
644 PRINTCMUADDR(v_ts1, "TS1");
645 PRINTCMUADDR(v_ts2, "TS2");