]>
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.69 2002-12-18 08:53:20 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_short sport
, u_short dport
, 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 printf("BOOTP/DHCP, length: %u",length
);
63 bp
= (const struct bootp
*)cp
;
68 /* Usually, a request goes from a client to a server */
69 if (sport
== IPPORT_BOOTPC
&& dport
== IPPORT_BOOTPS
)
70 printf("\n\tRequest");
74 /* Usually, a reply goes from a server to a client */
75 if (sport
== IPPORT_BOOTPS
&& dport
== IPPORT_BOOTPC
)
80 printf("\n\tbootp-#%d", bp
->bp_op
);
86 /* The usual hardware address type is 1 (10Mb Ethernet) */
87 if (bp
->bp_htype
!= 1)
88 printf(", htype-#%d", bp
->bp_htype
);
90 /* The usual length for 10Mb Ethernet address is 6 bytes */
91 if (bp
->bp_htype
!= 1 || bp
->bp_hlen
!= 6)
92 printf(", hlen:%d", bp
->bp_hlen
);
94 /* Only print interesting fields */
96 printf(", hops:%d", bp
->bp_hops
);
98 printf(", xid:0x%x", EXTRACT_32BITS(&bp
->bp_xid
));
100 printf(", secs:%d", EXTRACT_16BITS(&bp
->bp_secs
));
102 printf(", flags:0x%x", EXTRACT_16BITS(&bp
->bp_flags
));
104 /* Client's ip address */
105 TCHECK(bp
->bp_ciaddr
);
106 if (bp
->bp_ciaddr
.s_addr
)
107 printf("\n\t Client IP: %s", ipaddr_string(&bp
->bp_ciaddr
));
109 /* 'your' ip address (bootp client) */
110 TCHECK(bp
->bp_yiaddr
);
111 if (bp
->bp_yiaddr
.s_addr
)
112 printf("\n\t Your IP: %s", ipaddr_string(&bp
->bp_yiaddr
));
114 /* Server's ip address */
115 TCHECK(bp
->bp_siaddr
);
116 if (bp
->bp_siaddr
.s_addr
)
117 printf("\n\t Server IP: %s", ipaddr_string(&bp
->bp_siaddr
));
119 /* Gateway's ip address */
120 TCHECK(bp
->bp_giaddr
);
121 if (bp
->bp_giaddr
.s_addr
)
122 printf("\n\t Gateway IP: %s", ipaddr_string(&bp
->bp_giaddr
));
124 /* Client's Ethernet address */
125 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6) {
126 TCHECK2(bp
->bp_chaddr
[0], 6);
127 printf("\n\t Client Ethernet Address: %s", etheraddr_string(bp
->bp_chaddr
));
130 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
132 printf("\n\t sname \"");
133 if (fn_print(bp
->bp_sname
, snapend
)) {
135 fputs(tstr
+ 1, stdout
);
140 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
142 printf("\n\t file \"");
143 if (fn_print(bp
->bp_file
, snapend
)) {
145 fputs(tstr
+ 1, stdout
);
151 /* Decode the vendor buffer */
152 TCHECK(bp
->bp_vend
[0]);
153 if (memcmp((const char *)bp
->bp_vend
, vm_rfc1048
,
154 sizeof(u_int32_t
)) == 0)
155 rfc1048_print(bp
->bp_vend
);
156 else if (memcmp((const char *)bp
->bp_vend
, vm_cmu
,
157 sizeof(u_int32_t
)) == 0)
158 cmu_print(bp
->bp_vend
);
162 ul
= EXTRACT_32BITS(&bp
->bp_vend
);
164 printf("\n\t Vendor-#0x%x", ul
);
173 * The first character specifies the format to print:
174 * i - ip address (32 bits)
175 * p - ip address pairs (32 bits + 32 bits)
177 * L - unsigned long (32 bits)
178 * s - short (16 bits)
179 * b - period-seperated decimal bytes (variable length)
180 * x - colon-seperated hex bytes (variable length)
181 * a - ascii string (variable length)
182 * B - on/off (8 bits)
183 * $ - special (explicit code to handle)
185 static struct tok tag2str
[] = {
188 { TAG_SUBNET_MASK
, "iSM" }, /* subnet mask (RFC950) */
189 { TAG_TIME_OFFSET
, "LTZ" }, /* seconds from UTC */
190 { TAG_GATEWAY
, "iDG" }, /* default gateway */
191 { TAG_TIME_SERVER
, "iTS" }, /* time servers (RFC868) */
192 { TAG_NAME_SERVER
, "iIEN" }, /* IEN name servers (IEN116) */
193 { TAG_DOMAIN_SERVER
, "iNS" }, /* domain name (RFC1035) */
194 { TAG_LOG_SERVER
, "iLOG" }, /* MIT log servers */
195 { TAG_COOKIE_SERVER
, "iCS" }, /* cookie servers (RFC865) */
196 { TAG_LPR_SERVER
, "iLPR" }, /* lpr server (RFC1179) */
197 { TAG_IMPRESS_SERVER
, "iIM" }, /* impress servers (Imagen) */
198 { TAG_RLP_SERVER
, "iRL" }, /* resource location (RFC887) */
199 { TAG_HOSTNAME
, "aHN" }, /* ascii hostname */
200 { TAG_BOOTSIZE
, "sBS" }, /* 512 byte blocks */
203 { TAG_DUMPPATH
, "aDP" },
204 { TAG_DOMAINNAME
, "aDN" },
205 { TAG_SWAP_SERVER
, "iSS" },
206 { TAG_ROOTPATH
, "aRP" },
207 { TAG_EXTPATH
, "aEP" },
209 { TAG_IP_FORWARD
, "BIPF" },
210 { TAG_NL_SRCRT
, "BSRT" },
211 { TAG_PFILTERS
, "pPF" },
212 { TAG_REASS_SIZE
, "sRSZ" },
213 { TAG_DEF_TTL
, "bTTL" },
214 { TAG_MTU_TIMEOUT
, "lMA" },
215 { TAG_MTU_TABLE
, "sMT" },
216 { TAG_INT_MTU
, "sMTU" },
217 { TAG_LOCAL_SUBNETS
, "BLSN" },
218 { TAG_BROAD_ADDR
, "iBR" },
219 { TAG_DO_MASK_DISC
, "BMD" },
220 { TAG_SUPPLY_MASK
, "BMS" },
221 { TAG_DO_RDISC
, "BRD" },
222 { TAG_RTR_SOL_ADDR
, "iRSA" },
223 { TAG_STATIC_ROUTE
, "pSR" },
224 { TAG_USE_TRAILERS
, "BUT" },
225 { TAG_ARP_TIMEOUT
, "lAT" },
226 { TAG_ETH_ENCAP
, "BIE" },
227 { TAG_TCP_TTL
, "bTT" },
228 { TAG_TCP_KEEPALIVE
, "lKI" },
229 { TAG_KEEPALIVE_GO
, "BKG" },
230 { TAG_NIS_DOMAIN
, "aYD" },
231 { TAG_NIS_SERVERS
, "iYS" },
232 { TAG_NTP_SERVERS
, "iNTP" },
233 { TAG_VENDOR_OPTS
, "bVO" },
234 { TAG_NETBIOS_NS
, "iWNS" },
235 { TAG_NETBIOS_DDS
, "iWDD" },
236 { TAG_NETBIOS_NODE
, "$WNT" },
237 { TAG_NETBIOS_SCOPE
, "aWSC" },
238 { TAG_XWIN_FS
, "iXFS" },
239 { TAG_XWIN_DM
, "iXDM" },
240 { TAG_NIS_P_DOMAIN
, "sN+D" },
241 { TAG_NIS_P_SERVERS
, "iN+S" },
242 { TAG_MOBILE_HOME
, "iMH" },
243 { TAG_SMPT_SERVER
, "iSMTP" },
244 { TAG_POP3_SERVER
, "iPOP3" },
245 { TAG_NNTP_SERVER
, "iNNTP" },
246 { TAG_WWW_SERVER
, "iWWW" },
247 { TAG_FINGER_SERVER
, "iFG" },
248 { TAG_IRC_SERVER
, "iIRC" },
249 { TAG_STREETTALK_SRVR
, "iSTS" },
250 { TAG_STREETTALK_STDA
, "iSTDA" },
251 { TAG_REQUESTED_IP
, "iRQ" },
252 { TAG_IP_LEASE
, "lLT" },
253 { TAG_OPT_OVERLOAD
, "$OO" },
254 { TAG_TFTP_SERVER
, "aTFTP" },
255 { TAG_BOOTFILENAME
, "aBF" },
256 { TAG_DHCP_MESSAGE
, " DHCP" },
257 { TAG_SERVER_ID
, "iSID" },
258 { TAG_PARM_REQUEST
, "bPR" },
259 { TAG_MESSAGE
, "aMSG" },
260 { TAG_MAX_MSG_SIZE
, "sMSZ" },
261 { TAG_RENEWAL_TIME
, "lRN" },
262 { TAG_REBIND_TIME
, "lRB" },
263 { TAG_VENDOR_CLASS
, "aVC" },
264 { TAG_CLIENT_ID
, "$CID" },
266 { TAG_OPEN_GROUP_UAP
, "aUAP" },
268 { TAG_DISABLE_AUTOCONF
, "BNOAUTO" },
270 { TAG_SLP_DA
, "bSLP-DA" }, /*"b" is a little wrong */
271 { TAG_SLP_SCOPE
, "bSLP-SCOPE" }, /*"b" is a little wrong */
273 { TAG_NS_SEARCH
, "sNSSEARCH" }, /* XXX 's' */
275 { TAG_IP4_SUBNET_SELECT
, "iSUBNET" },
276 /* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */
277 { TAG_USER_CLASS
, "aCLASS" },
278 { TAG_SLP_NAMING_AUTH
, "aSLP-NA" },
279 { TAG_CLIENT_FQDN
, "$FQDN" },
280 { TAG_AGENT_CIRCUIT
, "bACKT" },
281 { TAG_AGENT_REMOTE
, "bARMT" },
282 { TAG_AGENT_MASK
, "bAMSK" },
283 { TAG_TZ_STRING
, "aTZSTR" },
284 { TAG_FQDN_OPTION
, "bFQDNS" }, /* XXX 'b' */
285 { TAG_AUTH
, "bAUTH" }, /* XXX 'b' */
286 { TAG_VINES_SERVERS
, "iVINES" },
287 { TAG_SERVER_RANK
, "sRANK" },
288 { TAG_CLIENT_ARCH
, "sARCH" },
289 { TAG_CLIENT_NDI
, "bNDI" }, /* XXX 'b' */
290 { TAG_CLIENT_GUID
, "bGUID" }, /* XXX 'b' */
291 { TAG_LDAP_URL
, "aLDAP" },
292 { TAG_6OVER4
, "i6o4" },
293 { TAG_PRINTER_NAME
, "aPRTR" },
294 { TAG_MDHCP_SERVER
, "bMDHCP" }, /* XXX 'b' */
295 { TAG_IPX_COMPAT
, "bIPX" }, /* XXX 'b' */
296 { TAG_NETINFO_PARENT
, "iNI" },
297 { TAG_NETINFO_PARENT_TAG
, "aNITAG" },
299 { TAG_FAILOVER
, "bFAIL" }, /* XXX 'b' */
302 /* 2-byte extended tags */
303 static struct tok xtag2str
[] = {
307 /* DHCP "options overload" types */
308 static struct tok oo2str
[] = {
315 /* NETBIOS over TCP/IP node type options */
316 static struct tok nbo2str
[] = {
324 /* ARP Hardware types, for Client-ID option */
325 static struct tok arp2str
[] = {
331 { 0x18, "ieee1394" },
336 rfc1048_print(register const u_char
*bp
)
338 register u_int16_t tag
;
339 register u_int len
, size
;
340 register const char *cp
;
347 printf("\n\t Vendor-rfc1048:");
349 /* Step over magic cookie */
350 bp
+= sizeof(int32_t);
352 /* Loop while we there is a tag left in the buffer */
353 while (bp
+ 1 < snapend
) {
359 if (tag
== TAG_EXTENDED_OPTION
) {
360 TCHECK2(*(bp
+ 1), 2);
361 tag
= EXTRACT_16BITS(bp
+ 1);
362 /* XXX we don't know yet if the IANA will
363 * preclude overlap of 1-byte and 2-byte spaces.
364 * If not, we need to offset tag after this step.
366 cp
= tok2str(xtag2str
, "?xT%u", tag
);
368 cp
= tok2str(tag2str
, "?T%u", tag
);
370 printf("\n\t %s:", cp
);
372 /* Get the length; check for truncation */
373 if (bp
+ 1 >= snapend
) {
378 if (bp
+ len
>= snapend
) {
383 if (tag
== TAG_DHCP_MESSAGE
&& len
== 1) {
386 case DHCPDISCOVER
: printf("DISCOVER"); break;
387 case DHCPOFFER
: printf("OFFER"); break;
388 case DHCPREQUEST
: printf("REQUEST"); break;
389 case DHCPDECLINE
: printf("DECLINE"); break;
390 case DHCPACK
: printf("ACK"); break;
391 case DHCPNAK
: printf("NACK"); break;
392 case DHCPRELEASE
: printf("RELEASE"); break;
393 case DHCPINFORM
: printf("INFORM"); break;
394 default: printf("%u", uc
); break;
399 if (tag
== TAG_PARM_REQUEST
) {
403 cp
= tok2str(tag2str
, "?T%u", uc
);
406 printf("%s", cp
+ 1);
411 if (tag
== TAG_EXTENDED_REQUEST
) {
415 us
= EXTRACT_16BITS(bp
);
417 cp
= tok2str(xtag2str
, "?xT%u", us
);
420 printf("%s", cp
+ 1);
429 /* Base default formats for unknown tags on data size */
443 (void)fn_printn(bp
, size
, NULL
);
452 /* ip addresses/32-bit words */
453 while (size
>= sizeof(ul
)) {
456 ul
= EXTRACT_32BITS(bp
);
459 printf("%s", ipaddr_string(&ul
));
471 /* IP address pairs */
472 while (size
>= 2*sizeof(ul
)) {
475 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
476 printf("(%s:", ipaddr_string(&ul
));
478 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
479 printf("%s)", ipaddr_string(&ul
));
481 size
-= 2*sizeof(ul
);
488 while (size
>= sizeof(us
)) {
491 us
= EXTRACT_16BITS(bp
);
527 putchar(c
== 'x' ? ':' : '.');
539 /* Guys we can't handle with one of the usual cases */
542 case TAG_NETBIOS_NODE
:
545 fputs(tok2str(nbo2str
, NULL
, tag
), stdout
);
548 case TAG_OPT_OVERLOAD
:
551 fputs(tok2str(oo2str
, NULL
, tag
), stdout
);
554 case TAG_CLIENT_FQDN
:
558 printf("%u/%u/", *bp
, *(bp
+1));
561 (void)fn_printn(bp
, size
- 3, NULL
);
572 (void)fn_printn(bp
, size
, NULL
);
576 printf("[%s]", tok2str(arp2str
, "type-%d", type
));
590 printf("[unknown special tag %u, size %u]",
598 /* Data left over? */
600 printf("[len %u]", len
);
604 printf("|[rfc1048]");
608 cmu_print(register const u_char
*bp
)
610 register const struct cmu_vend
*cmu
;
612 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
613 if (cmu->m.s_addr != 0) \
614 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
617 cmu
= (const struct cmu_vend
*)bp
;
619 /* Only print if there are unknown bits */
620 TCHECK(cmu
->v_flags
);
621 if ((cmu
->v_flags
& ~(VF_SMASK
)) != 0)
622 printf(" F:0x%x", cmu
->v_flags
);
623 PRINTCMUADDR(v_dgate
, "DG");
624 PRINTCMUADDR(v_smask
, cmu
->v_flags
& VF_SMASK
? "SM" : "SM*");
625 PRINTCMUADDR(v_dns1
, "NS1");
626 PRINTCMUADDR(v_dns2
, "NS2");
627 PRINTCMUADDR(v_ins1
, "IEN1");
628 PRINTCMUADDR(v_ins2
, "IEN2");
629 PRINTCMUADDR(v_ts1
, "TS1");
630 PRINTCMUADDR(v_ts2
, "TS2");