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.78.2.3 2006/02/13 19:02:05 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
, "iSubnet-Mask" }, /* subnet mask (RFC950) */
193 { TAG_TIME_OFFSET
, "LTime-Zone" }, /* seconds from UTC */
194 { TAG_GATEWAY
, "iDefault-Gateway" }, /* default gateway */
195 { TAG_TIME_SERVER
, "iTime-Server" }, /* time servers (RFC868) */
196 { TAG_NAME_SERVER
, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
197 { TAG_DOMAIN_SERVER
, "iDomain-Name-Server" }, /* domain name (RFC1035) */
198 { TAG_LOG_SERVER
, "iLOG" }, /* MIT log servers */
199 { TAG_COOKIE_SERVER
, "iCS" }, /* cookie servers (RFC865) */
200 { TAG_LPR_SERVER
, "iLPR-Server" }, /* lpr server (RFC1179) */
201 { TAG_IMPRESS_SERVER
, "iIM" }, /* impress servers (Imagen) */
202 { TAG_RLP_SERVER
, "iRL" }, /* resource location (RFC887) */
203 { TAG_HOSTNAME
, "aHostname" }, /* ascii hostname */
204 { TAG_BOOTSIZE
, "sBS" }, /* 512 byte blocks */
207 { TAG_DUMPPATH
, "aDP" },
208 { TAG_DOMAINNAME
, "aDomain-Name" },
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
, "lMTU-Timeout" },
219 { TAG_MTU_TABLE
, "sMTU-Table" },
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
, "BRouter-Discovery" },
226 { TAG_RTR_SOL_ADDR
, "iRSA" },
227 { TAG_STATIC_ROUTE
, "pStatic-Route" },
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
, "bVendor-Option" },
238 { TAG_NETBIOS_NS
, "iNetbios-Name-Server" },
239 { TAG_NETBIOS_DDS
, "iWDD" },
240 { TAG_NETBIOS_NODE
, "$Netbios-Node" },
241 { TAG_NETBIOS_SCOPE
, "aNetbios-Scope" },
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
, "iRequested-IP" },
256 { TAG_IP_LEASE
, "lLease-Time" },
257 { TAG_OPT_OVERLOAD
, "$OO" },
258 { TAG_TFTP_SERVER
, "aTFTP" },
259 { TAG_BOOTFILENAME
, "aBF" },
260 { TAG_DHCP_MESSAGE
, " DHCP-Message" },
261 { TAG_SERVER_ID
, "iServer-ID" },
262 { TAG_PARM_REQUEST
, "bParameter-Request" },
263 { TAG_MESSAGE
, "aMSG" },
264 { TAG_MAX_MSG_SIZE
, "sMSZ" },
265 { TAG_RENEWAL_TIME
, "lRN" },
266 { TAG_REBIND_TIME
, "lRB" },
267 { TAG_VENDOR_CLASS
, "aVendor-Class" },
268 { TAG_CLIENT_ID
, "$Client-ID" },
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
, "$Agent-Information" },
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" },
339 static struct tok dhcp_msg_values
[] = {
340 { DHCPDISCOVER
, "Discover" },
341 { DHCPOFFER
, "Offer" },
342 { DHCPREQUEST
, "Request" },
343 { DHCPDECLINE
, "Decline" },
346 { DHCPRELEASE
, "Release" },
347 { DHCPINFORM
, "Inform" },
351 #define AGENT_SUBOPTION_CIRCUIT_ID 1
352 static struct tok agent_suboption_values
[] = {
353 { AGENT_SUBOPTION_CIRCUIT_ID
, "Circuit-ID" },
359 rfc1048_print(register const u_char
*bp
)
361 register u_int16_t tag
;
362 register u_int len
, size
;
363 register const char *cp
;
368 u_int8_t uc
, subopt
, suboptlen
;
370 printf("\n\t Vendor-rfc1048 Extensions");
372 /* Step over magic cookie */
373 printf("\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp
));
374 bp
+= sizeof(int32_t);
376 /* Loop while we there is a tag left in the buffer */
377 while (bp
+ 1 < snapend
) {
383 if (tag
== TAG_EXTENDED_OPTION
) {
384 TCHECK2(*(bp
+ 1), 2);
385 tag
= EXTRACT_16BITS(bp
+ 1);
386 /* XXX we don't know yet if the IANA will
387 * preclude overlap of 1-byte and 2-byte spaces.
388 * If not, we need to offset tag after this step.
390 cp
= tok2str(xtag2str
, "?xT%u", tag
);
392 cp
= tok2str(tag2str
, "?T%u", tag
);
395 /* Get the length; check for truncation */
396 if (bp
+ 1 >= snapend
) {
402 printf("\n\t %s Option %u, length %u: ", cp
, tag
, len
);
404 if (bp
+ len
>= snapend
) {
405 printf("[|bootp %u]", len
);
409 if (tag
== TAG_DHCP_MESSAGE
&& len
== 1) {
411 printf("%s", tok2str(dhcp_msg_values
, "Unknown (%u)", uc
));
415 if (tag
== TAG_PARM_REQUEST
) {
421 cp
= tok2str(tag2str
, "?Option %u", uc
);
422 printf("%s%s", (first
|| (!(idx
%4))) ? "" : ", ", cp
+ 1);
432 if (tag
== TAG_EXTENDED_REQUEST
) {
436 us
= EXTRACT_16BITS(bp
);
438 cp
= tok2str(xtag2str
, "?xT%u", us
);
441 printf("%s", cp
+ 1);
450 /* Base default formats for unknown tags on data size */
464 if (fn_printn(bp
, size
, snapend
)) {
476 /* ip addresses/32-bit words */
477 while (size
>= sizeof(ul
)) {
480 ul
= EXTRACT_32BITS(bp
);
483 printf("%s", ipaddr_string(&ul
));
495 /* IP address pairs */
496 while (size
>= 2*sizeof(ul
)) {
499 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
500 printf("(%s:", ipaddr_string(&ul
));
502 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
503 printf("%s)", ipaddr_string(&ul
));
505 size
-= 2*sizeof(ul
);
512 while (size
>= sizeof(us
)) {
515 us
= EXTRACT_16BITS(bp
);
551 putchar(c
== 'x' ? ':' : '.');
563 /* Guys we can't handle with one of the usual cases */
566 case TAG_NETBIOS_NODE
:
569 fputs(tok2str(nbo2str
, NULL
, tag
), stdout
);
572 case TAG_OPT_OVERLOAD
:
575 fputs(tok2str(oo2str
, NULL
, tag
), stdout
);
578 case TAG_CLIENT_FQDN
:
579 /* option 81 should be at least 4 bytes long */
581 printf("ERROR: options 81 len %u < 4 bytes", len
);
587 printf("%u/%u/", *bp
, *(bp
+1));
590 if (fn_printn(bp
, size
- 3, snapend
)) {
604 if (fn_printn(bp
, size
, snapend
)) {
613 printf("%s ", tok2str(arp2str
, "hardware-type %u,", type
));
626 case TAG_AGENT_CIRCUIT
:
632 printf("\n\t %s SubOption %u, length %u: ",
633 tok2str(agent_suboption_values
, "Unknown", subopt
),
637 if (subopt
== 0 || suboptlen
== 0) {
642 case AGENT_SUBOPTION_CIRCUIT_ID
:
643 for (idx
= 0; idx
< suboptlen
; idx
++) {
644 safeputchar(*(bp
+idx
));
648 print_unknown_data(bp
, "\n\t\t", suboptlen
);
658 printf("[unknown special tag %u, size %u]",
666 /* Data left over? */
668 printf("\n\t trailing data length %u", len
);
674 printf("|[rfc1048]");
678 cmu_print(register const u_char
*bp
)
680 register const struct cmu_vend
*cmu
;
682 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
683 if (cmu->m.s_addr != 0) \
684 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
687 cmu
= (const struct cmu_vend
*)bp
;
689 /* Only print if there are unknown bits */
690 TCHECK(cmu
->v_flags
);
691 if ((cmu
->v_flags
& ~(VF_SMASK
)) != 0)
692 printf(" F:0x%x", cmu
->v_flags
);
693 PRINTCMUADDR(v_dgate
, "DG");
694 PRINTCMUADDR(v_smask
, cmu
->v_flags
& VF_SMASK
? "SM" : "SM*");
695 PRINTCMUADDR(v_dns1
, "NS1");
696 PRINTCMUADDR(v_dns2
, "NS2");
697 PRINTCMUADDR(v_ins1
, "IEN1");
698 PRINTCMUADDR(v_ins2
, "IEN2");
699 PRINTCMUADDR(v_ts1
, "TS1");
700 PRINTCMUADDR(v_ts2
, "TS2");