4 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * Format and print bootp packets.
25 #include <sys/cdefs.h>
28 static const char rcsid
[] _U_
=
29 "@(#) Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.78.2.7 2007/01/29 20:56:00 guy Exp (LBL)";
31 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
39 #include <tcpdump-stdinc.h>
44 #include "interface.h"
45 #include "addrtoname.h"
50 static void rfc1048_print(const u_char
*);
51 static void cmu_print(const u_char
*);
52 static char *client_fqdn_flags(u_int flags
);
54 static char tstr
[] = " [|bootp]";
56 static const struct tok bootp_flag_values
[] = {
57 { 0x8000, "Broadcast" },
61 static const struct tok bootp_op_values
[] = {
62 { BOOTPREQUEST
, "Request" },
63 { BOOTPREPLY
, "Reply" },
68 * Print bootp requests
71 bootp_print(register const u_char
*cp
, u_int length
)
73 register const struct bootp
*bp
;
74 static const u_char vm_cmu
[4] = VM_CMU
;
75 static const u_char vm_rfc1048
[4] = VM_RFC1048
;
77 bp
= (const struct bootp
*)cp
;
80 printf("BOOTP/DHCP, %s",
81 tok2str(bootp_op_values
, "unknown (0x%02x)", bp
->bp_op
));
83 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6 && bp
->bp_op
== BOOTPREQUEST
) {
84 TCHECK2(bp
->bp_chaddr
[0], 6);
85 printf(" from %s", etheraddr_string(bp
->bp_chaddr
));
88 printf(", length %u", length
);
95 /* The usual hardware address type is 1 (10Mb Ethernet) */
96 if (bp
->bp_htype
!= 1)
97 printf(", htype %d", bp
->bp_htype
);
99 /* The usual length for 10Mb Ethernet address is 6 bytes */
100 if (bp
->bp_htype
!= 1 || bp
->bp_hlen
!= 6)
101 printf(", hlen %d", bp
->bp_hlen
);
103 /* Only print interesting fields */
105 printf(", hops %d", bp
->bp_hops
);
107 printf(", xid 0x%x", EXTRACT_32BITS(&bp
->bp_xid
));
109 printf(", secs %d", EXTRACT_16BITS(&bp
->bp_secs
));
111 printf(", Flags [%s]",
112 bittok2str(bootp_flag_values
, "none", EXTRACT_16BITS(&bp
->bp_flags
)));
114 printf(" (0x%04x)", EXTRACT_16BITS(&bp
->bp_flags
));
116 /* Client's ip address */
117 TCHECK(bp
->bp_ciaddr
);
118 if (bp
->bp_ciaddr
.s_addr
)
119 printf("\n\t Client-IP %s", ipaddr_string(&bp
->bp_ciaddr
));
121 /* 'your' ip address (bootp client) */
122 TCHECK(bp
->bp_yiaddr
);
123 if (bp
->bp_yiaddr
.s_addr
)
124 printf("\n\t Your-IP %s", ipaddr_string(&bp
->bp_yiaddr
));
126 /* Server's ip address */
127 TCHECK(bp
->bp_siaddr
);
128 if (bp
->bp_siaddr
.s_addr
)
129 printf("\n\t Server-IP %s", ipaddr_string(&bp
->bp_siaddr
));
131 /* Gateway's ip address */
132 TCHECK(bp
->bp_giaddr
);
133 if (bp
->bp_giaddr
.s_addr
)
134 printf("\n\t Gateway-IP %s", ipaddr_string(&bp
->bp_giaddr
));
136 /* Client's Ethernet address */
137 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6) {
138 TCHECK2(bp
->bp_chaddr
[0], 6);
139 printf("\n\t Client-Ethernet-Address %s", etheraddr_string(bp
->bp_chaddr
));
142 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
144 printf("\n\t sname \"");
145 if (fn_print(bp
->bp_sname
, snapend
)) {
147 fputs(tstr
+ 1, stdout
);
152 TCHECK2(bp
->bp_file
[0], 1); /* check first char only */
154 printf("\n\t file \"");
155 if (fn_print(bp
->bp_file
, snapend
)) {
157 fputs(tstr
+ 1, stdout
);
163 /* Decode the vendor buffer */
164 TCHECK(bp
->bp_vend
[0]);
165 if (memcmp((const char *)bp
->bp_vend
, vm_rfc1048
,
166 sizeof(u_int32_t
)) == 0)
167 rfc1048_print(bp
->bp_vend
);
168 else if (memcmp((const char *)bp
->bp_vend
, vm_cmu
,
169 sizeof(u_int32_t
)) == 0)
170 cmu_print(bp
->bp_vend
);
174 ul
= EXTRACT_32BITS(&bp
->bp_vend
);
176 printf("\n\t Vendor-#0x%x", ul
);
185 * The first character specifies the format to print:
186 * i - ip address (32 bits)
187 * p - ip address pairs (32 bits + 32 bits)
189 * L - unsigned long (32 bits)
190 * s - short (16 bits)
191 * b - period-seperated decimal bytes (variable length)
192 * x - colon-seperated hex bytes (variable length)
193 * a - ascii string (variable length)
194 * B - on/off (8 bits)
195 * $ - special (explicit code to handle)
197 static struct tok tag2str
[] = {
200 { TAG_SUBNET_MASK
, "iSubnet-Mask" }, /* subnet mask (RFC950) */
201 { TAG_TIME_OFFSET
, "LTime-Zone" }, /* seconds from UTC */
202 { TAG_GATEWAY
, "iDefault-Gateway" }, /* default gateway */
203 { TAG_TIME_SERVER
, "iTime-Server" }, /* time servers (RFC868) */
204 { TAG_NAME_SERVER
, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
205 { TAG_DOMAIN_SERVER
, "iDomain-Name-Server" }, /* domain name (RFC1035) */
206 { TAG_LOG_SERVER
, "iLOG" }, /* MIT log servers */
207 { TAG_COOKIE_SERVER
, "iCS" }, /* cookie servers (RFC865) */
208 { TAG_LPR_SERVER
, "iLPR-Server" }, /* lpr server (RFC1179) */
209 { TAG_IMPRESS_SERVER
, "iIM" }, /* impress servers (Imagen) */
210 { TAG_RLP_SERVER
, "iRL" }, /* resource location (RFC887) */
211 { TAG_HOSTNAME
, "aHostname" }, /* ascii hostname */
212 { TAG_BOOTSIZE
, "sBS" }, /* 512 byte blocks */
215 { TAG_DUMPPATH
, "aDP" },
216 { TAG_DOMAINNAME
, "aDomain-Name" },
217 { TAG_SWAP_SERVER
, "iSS" },
218 { TAG_ROOTPATH
, "aRP" },
219 { TAG_EXTPATH
, "aEP" },
221 { TAG_IP_FORWARD
, "BIPF" },
222 { TAG_NL_SRCRT
, "BSRT" },
223 { TAG_PFILTERS
, "pPF" },
224 { TAG_REASS_SIZE
, "sRSZ" },
225 { TAG_DEF_TTL
, "bTTL" },
226 { TAG_MTU_TIMEOUT
, "lMTU-Timeout" },
227 { TAG_MTU_TABLE
, "sMTU-Table" },
228 { TAG_INT_MTU
, "sMTU" },
229 { TAG_LOCAL_SUBNETS
, "BLSN" },
230 { TAG_BROAD_ADDR
, "iBR" },
231 { TAG_DO_MASK_DISC
, "BMD" },
232 { TAG_SUPPLY_MASK
, "BMS" },
233 { TAG_DO_RDISC
, "BRouter-Discovery" },
234 { TAG_RTR_SOL_ADDR
, "iRSA" },
235 { TAG_STATIC_ROUTE
, "pStatic-Route" },
236 { TAG_USE_TRAILERS
, "BUT" },
237 { TAG_ARP_TIMEOUT
, "lAT" },
238 { TAG_ETH_ENCAP
, "BIE" },
239 { TAG_TCP_TTL
, "bTT" },
240 { TAG_TCP_KEEPALIVE
, "lKI" },
241 { TAG_KEEPALIVE_GO
, "BKG" },
242 { TAG_NIS_DOMAIN
, "aYD" },
243 { TAG_NIS_SERVERS
, "iYS" },
244 { TAG_NTP_SERVERS
, "iNTP" },
245 { TAG_VENDOR_OPTS
, "bVendor-Option" },
246 { TAG_NETBIOS_NS
, "iNetbios-Name-Server" },
247 { TAG_NETBIOS_DDS
, "iWDD" },
248 { TAG_NETBIOS_NODE
, "$Netbios-Node" },
249 { TAG_NETBIOS_SCOPE
, "aNetbios-Scope" },
250 { TAG_XWIN_FS
, "iXFS" },
251 { TAG_XWIN_DM
, "iXDM" },
252 { TAG_NIS_P_DOMAIN
, "sN+D" },
253 { TAG_NIS_P_SERVERS
, "iN+S" },
254 { TAG_MOBILE_HOME
, "iMH" },
255 { TAG_SMPT_SERVER
, "iSMTP" },
256 { TAG_POP3_SERVER
, "iPOP3" },
257 { TAG_NNTP_SERVER
, "iNNTP" },
258 { TAG_WWW_SERVER
, "iWWW" },
259 { TAG_FINGER_SERVER
, "iFG" },
260 { TAG_IRC_SERVER
, "iIRC" },
261 { TAG_STREETTALK_SRVR
, "iSTS" },
262 { TAG_STREETTALK_STDA
, "iSTDA" },
263 { TAG_REQUESTED_IP
, "iRequested-IP" },
264 { TAG_IP_LEASE
, "lLease-Time" },
265 { TAG_OPT_OVERLOAD
, "$OO" },
266 { TAG_TFTP_SERVER
, "aTFTP" },
267 { TAG_BOOTFILENAME
, "aBF" },
268 { TAG_DHCP_MESSAGE
, " DHCP-Message" },
269 { TAG_SERVER_ID
, "iServer-ID" },
270 { TAG_PARM_REQUEST
, "bParameter-Request" },
271 { TAG_MESSAGE
, "aMSG" },
272 { TAG_MAX_MSG_SIZE
, "sMSZ" },
273 { TAG_RENEWAL_TIME
, "lRN" },
274 { TAG_REBIND_TIME
, "lRB" },
275 { TAG_VENDOR_CLASS
, "aVendor-Class" },
276 { TAG_CLIENT_ID
, "$Client-ID" },
278 { TAG_OPEN_GROUP_UAP
, "aUAP" },
280 { TAG_DISABLE_AUTOCONF
, "BNOAUTO" },
282 { TAG_SLP_DA
, "bSLP-DA" }, /*"b" is a little wrong */
283 { TAG_SLP_SCOPE
, "bSLP-SCOPE" }, /*"b" is a little wrong */
285 { TAG_NS_SEARCH
, "sNSSEARCH" }, /* XXX 's' */
287 { TAG_IP4_SUBNET_SELECT
, "iSUBNET" },
288 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
289 { TAG_USER_CLASS
, "aCLASS" },
290 { TAG_SLP_NAMING_AUTH
, "aSLP-NA" },
291 { TAG_CLIENT_FQDN
, "$FQDN" },
292 { TAG_AGENT_CIRCUIT
, "$Agent-Information" },
293 { TAG_AGENT_REMOTE
, "bARMT" },
294 { TAG_AGENT_MASK
, "bAMSK" },
295 { TAG_TZ_STRING
, "aTZSTR" },
296 { TAG_FQDN_OPTION
, "bFQDNS" }, /* XXX 'b' */
297 { TAG_AUTH
, "bAUTH" }, /* XXX 'b' */
298 { TAG_VINES_SERVERS
, "iVINES" },
299 { TAG_SERVER_RANK
, "sRANK" },
300 { TAG_CLIENT_ARCH
, "sARCH" },
301 { TAG_CLIENT_NDI
, "bNDI" }, /* XXX 'b' */
302 { TAG_CLIENT_GUID
, "bGUID" }, /* XXX 'b' */
303 { TAG_LDAP_URL
, "aLDAP" },
304 { TAG_6OVER4
, "i6o4" },
305 { TAG_PRINTER_NAME
, "aPRTR" },
306 { TAG_MDHCP_SERVER
, "bMDHCP" }, /* XXX 'b' */
307 { TAG_IPX_COMPAT
, "bIPX" }, /* XXX 'b' */
308 { TAG_NETINFO_PARENT
, "iNI" },
309 { TAG_NETINFO_PARENT_TAG
, "aNITAG" },
311 { TAG_FAILOVER
, "bFAIL" }, /* XXX 'b' */
314 /* 2-byte extended tags */
315 static struct tok xtag2str
[] = {
319 /* DHCP "options overload" types */
320 static struct tok oo2str
[] = {
327 /* NETBIOS over TCP/IP node type options */
328 static struct tok nbo2str
[] = {
336 /* ARP Hardware types, for Client-ID option */
337 static struct tok arp2str
[] = {
343 { 0x18, "ieee1394" },
347 static struct tok dhcp_msg_values
[] = {
348 { DHCPDISCOVER
, "Discover" },
349 { DHCPOFFER
, "Offer" },
350 { DHCPREQUEST
, "Request" },
351 { DHCPDECLINE
, "Decline" },
354 { DHCPRELEASE
, "Release" },
355 { DHCPINFORM
, "Inform" },
359 #define AGENT_SUBOPTION_CIRCUIT_ID 1
360 static struct tok agent_suboption_values
[] = {
361 { AGENT_SUBOPTION_CIRCUIT_ID
, "Circuit-ID" },
367 rfc1048_print(register const u_char
*bp
)
369 register u_int16_t tag
;
370 register u_int len
, size
;
371 register const char *cp
;
376 u_int8_t uc
, subopt
, suboptlen
;
378 printf("\n\t Vendor-rfc1048 Extensions");
380 /* Step over magic cookie */
381 printf("\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp
));
382 bp
+= sizeof(int32_t);
384 /* Loop while we there is a tag left in the buffer */
385 while (TTEST2(*bp
, 1)) {
387 if (tag
== TAG_PAD
&& vflag
< 3)
389 if (tag
== TAG_END
&& vflag
< 3)
391 if (tag
== TAG_EXTENDED_OPTION
) {
392 TCHECK2(*(bp
+ 1), 2);
393 tag
= EXTRACT_16BITS(bp
+ 1);
394 /* XXX we don't know yet if the IANA will
395 * preclude overlap of 1-byte and 2-byte spaces.
396 * If not, we need to offset tag after this step.
398 cp
= tok2str(xtag2str
, "?xT%u", tag
);
400 cp
= tok2str(tag2str
, "?T%u", tag
);
403 if (tag
== TAG_PAD
|| tag
== TAG_END
)
406 /* Get the length; check for truncation */
411 printf("\n\t %s Option %u, length %u%s", cp
, tag
, len
,
412 len
> 0 ? ": " : "");
414 if (tag
== TAG_PAD
&& vflag
> 2) {
416 while (TTEST2(*bp
, 1) && *bp
== TAG_PAD
) {
421 printf(", occurs %u", ntag
);
424 if (!TTEST2(*bp
, len
)) {
425 printf("[|rfc1048 %u]", len
);
429 if (tag
== TAG_DHCP_MESSAGE
&& len
== 1) {
431 printf("%s", tok2str(dhcp_msg_values
, "Unknown (%u)", uc
));
435 if (tag
== TAG_PARM_REQUEST
) {
439 cp
= tok2str(tag2str
, "?Option %u", uc
);
444 printf("%s", cp
+ 1);
450 if (tag
== TAG_EXTENDED_REQUEST
) {
454 us
= EXTRACT_16BITS(bp
);
456 cp
= tok2str(xtag2str
, "?xT%u", us
);
459 printf("%s", cp
+ 1);
468 /* Base default formats for unknown tags on data size */
482 if (fn_printn(bp
, size
, snapend
)) {
494 /* ip addresses/32-bit words */
495 while (size
>= sizeof(ul
)) {
498 ul
= EXTRACT_32BITS(bp
);
501 printf("%s", ipaddr_string(&ul
));
513 /* IP address pairs */
514 while (size
>= 2*sizeof(ul
)) {
517 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
518 printf("(%s:", ipaddr_string(&ul
));
520 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
521 printf("%s)", ipaddr_string(&ul
));
523 size
-= 2*sizeof(ul
);
530 while (size
>= sizeof(us
)) {
533 us
= EXTRACT_16BITS(bp
);
569 putchar(c
== 'x' ? ':' : '.');
581 /* Guys we can't handle with one of the usual cases */
584 case TAG_NETBIOS_NODE
:
587 fputs(tok2str(nbo2str
, NULL
, tag
), stdout
);
590 case TAG_OPT_OVERLOAD
:
593 fputs(tok2str(oo2str
, NULL
, tag
), stdout
);
596 case TAG_CLIENT_FQDN
:
597 /* option 81 should be at least 3 bytes long */
599 printf("ERROR: option 81 len %u < 3 bytes", len
);
603 printf("[%s] ", client_fqdn_flags(*bp
));
606 printf("%u/%u ", *bp
, *(bp
+1));
609 if (fn_printn(bp
, size
- 3, snapend
)) {
623 if (fn_printn(bp
, size
, snapend
)) {
632 printf("%s ", tok2str(arp2str
, "hardware-type %u,", type
));
645 case TAG_AGENT_CIRCUIT
:
651 printf("\n\t %s SubOption %u, length %u: ",
652 tok2str(agent_suboption_values
, "Unknown", subopt
),
656 if (subopt
== 0 || suboptlen
== 0) {
661 case AGENT_SUBOPTION_CIRCUIT_ID
:
662 for (idx
= 0; idx
< suboptlen
; idx
++) {
663 safeputchar(*(bp
+idx
));
667 print_unknown_data(bp
, "\n\t\t", suboptlen
);
677 printf("[unknown special tag %u, size %u]",
685 /* Data left over? */
687 printf("\n\t trailing data length %u", len
);
693 printf("|[rfc1048]");
697 cmu_print(register const u_char
*bp
)
699 register const struct cmu_vend
*cmu
;
701 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
702 if (cmu->m.s_addr != 0) \
703 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
706 cmu
= (const struct cmu_vend
*)bp
;
708 /* Only print if there are unknown bits */
709 TCHECK(cmu
->v_flags
);
710 if ((cmu
->v_flags
& ~(VF_SMASK
)) != 0)
711 printf(" F:0x%x", cmu
->v_flags
);
712 PRINTCMUADDR(v_dgate
, "DG");
713 PRINTCMUADDR(v_smask
, cmu
->v_flags
& VF_SMASK
? "SM" : "SM*");
714 PRINTCMUADDR(v_dns1
, "NS1");
715 PRINTCMUADDR(v_dns2
, "NS2");
716 PRINTCMUADDR(v_ins1
, "IEN1");
717 PRINTCMUADDR(v_ins2
, "IEN2");
718 PRINTCMUADDR(v_ts1
, "TS1");
719 PRINTCMUADDR(v_ts2
, "TS2");
728 client_fqdn_flags(u_int flags
)
730 static char buf
[8+1];
733 if (flags
& CLIENT_FQDN_FLAGS_S
)
735 if (flags
& CLIENT_FQDN_FLAGS_O
)
737 if (flags
& CLIENT_FQDN_FLAGS_E
)
739 if (flags
& CLIENT_FQDN_FLAGS_N
)