]>
The Tcpdump Group git mirrors - tcpdump/blob - print-bootp.c
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
[] =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.73 2003-05-01 18:02:12 guy 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]";
49 * Print bootp requests
52 bootp_print(register const u_char
*cp
, u_int length
)
54 register const struct bootp
*bp
;
55 static const u_char vm_cmu
[4] = VM_CMU
;
56 static const u_char vm_rfc1048
[4] = VM_RFC1048
;
58 bp
= (const struct bootp
*)cp
;
61 printf("BOOTP/DHCP, %s",
62 tok2str(bootp_op_values
, "unknown (0x%02x)", bp
->bp_op
));
64 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6 && bp
->bp_op
== BOOTPREQUEST
) {
65 TCHECK2(bp
->bp_chaddr
[0], 6);
66 printf(" from %s", etheraddr_string(bp
->bp_chaddr
));
69 printf(", length: %u", length
);
76 /* The usual hardware address type is 1 (10Mb Ethernet) */
77 if (bp
->bp_htype
!= 1)
78 printf(", htype-#%d", bp
->bp_htype
);
80 /* The usual length for 10Mb Ethernet address is 6 bytes */
81 if (bp
->bp_htype
!= 1 || bp
->bp_hlen
!= 6)
82 printf(", hlen:%d", bp
->bp_hlen
);
84 /* Only print interesting fields */
86 printf(", hops:%d", bp
->bp_hops
);
88 printf(", xid:0x%x", EXTRACT_32BITS(&bp
->bp_xid
));
90 printf(", secs:%d", EXTRACT_16BITS(&bp
->bp_secs
));
92 printf(", flags: [%s]",
93 bittok2str(bootp_flag_values
, "none", EXTRACT_16BITS(&bp
->bp_flags
)));
95 printf( " (0x%04x)", EXTRACT_16BITS(&bp
->bp_flags
));
97 /* Client's ip address */
98 TCHECK(bp
->bp_ciaddr
);
99 if (bp
->bp_ciaddr
.s_addr
)
100 printf("\n\t Client IP: %s", ipaddr_string(&bp
->bp_ciaddr
));
102 /* 'your' ip address (bootp client) */
103 TCHECK(bp
->bp_yiaddr
);
104 if (bp
->bp_yiaddr
.s_addr
)
105 printf("\n\t Your IP: %s", ipaddr_string(&bp
->bp_yiaddr
));
107 /* Server's ip address */
108 TCHECK(bp
->bp_siaddr
);
109 if (bp
->bp_siaddr
.s_addr
)
110 printf("\n\t Server IP: %s", ipaddr_string(&bp
->bp_siaddr
));
112 /* Gateway's ip address */
113 TCHECK(bp
->bp_giaddr
);
114 if (bp
->bp_giaddr
.s_addr
)
115 printf("\n\t Gateway IP: %s", ipaddr_string(&bp
->bp_giaddr
));
117 /* Client's Ethernet address */
118 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6) {
119 TCHECK2(bp
->bp_chaddr
[0], 6);
120 printf("\n\t Client Ethernet Address: %s", etheraddr_string(bp
->bp_chaddr
));
123 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
125 printf("\n\t sname \"");
126 if (fn_print(bp
->bp_sname
, snapend
)) {
128 fputs(tstr
+ 1, stdout
);
133 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
135 printf("\n\t file \"");
136 if (fn_print(bp
->bp_file
, snapend
)) {
138 fputs(tstr
+ 1, stdout
);
144 /* Decode the vendor buffer */
145 TCHECK(bp
->bp_vend
[0]);
146 if (memcmp((const char *)bp
->bp_vend
, vm_rfc1048
,
147 sizeof(u_int32_t
)) == 0)
148 rfc1048_print(bp
->bp_vend
);
149 else if (memcmp((const char *)bp
->bp_vend
, vm_cmu
,
150 sizeof(u_int32_t
)) == 0)
151 cmu_print(bp
->bp_vend
);
155 ul
= EXTRACT_32BITS(&bp
->bp_vend
);
157 printf("\n\t Vendor-#0x%x", ul
);
166 * The first character specifies the format to print:
167 * i - ip address (32 bits)
168 * p - ip address pairs (32 bits + 32 bits)
170 * L - unsigned long (32 bits)
171 * s - short (16 bits)
172 * b - period-seperated decimal bytes (variable length)
173 * x - colon-seperated hex bytes (variable length)
174 * a - ascii string (variable length)
175 * B - on/off (8 bits)
176 * $ - special (explicit code to handle)
178 static struct tok tag2str
[] = {
181 { TAG_SUBNET_MASK
, "iSM" }, /* subnet mask (RFC950) */
182 { TAG_TIME_OFFSET
, "LTZ" }, /* seconds from UTC */
183 { TAG_GATEWAY
, "iDG" }, /* default gateway */
184 { TAG_TIME_SERVER
, "iTS" }, /* time servers (RFC868) */
185 { TAG_NAME_SERVER
, "iIEN" }, /* IEN name servers (IEN116) */
186 { TAG_DOMAIN_SERVER
, "iNS" }, /* domain name (RFC1035) */
187 { TAG_LOG_SERVER
, "iLOG" }, /* MIT log servers */
188 { TAG_COOKIE_SERVER
, "iCS" }, /* cookie servers (RFC865) */
189 { TAG_LPR_SERVER
, "iLPR" }, /* lpr server (RFC1179) */
190 { TAG_IMPRESS_SERVER
, "iIM" }, /* impress servers (Imagen) */
191 { TAG_RLP_SERVER
, "iRL" }, /* resource location (RFC887) */
192 { TAG_HOSTNAME
, "aHN" }, /* ascii hostname */
193 { TAG_BOOTSIZE
, "sBS" }, /* 512 byte blocks */
196 { TAG_DUMPPATH
, "aDP" },
197 { TAG_DOMAINNAME
, "aDN" },
198 { TAG_SWAP_SERVER
, "iSS" },
199 { TAG_ROOTPATH
, "aRP" },
200 { TAG_EXTPATH
, "aEP" },
202 { TAG_IP_FORWARD
, "BIPF" },
203 { TAG_NL_SRCRT
, "BSRT" },
204 { TAG_PFILTERS
, "pPF" },
205 { TAG_REASS_SIZE
, "sRSZ" },
206 { TAG_DEF_TTL
, "bTTL" },
207 { TAG_MTU_TIMEOUT
, "lMA" },
208 { TAG_MTU_TABLE
, "sMT" },
209 { TAG_INT_MTU
, "sMTU" },
210 { TAG_LOCAL_SUBNETS
, "BLSN" },
211 { TAG_BROAD_ADDR
, "iBR" },
212 { TAG_DO_MASK_DISC
, "BMD" },
213 { TAG_SUPPLY_MASK
, "BMS" },
214 { TAG_DO_RDISC
, "BRD" },
215 { TAG_RTR_SOL_ADDR
, "iRSA" },
216 { TAG_STATIC_ROUTE
, "pSR" },
217 { TAG_USE_TRAILERS
, "BUT" },
218 { TAG_ARP_TIMEOUT
, "lAT" },
219 { TAG_ETH_ENCAP
, "BIE" },
220 { TAG_TCP_TTL
, "bTT" },
221 { TAG_TCP_KEEPALIVE
, "lKI" },
222 { TAG_KEEPALIVE_GO
, "BKG" },
223 { TAG_NIS_DOMAIN
, "aYD" },
224 { TAG_NIS_SERVERS
, "iYS" },
225 { TAG_NTP_SERVERS
, "iNTP" },
226 { TAG_VENDOR_OPTS
, "bVO" },
227 { TAG_NETBIOS_NS
, "iWNS" },
228 { TAG_NETBIOS_DDS
, "iWDD" },
229 { TAG_NETBIOS_NODE
, "$WNT" },
230 { TAG_NETBIOS_SCOPE
, "aWSC" },
231 { TAG_XWIN_FS
, "iXFS" },
232 { TAG_XWIN_DM
, "iXDM" },
233 { TAG_NIS_P_DOMAIN
, "sN+D" },
234 { TAG_NIS_P_SERVERS
, "iN+S" },
235 { TAG_MOBILE_HOME
, "iMH" },
236 { TAG_SMPT_SERVER
, "iSMTP" },
237 { TAG_POP3_SERVER
, "iPOP3" },
238 { TAG_NNTP_SERVER
, "iNNTP" },
239 { TAG_WWW_SERVER
, "iWWW" },
240 { TAG_FINGER_SERVER
, "iFG" },
241 { TAG_IRC_SERVER
, "iIRC" },
242 { TAG_STREETTALK_SRVR
, "iSTS" },
243 { TAG_STREETTALK_STDA
, "iSTDA" },
244 { TAG_REQUESTED_IP
, "iRQ" },
245 { TAG_IP_LEASE
, "lLT" },
246 { TAG_OPT_OVERLOAD
, "$OO" },
247 { TAG_TFTP_SERVER
, "aTFTP" },
248 { TAG_BOOTFILENAME
, "aBF" },
249 { TAG_DHCP_MESSAGE
, " DHCP" },
250 { TAG_SERVER_ID
, "iSID" },
251 { TAG_PARM_REQUEST
, "bPR" },
252 { TAG_MESSAGE
, "aMSG" },
253 { TAG_MAX_MSG_SIZE
, "sMSZ" },
254 { TAG_RENEWAL_TIME
, "lRN" },
255 { TAG_REBIND_TIME
, "lRB" },
256 { TAG_VENDOR_CLASS
, "aVC" },
257 { TAG_CLIENT_ID
, "$CID" },
259 { TAG_OPEN_GROUP_UAP
, "aUAP" },
261 { TAG_DISABLE_AUTOCONF
, "BNOAUTO" },
263 { TAG_SLP_DA
, "bSLP-DA" }, /*"b" is a little wrong */
264 { TAG_SLP_SCOPE
, "bSLP-SCOPE" }, /*"b" is a little wrong */
266 { TAG_NS_SEARCH
, "sNSSEARCH" }, /* XXX 's' */
268 { TAG_IP4_SUBNET_SELECT
, "iSUBNET" },
269 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
270 { TAG_USER_CLASS
, "aCLASS" },
271 { TAG_SLP_NAMING_AUTH
, "aSLP-NA" },
272 { TAG_CLIENT_FQDN
, "$FQDN" },
273 { TAG_AGENT_CIRCUIT
, "bACKT" },
274 { TAG_AGENT_REMOTE
, "bARMT" },
275 { TAG_AGENT_MASK
, "bAMSK" },
276 { TAG_TZ_STRING
, "aTZSTR" },
277 { TAG_FQDN_OPTION
, "bFQDNS" }, /* XXX 'b' */
278 { TAG_AUTH
, "bAUTH" }, /* XXX 'b' */
279 { TAG_VINES_SERVERS
, "iVINES" },
280 { TAG_SERVER_RANK
, "sRANK" },
281 { TAG_CLIENT_ARCH
, "sARCH" },
282 { TAG_CLIENT_NDI
, "bNDI" }, /* XXX 'b' */
283 { TAG_CLIENT_GUID
, "bGUID" }, /* XXX 'b' */
284 { TAG_LDAP_URL
, "aLDAP" },
285 { TAG_6OVER4
, "i6o4" },
286 { TAG_PRINTER_NAME
, "aPRTR" },
287 { TAG_MDHCP_SERVER
, "bMDHCP" }, /* XXX 'b' */
288 { TAG_IPX_COMPAT
, "bIPX" }, /* XXX 'b' */
289 { TAG_NETINFO_PARENT
, "iNI" },
290 { TAG_NETINFO_PARENT_TAG
, "aNITAG" },
292 { TAG_FAILOVER
, "bFAIL" }, /* XXX 'b' */
295 /* 2-byte extended tags */
296 static struct tok xtag2str
[] = {
300 /* DHCP "options overload" types */
301 static struct tok oo2str
[] = {
308 /* NETBIOS over TCP/IP node type options */
309 static struct tok nbo2str
[] = {
317 /* ARP Hardware types, for Client-ID option */
318 static struct tok arp2str
[] = {
324 { 0x18, "ieee1394" },
329 rfc1048_print(register const u_char
*bp
)
331 register u_int16_t tag
;
332 register u_int len
, size
;
333 register const char *cp
;
340 printf("\n\t Vendor-rfc1048:");
342 /* Step over magic cookie */
343 bp
+= sizeof(int32_t);
345 /* Loop while we there is a tag left in the buffer */
346 while (bp
+ 1 < snapend
) {
352 if (tag
== TAG_EXTENDED_OPTION
) {
353 TCHECK2(*(bp
+ 1), 2);
354 tag
= EXTRACT_16BITS(bp
+ 1);
355 /* XXX we don't know yet if the IANA will
356 * preclude overlap of 1-byte and 2-byte spaces.
357 * If not, we need to offset tag after this step.
359 cp
= tok2str(xtag2str
, "?xT%u", tag
);
361 cp
= tok2str(tag2str
, "?T%u", tag
);
363 printf("\n\t %s:", cp
);
365 /* Get the length; check for truncation */
366 if (bp
+ 1 >= snapend
) {
371 if (bp
+ len
>= snapend
) {
372 printf("[|bootp %u]", len
);
376 if (tag
== TAG_DHCP_MESSAGE
&& len
== 1) {
379 case DHCPDISCOVER
: printf("DISCOVER"); break;
380 case DHCPOFFER
: printf("OFFER"); break;
381 case DHCPREQUEST
: printf("REQUEST"); break;
382 case DHCPDECLINE
: printf("DECLINE"); break;
383 case DHCPACK
: printf("ACK"); break;
384 case DHCPNAK
: printf("NACK"); break;
385 case DHCPRELEASE
: printf("RELEASE"); break;
386 case DHCPINFORM
: printf("INFORM"); break;
387 default: printf("%u", uc
); break;
392 if (tag
== TAG_PARM_REQUEST
) {
396 cp
= tok2str(tag2str
, "?T%u", uc
);
399 printf("%s", cp
+ 1);
404 if (tag
== TAG_EXTENDED_REQUEST
) {
408 us
= EXTRACT_16BITS(bp
);
410 cp
= tok2str(xtag2str
, "?xT%u", us
);
413 printf("%s", cp
+ 1);
422 /* Base default formats for unknown tags on data size */
436 (void)fn_printn(bp
, size
, NULL
);
445 /* ip addresses/32-bit words */
446 while (size
>= sizeof(ul
)) {
449 ul
= EXTRACT_32BITS(bp
);
452 printf("%s", ipaddr_string(&ul
));
464 /* IP address pairs */
465 while (size
>= 2*sizeof(ul
)) {
468 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
469 printf("(%s:", ipaddr_string(&ul
));
471 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
472 printf("%s)", ipaddr_string(&ul
));
474 size
-= 2*sizeof(ul
);
481 while (size
>= sizeof(us
)) {
484 us
= EXTRACT_16BITS(bp
);
520 putchar(c
== 'x' ? ':' : '.');
532 /* Guys we can't handle with one of the usual cases */
535 case TAG_NETBIOS_NODE
:
538 fputs(tok2str(nbo2str
, NULL
, tag
), stdout
);
541 case TAG_OPT_OVERLOAD
:
544 fputs(tok2str(oo2str
, NULL
, tag
), stdout
);
547 case TAG_CLIENT_FQDN
:
551 printf("%u/%u/", *bp
, *(bp
+1));
554 (void)fn_printn(bp
, size
- 3, NULL
);
565 (void)fn_printn(bp
, size
, NULL
);
571 printf("[%s]", tok2str(arp2str
, "type-%d", type
));
585 printf("[unknown special tag %u, size %u]",
593 /* Data left over? */
595 printf("[len %u]", len
);
601 printf("|[rfc1048]");
605 cmu_print(register const u_char
*bp
)
607 register const struct cmu_vend
*cmu
;
609 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
610 if (cmu->m.s_addr != 0) \
611 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
614 cmu
= (const struct cmu_vend
*)bp
;
616 /* Only print if there are unknown bits */
617 TCHECK(cmu
->v_flags
);
618 if ((cmu
->v_flags
& ~(VF_SMASK
)) != 0)
619 printf(" F:0x%x", cmu
->v_flags
);
620 PRINTCMUADDR(v_dgate
, "DG");
621 PRINTCMUADDR(v_smask
, cmu
->v_flags
& VF_SMASK
? "SM" : "SM*");
622 PRINTCMUADDR(v_dns1
, "NS1");
623 PRINTCMUADDR(v_dns2
, "NS2");
624 PRINTCMUADDR(v_ins1
, "IEN1");
625 PRINTCMUADDR(v_ins2
, "IEN2");
626 PRINTCMUADDR(v_ts1
, "TS1");
627 PRINTCMUADDR(v_ts2
, "TS2");