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.
24 static const char rcsid
[] _U_
=
25 "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.75.2.3 2004/03/02 07:45:13 hannes Exp $ (LBL)";
32 #include <tcpdump-stdinc.h>
37 #include "interface.h"
38 #include "addrtoname.h"
43 static void rfc1048_print(const u_char
*);
44 static void cmu_print(const u_char
*);
46 static char tstr
[] = " [|bootp]";
48 static const struct tok bootp_flag_values
[] = {
49 { 0x8000, "Broadcast" },
53 static const struct tok bootp_op_values
[] = {
54 { BOOTPREQUEST
, "Request" },
55 { BOOTPREPLY
, "Reply" },
60 * Print bootp requests
63 bootp_print(register const u_char
*cp
, u_int length
)
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
;
72 printf("BOOTP/DHCP, %s",
73 tok2str(bootp_op_values
, "unknown (0x%02x)", bp
->bp_op
));
75 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6 && bp
->bp_op
== BOOTPREQUEST
) {
76 TCHECK2(bp
->bp_chaddr
[0], 6);
77 printf(" from %s", etheraddr_string(bp
->bp_chaddr
));
80 printf(", length: %u", length
);
87 /* The usual hardware address type is 1 (10Mb Ethernet) */
88 if (bp
->bp_htype
!= 1)
89 printf(", htype-#%d", bp
->bp_htype
);
91 /* The usual length for 10Mb Ethernet address is 6 bytes */
92 if (bp
->bp_htype
!= 1 || bp
->bp_hlen
!= 6)
93 printf(", hlen:%d", bp
->bp_hlen
);
95 /* Only print interesting fields */
97 printf(", hops:%d", bp
->bp_hops
);
99 printf(", xid:0x%x", EXTRACT_32BITS(&bp
->bp_xid
));
101 printf(", secs:%d", EXTRACT_16BITS(&bp
->bp_secs
));
103 printf(", flags: [%s]",
104 bittok2str(bootp_flag_values
, "none", EXTRACT_16BITS(&bp
->bp_flags
)));
106 printf( " (0x%04x)", EXTRACT_16BITS(&bp
->bp_flags
));
108 /* Client's ip address */
109 TCHECK(bp
->bp_ciaddr
);
110 if (bp
->bp_ciaddr
.s_addr
)
111 printf("\n\t Client IP: %s", ipaddr_string(&bp
->bp_ciaddr
));
113 /* 'your' ip address (bootp client) */
114 TCHECK(bp
->bp_yiaddr
);
115 if (bp
->bp_yiaddr
.s_addr
)
116 printf("\n\t Your IP: %s", ipaddr_string(&bp
->bp_yiaddr
));
118 /* Server's ip address */
119 TCHECK(bp
->bp_siaddr
);
120 if (bp
->bp_siaddr
.s_addr
)
121 printf("\n\t Server IP: %s", ipaddr_string(&bp
->bp_siaddr
));
123 /* Gateway's ip address */
124 TCHECK(bp
->bp_giaddr
);
125 if (bp
->bp_giaddr
.s_addr
)
126 printf("\n\t Gateway IP: %s", ipaddr_string(&bp
->bp_giaddr
));
128 /* Client's Ethernet address */
129 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6) {
130 TCHECK2(bp
->bp_chaddr
[0], 6);
131 printf("\n\t Client Ethernet Address: %s", etheraddr_string(bp
->bp_chaddr
));
134 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
136 printf("\n\t sname \"");
137 if (fn_print(bp
->bp_sname
, snapend
)) {
139 fputs(tstr
+ 1, stdout
);
144 TCHECK2(bp
->bp_file
[0], 1); /* check first char only */
146 printf("\n\t file \"");
147 if (fn_print(bp
->bp_file
, snapend
)) {
149 fputs(tstr
+ 1, stdout
);
155 /* Decode the vendor buffer */
156 TCHECK(bp
->bp_vend
[0]);
157 if (memcmp((const char *)bp
->bp_vend
, vm_rfc1048
,
158 sizeof(u_int32_t
)) == 0)
159 rfc1048_print(bp
->bp_vend
);
160 else if (memcmp((const char *)bp
->bp_vend
, vm_cmu
,
161 sizeof(u_int32_t
)) == 0)
162 cmu_print(bp
->bp_vend
);
166 ul
= EXTRACT_32BITS(&bp
->bp_vend
);
168 printf("\n\t Vendor-#0x%x", ul
);
177 * The first character specifies the format to print:
178 * i - ip address (32 bits)
179 * p - ip address pairs (32 bits + 32 bits)
181 * L - unsigned long (32 bits)
182 * s - short (16 bits)
183 * b - period-seperated decimal bytes (variable length)
184 * x - colon-seperated hex bytes (variable length)
185 * a - ascii string (variable length)
186 * B - on/off (8 bits)
187 * $ - special (explicit code to handle)
189 static struct tok tag2str
[] = {
192 { TAG_SUBNET_MASK
, "iSM" }, /* subnet mask (RFC950) */
193 { TAG_TIME_OFFSET
, "LTZ" }, /* seconds from UTC */
194 { TAG_GATEWAY
, "iDG" }, /* default gateway */
195 { TAG_TIME_SERVER
, "iTS" }, /* time servers (RFC868) */
196 { TAG_NAME_SERVER
, "iIEN" }, /* IEN name servers (IEN116) */
197 { TAG_DOMAIN_SERVER
, "iNS" }, /* domain name (RFC1035) */
198 { TAG_LOG_SERVER
, "iLOG" }, /* MIT log servers */
199 { TAG_COOKIE_SERVER
, "iCS" }, /* cookie servers (RFC865) */
200 { TAG_LPR_SERVER
, "iLPR" }, /* lpr server (RFC1179) */
201 { TAG_IMPRESS_SERVER
, "iIM" }, /* impress servers (Imagen) */
202 { TAG_RLP_SERVER
, "iRL" }, /* resource location (RFC887) */
203 { TAG_HOSTNAME
, "aHN" }, /* ascii hostname */
204 { TAG_BOOTSIZE
, "sBS" }, /* 512 byte blocks */
207 { TAG_DUMPPATH
, "aDP" },
208 { TAG_DOMAINNAME
, "aDN" },
209 { TAG_SWAP_SERVER
, "iSS" },
210 { TAG_ROOTPATH
, "aRP" },
211 { TAG_EXTPATH
, "aEP" },
213 { TAG_IP_FORWARD
, "BIPF" },
214 { TAG_NL_SRCRT
, "BSRT" },
215 { TAG_PFILTERS
, "pPF" },
216 { TAG_REASS_SIZE
, "sRSZ" },
217 { TAG_DEF_TTL
, "bTTL" },
218 { TAG_MTU_TIMEOUT
, "lMA" },
219 { TAG_MTU_TABLE
, "sMT" },
220 { TAG_INT_MTU
, "sMTU" },
221 { TAG_LOCAL_SUBNETS
, "BLSN" },
222 { TAG_BROAD_ADDR
, "iBR" },
223 { TAG_DO_MASK_DISC
, "BMD" },
224 { TAG_SUPPLY_MASK
, "BMS" },
225 { TAG_DO_RDISC
, "BRD" },
226 { TAG_RTR_SOL_ADDR
, "iRSA" },
227 { TAG_STATIC_ROUTE
, "pSR" },
228 { TAG_USE_TRAILERS
, "BUT" },
229 { TAG_ARP_TIMEOUT
, "lAT" },
230 { TAG_ETH_ENCAP
, "BIE" },
231 { TAG_TCP_TTL
, "bTT" },
232 { TAG_TCP_KEEPALIVE
, "lKI" },
233 { TAG_KEEPALIVE_GO
, "BKG" },
234 { TAG_NIS_DOMAIN
, "aYD" },
235 { TAG_NIS_SERVERS
, "iYS" },
236 { TAG_NTP_SERVERS
, "iNTP" },
237 { TAG_VENDOR_OPTS
, "bVO" },
238 { TAG_NETBIOS_NS
, "iWNS" },
239 { TAG_NETBIOS_DDS
, "iWDD" },
240 { TAG_NETBIOS_NODE
, "$WNT" },
241 { TAG_NETBIOS_SCOPE
, "aWSC" },
242 { TAG_XWIN_FS
, "iXFS" },
243 { TAG_XWIN_DM
, "iXDM" },
244 { TAG_NIS_P_DOMAIN
, "sN+D" },
245 { TAG_NIS_P_SERVERS
, "iN+S" },
246 { TAG_MOBILE_HOME
, "iMH" },
247 { TAG_SMPT_SERVER
, "iSMTP" },
248 { TAG_POP3_SERVER
, "iPOP3" },
249 { TAG_NNTP_SERVER
, "iNNTP" },
250 { TAG_WWW_SERVER
, "iWWW" },
251 { TAG_FINGER_SERVER
, "iFG" },
252 { TAG_IRC_SERVER
, "iIRC" },
253 { TAG_STREETTALK_SRVR
, "iSTS" },
254 { TAG_STREETTALK_STDA
, "iSTDA" },
255 { TAG_REQUESTED_IP
, "iRQ" },
256 { TAG_IP_LEASE
, "lLT" },
257 { TAG_OPT_OVERLOAD
, "$OO" },
258 { TAG_TFTP_SERVER
, "aTFTP" },
259 { TAG_BOOTFILENAME
, "aBF" },
260 { TAG_DHCP_MESSAGE
, " DHCP" },
261 { TAG_SERVER_ID
, "iSID" },
262 { TAG_PARM_REQUEST
, "bPR" },
263 { TAG_MESSAGE
, "aMSG" },
264 { TAG_MAX_MSG_SIZE
, "sMSZ" },
265 { TAG_RENEWAL_TIME
, "lRN" },
266 { TAG_REBIND_TIME
, "lRB" },
267 { TAG_VENDOR_CLASS
, "aVC" },
268 { TAG_CLIENT_ID
, "$CID" },
270 { TAG_OPEN_GROUP_UAP
, "aUAP" },
272 { TAG_DISABLE_AUTOCONF
, "BNOAUTO" },
274 { TAG_SLP_DA
, "bSLP-DA" }, /*"b" is a little wrong */
275 { TAG_SLP_SCOPE
, "bSLP-SCOPE" }, /*"b" is a little wrong */
277 { TAG_NS_SEARCH
, "sNSSEARCH" }, /* XXX 's' */
279 { TAG_IP4_SUBNET_SELECT
, "iSUBNET" },
280 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
281 { TAG_USER_CLASS
, "aCLASS" },
282 { TAG_SLP_NAMING_AUTH
, "aSLP-NA" },
283 { TAG_CLIENT_FQDN
, "$FQDN" },
284 { TAG_AGENT_CIRCUIT
, "bACKT" },
285 { TAG_AGENT_REMOTE
, "bARMT" },
286 { TAG_AGENT_MASK
, "bAMSK" },
287 { TAG_TZ_STRING
, "aTZSTR" },
288 { TAG_FQDN_OPTION
, "bFQDNS" }, /* XXX 'b' */
289 { TAG_AUTH
, "bAUTH" }, /* XXX 'b' */
290 { TAG_VINES_SERVERS
, "iVINES" },
291 { TAG_SERVER_RANK
, "sRANK" },
292 { TAG_CLIENT_ARCH
, "sARCH" },
293 { TAG_CLIENT_NDI
, "bNDI" }, /* XXX 'b' */
294 { TAG_CLIENT_GUID
, "bGUID" }, /* XXX 'b' */
295 { TAG_LDAP_URL
, "aLDAP" },
296 { TAG_6OVER4
, "i6o4" },
297 { TAG_PRINTER_NAME
, "aPRTR" },
298 { TAG_MDHCP_SERVER
, "bMDHCP" }, /* XXX 'b' */
299 { TAG_IPX_COMPAT
, "bIPX" }, /* XXX 'b' */
300 { TAG_NETINFO_PARENT
, "iNI" },
301 { TAG_NETINFO_PARENT_TAG
, "aNITAG" },
303 { TAG_FAILOVER
, "bFAIL" }, /* XXX 'b' */
306 /* 2-byte extended tags */
307 static struct tok xtag2str
[] = {
311 /* DHCP "options overload" types */
312 static struct tok oo2str
[] = {
319 /* NETBIOS over TCP/IP node type options */
320 static struct tok nbo2str
[] = {
328 /* ARP Hardware types, for Client-ID option */
329 static struct tok arp2str
[] = {
335 { 0x18, "ieee1394" },
340 rfc1048_print(register const u_char
*bp
)
342 register u_int16_t tag
;
343 register u_int len
, size
;
344 register const char *cp
;
351 printf("\n\t Vendor-rfc1048:");
353 /* Step over magic cookie */
354 bp
+= sizeof(int32_t);
356 /* Loop while we there is a tag left in the buffer */
357 while (bp
+ 1 < snapend
) {
363 if (tag
== TAG_EXTENDED_OPTION
) {
364 TCHECK2(*(bp
+ 1), 2);
365 tag
= EXTRACT_16BITS(bp
+ 1);
366 /* XXX we don't know yet if the IANA will
367 * preclude overlap of 1-byte and 2-byte spaces.
368 * If not, we need to offset tag after this step.
370 cp
= tok2str(xtag2str
, "?xT%u", tag
);
372 cp
= tok2str(tag2str
, "?T%u", tag
);
374 printf("\n\t %s:", cp
);
376 /* Get the length; check for truncation */
377 if (bp
+ 1 >= snapend
) {
382 if (bp
+ len
>= snapend
) {
383 printf("[|bootp %u]", len
);
387 if (tag
== TAG_DHCP_MESSAGE
&& len
== 1) {
390 case DHCPDISCOVER
: printf("DISCOVER"); break;
391 case DHCPOFFER
: printf("OFFER"); break;
392 case DHCPREQUEST
: printf("REQUEST"); break;
393 case DHCPDECLINE
: printf("DECLINE"); break;
394 case DHCPACK
: printf("ACK"); break;
395 case DHCPNAK
: printf("NACK"); break;
396 case DHCPRELEASE
: printf("RELEASE"); break;
397 case DHCPINFORM
: printf("INFORM"); break;
398 default: printf("%u", uc
); break;
403 if (tag
== TAG_PARM_REQUEST
) {
407 cp
= tok2str(tag2str
, "?T%u", uc
);
410 printf("%s", cp
+ 1);
415 if (tag
== TAG_EXTENDED_REQUEST
) {
419 us
= EXTRACT_16BITS(bp
);
421 cp
= tok2str(xtag2str
, "?xT%u", us
);
424 printf("%s", cp
+ 1);
433 /* Base default formats for unknown tags on data size */
447 (void)fn_printn(bp
, size
, NULL
);
456 /* ip addresses/32-bit words */
457 while (size
>= sizeof(ul
)) {
460 ul
= EXTRACT_32BITS(bp
);
463 printf("%s", ipaddr_string(&ul
));
475 /* IP address pairs */
476 while (size
>= 2*sizeof(ul
)) {
479 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
480 printf("(%s:", ipaddr_string(&ul
));
482 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
483 printf("%s)", ipaddr_string(&ul
));
485 size
-= 2*sizeof(ul
);
492 while (size
>= sizeof(us
)) {
495 us
= EXTRACT_16BITS(bp
);
531 putchar(c
== 'x' ? ':' : '.');
543 /* Guys we can't handle with one of the usual cases */
546 case TAG_NETBIOS_NODE
:
549 fputs(tok2str(nbo2str
, NULL
, tag
), stdout
);
552 case TAG_OPT_OVERLOAD
:
555 fputs(tok2str(oo2str
, NULL
, tag
), stdout
);
558 case TAG_CLIENT_FQDN
:
559 /* option 81 should be at least 4 bytes long */
561 printf("ERROR: options 81 len %u < 4 bytes", len
);
566 printf("%u/%u/", *bp
, *(bp
+1));
569 (void)fn_printn(bp
, size
- 3, NULL
);
580 (void)fn_printn(bp
, size
, NULL
);
586 printf("[%s]", tok2str(arp2str
, "type-%d", type
));
600 printf("[unknown special tag %u, size %u]",
608 /* Data left over? */
610 printf("[len %u]", len
);
616 printf("|[rfc1048]");
620 cmu_print(register const u_char
*bp
)
622 register const struct cmu_vend
*cmu
;
624 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
625 if (cmu->m.s_addr != 0) \
626 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
629 cmu
= (const struct cmu_vend
*)bp
;
631 /* Only print if there are unknown bits */
632 TCHECK(cmu
->v_flags
);
633 if ((cmu
->v_flags
& ~(VF_SMASK
)) != 0)
634 printf(" F:0x%x", cmu
->v_flags
);
635 PRINTCMUADDR(v_dgate
, "DG");
636 PRINTCMUADDR(v_smask
, cmu
->v_flags
& VF_SMASK
? "SM" : "SM*");
637 PRINTCMUADDR(v_dns1
, "NS1");
638 PRINTCMUADDR(v_dns2
, "NS2");
639 PRINTCMUADDR(v_ins1
, "IEN1");
640 PRINTCMUADDR(v_ins2
, "IEN2");
641 PRINTCMUADDR(v_ts1
, "TS1");
642 PRINTCMUADDR(v_ts2
, "TS2");