]>
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.64 2002-08-01 08:53:02 risso Exp $ (LBL)";
32 #include <tcpdump-stdinc.h>
38 #include "interface.h"
39 #include "addrtoname.h"
44 static void rfc1048_print(const u_char
*);
45 static void cmu_print(const u_char
*);
47 static char tstr
[] = " [|bootp]";
50 * Print bootp requests
53 bootp_print(register const u_char
*cp
, u_int length
,
54 u_short sport
, u_short dport
)
56 register const struct bootp
*bp
;
57 static const u_char vm_cmu
[4] = VM_CMU
;
58 static const u_char vm_rfc1048
[4] = VM_RFC1048
;
60 bp
= (const struct bootp
*)cp
;
65 /* Usually, a request goes from a client to a server */
66 if (sport
!= IPPORT_BOOTPC
|| dport
!= IPPORT_BOOTPS
)
71 /* Usually, a reply goes from a server to a client */
72 if (sport
!= IPPORT_BOOTPS
|| dport
!= IPPORT_BOOTPC
)
77 printf(" bootp-#%d", bp
->bp_op
);
82 /* The usual hardware address type is 1 (10Mb Ethernet) */
83 if (bp
->bp_htype
!= 1)
84 printf(" htype-#%d", bp
->bp_htype
);
86 /* The usual length for 10Mb Ethernet address is 6 bytes */
87 if (bp
->bp_htype
!= 1 || bp
->bp_hlen
!= 6)
88 printf(" hlen:%d", bp
->bp_hlen
);
90 /* Only print interesting fields */
92 printf(" hops:%d", bp
->bp_hops
);
94 printf(" xid:0x%x", (u_int32_t
)ntohl(bp
->bp_xid
));
96 printf(" secs:%d", ntohs(bp
->bp_secs
));
98 printf(" flags:0x%x", ntohs(bp
->bp_flags
));
100 /* Client's ip address */
101 TCHECK(bp
->bp_ciaddr
);
102 if (bp
->bp_ciaddr
.s_addr
)
103 printf(" C:%s", ipaddr_string(&bp
->bp_ciaddr
));
105 /* 'your' ip address (bootp client) */
106 TCHECK(bp
->bp_yiaddr
);
107 if (bp
->bp_yiaddr
.s_addr
)
108 printf(" Y:%s", ipaddr_string(&bp
->bp_yiaddr
));
110 /* Server's ip address */
111 TCHECK(bp
->bp_siaddr
);
112 if (bp
->bp_siaddr
.s_addr
)
113 printf(" S:%s", ipaddr_string(&bp
->bp_siaddr
));
115 /* Gateway's ip address */
116 TCHECK(bp
->bp_giaddr
);
117 if (bp
->bp_giaddr
.s_addr
)
118 printf(" G:%s", ipaddr_string(&bp
->bp_giaddr
));
120 /* Client's Ethernet address */
121 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6) {
122 register const struct ether_header
*eh
;
123 register const char *e
;
125 TCHECK2(bp
->bp_chaddr
[0], 6);
126 eh
= (const struct ether_header
*)packetp
;
127 if (bp
->bp_op
== BOOTREQUEST
)
128 e
= (const char *)ESRC(eh
);
129 else if (bp
->bp_op
== BOOTREPLY
)
130 e
= (const char *)EDST(eh
);
133 if (e
== 0 || memcmp((const char *)bp
->bp_chaddr
, e
, 6) != 0)
134 printf(" ether %s", etheraddr_string(bp
->bp_chaddr
));
137 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
140 if (fn_print(bp
->bp_sname
, snapend
)) {
142 fputs(tstr
+ 1, stdout
);
147 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
150 if (fn_print(bp
->bp_file
, snapend
)) {
152 fputs(tstr
+ 1, stdout
);
158 /* Decode the vendor buffer */
159 TCHECK(bp
->bp_vend
[0]);
160 if (memcmp((const char *)bp
->bp_vend
, vm_rfc1048
,
161 sizeof(u_int32_t
)) == 0)
162 rfc1048_print(bp
->bp_vend
);
163 else if (memcmp((const char *)bp
->bp_vend
, vm_cmu
,
164 sizeof(u_int32_t
)) == 0)
165 cmu_print(bp
->bp_vend
);
169 ul
= EXTRACT_32BITS(&bp
->bp_vend
);
171 printf("vend-#0x%x", ul
);
180 * The first character specifies the format to print:
181 * i - ip address (32 bits)
182 * p - ip address pairs (32 bits + 32 bits)
184 * L - unsigned long (32 bits)
185 * s - short (16 bits)
186 * b - period-seperated decimal bytes (variable length)
187 * x - colon-seperated hex bytes (variable length)
188 * a - ascii string (variable length)
189 * B - on/off (8 bits)
190 * $ - special (explicit code to handle)
192 static struct tok tag2str
[] = {
195 { TAG_SUBNET_MASK
, "iSM" }, /* subnet mask (RFC950) */
196 { TAG_TIME_OFFSET
, "LTZ" }, /* seconds from UTC */
197 { TAG_GATEWAY
, "iDG" }, /* default gateway */
198 { TAG_TIME_SERVER
, "iTS" }, /* time servers (RFC868) */
199 { TAG_NAME_SERVER
, "iIEN" }, /* IEN name servers (IEN116) */
200 { TAG_DOMAIN_SERVER
, "iNS" }, /* domain name (RFC1035) */
201 { TAG_LOG_SERVER
, "iLOG" }, /* MIT log servers */
202 { TAG_COOKIE_SERVER
, "iCS" }, /* cookie servers (RFC865) */
203 { TAG_LPR_SERVER
, "iLPR" }, /* lpr server (RFC1179) */
204 { TAG_IMPRESS_SERVER
, "iIM" }, /* impress servers (Imagen) */
205 { TAG_RLP_SERVER
, "iRL" }, /* resource location (RFC887) */
206 { TAG_HOSTNAME
, "aHN" }, /* ascii hostname */
207 { TAG_BOOTSIZE
, "sBS" }, /* 512 byte blocks */
210 { TAG_DUMPPATH
, "aDP" },
211 { TAG_DOMAINNAME
, "aDN" },
212 { TAG_SWAP_SERVER
, "iSS" },
213 { TAG_ROOTPATH
, "aRP" },
214 { TAG_EXTPATH
, "aEP" },
216 { TAG_IP_FORWARD
, "BIPF" },
217 { TAG_NL_SRCRT
, "BSRT" },
218 { TAG_PFILTERS
, "pPF" },
219 { TAG_REASS_SIZE
, "sRSZ" },
220 { TAG_DEF_TTL
, "bTTL" },
221 { TAG_MTU_TIMEOUT
, "lMA" },
222 { TAG_MTU_TABLE
, "sMT" },
223 { TAG_INT_MTU
, "sMTU" },
224 { TAG_LOCAL_SUBNETS
, "BLSN" },
225 { TAG_BROAD_ADDR
, "iBR" },
226 { TAG_DO_MASK_DISC
, "BMD" },
227 { TAG_SUPPLY_MASK
, "BMS" },
228 { TAG_DO_RDISC
, "BRD" },
229 { TAG_RTR_SOL_ADDR
, "iRSA" },
230 { TAG_STATIC_ROUTE
, "pSR" },
231 { TAG_USE_TRAILERS
, "BUT" },
232 { TAG_ARP_TIMEOUT
, "lAT" },
233 { TAG_ETH_ENCAP
, "BIE" },
234 { TAG_TCP_TTL
, "bTT" },
235 { TAG_TCP_KEEPALIVE
, "lKI" },
236 { TAG_KEEPALIVE_GO
, "BKG" },
237 { TAG_NIS_DOMAIN
, "aYD" },
238 { TAG_NIS_SERVERS
, "iYS" },
239 { TAG_NTP_SERVERS
, "iNTP" },
240 { TAG_VENDOR_OPTS
, "bVO" },
241 { TAG_NETBIOS_NS
, "iWNS" },
242 { TAG_NETBIOS_DDS
, "iWDD" },
243 { TAG_NETBIOS_NODE
, "$WNT" },
244 { TAG_NETBIOS_SCOPE
, "aWSC" },
245 { TAG_XWIN_FS
, "iXFS" },
246 { TAG_XWIN_DM
, "iXDM" },
247 { TAG_NIS_P_DOMAIN
, "sN+D" },
248 { TAG_NIS_P_SERVERS
, "iN+S" },
249 { TAG_MOBILE_HOME
, "iMH" },
250 { TAG_SMPT_SERVER
, "iSMTP" },
251 { TAG_POP3_SERVER
, "iPOP3" },
252 { TAG_NNTP_SERVER
, "iNNTP" },
253 { TAG_WWW_SERVER
, "iWWW" },
254 { TAG_FINGER_SERVER
, "iFG" },
255 { TAG_IRC_SERVER
, "iIRC" },
256 { TAG_STREETTALK_SRVR
, "iSTS" },
257 { TAG_STREETTALK_STDA
, "iSTDA" },
258 { TAG_REQUESTED_IP
, "iRQ" },
259 { TAG_IP_LEASE
, "lLT" },
260 { TAG_OPT_OVERLOAD
, "$OO" },
261 { TAG_TFTP_SERVER
, "aTFTP" },
262 { TAG_BOOTFILENAME
, "aBF" },
263 { TAG_DHCP_MESSAGE
, " DHCP" },
264 { TAG_SERVER_ID
, "iSID" },
265 { TAG_PARM_REQUEST
, "bPR" },
266 { TAG_MESSAGE
, "aMSG" },
267 { TAG_MAX_MSG_SIZE
, "sMSZ" },
268 { TAG_RENEWAL_TIME
, "lRN" },
269 { TAG_REBIND_TIME
, "lRB" },
270 { TAG_VENDOR_CLASS
, "aVC" },
271 { TAG_CLIENT_ID
, "$CID" },
273 { TAG_OPEN_GROUP_UAP
, "aUAP" },
275 { TAG_DISABLE_AUTOCONF
, "BNOAUTO" },
277 { TAG_SLP_DA
, "bSLP-DA" }, /*"b" is a little wrong */
278 { TAG_SLP_SCOPE
, "bSLP-SCOPE" }, /*"b" is a little wrong */
280 { TAG_NS_SEARCH
, "sNSSEARCH" }, /* XXX 's' */
282 { TAG_IP4_SUBNET_SELECT
, "iSUBNET" },
283 /* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */
284 { TAG_USER_CLASS
, "aCLASS" },
285 { TAG_SLP_NAMING_AUTH
, "aSLP-NA" },
286 { TAG_CLIENT_FQDN
, "$FQDN" },
287 { TAG_AGENT_CIRCUIT
, "bACKT" },
288 { TAG_AGENT_REMOTE
, "bARMT" },
289 { TAG_AGENT_MASK
, "bAMSK" },
290 { TAG_TZ_STRING
, "aTZSTR" },
291 { TAG_FQDN_OPTION
, "bFQDNS" }, /* XXX 'b' */
292 { TAG_AUTH
, "bAUTH" }, /* XXX 'b' */
293 { TAG_VINES_SERVERS
, "iVINES" },
294 { TAG_SERVER_RANK
, "sRANK" },
295 { TAG_CLIENT_ARCH
, "sARCH" },
296 { TAG_CLIENT_NDI
, "bNDI" }, /* XXX 'b' */
297 { TAG_CLIENT_GUID
, "bGUID" }, /* XXX 'b' */
298 { TAG_LDAP_URL
, "aLDAP" },
299 { TAG_6OVER4
, "i6o4" },
300 { TAG_PRINTER_NAME
, "aPRTR" },
301 { TAG_MDHCP_SERVER
, "bMDHCP" }, /* XXX 'b' */
302 { TAG_IPX_COMPAT
, "bIPX" }, /* XXX 'b' */
303 { TAG_NETINFO_PARENT
, "iNI" },
304 { TAG_NETINFO_PARENT_TAG
, "aNITAG" },
306 { TAG_FAILOVER
, "bFAIL" }, /* XXX 'b' */
309 /* 2-byte extended tags */
310 static struct tok xtag2str
[] = {
314 /* DHCP "options overload" types */
315 static struct tok oo2str
[] = {
322 /* NETBIOS over TCP/IP node type options */
323 static struct tok nbo2str
[] = {
331 /* ARP Hardware types, for Client-ID option */
332 static struct tok arp2str
[] = {
338 { 0x18, "ieee1394" },
343 rfc1048_print(register const u_char
*bp
)
345 register u_int16_t tag
;
346 register u_int len
, size
;
347 register const char *cp
;
354 printf(" vend-rfc1048");
356 /* Step over magic cookie */
357 bp
+= sizeof(int32_t);
359 /* Loop while we there is a tag left in the buffer */
360 while (bp
+ 1 < snapend
) {
366 if (tag
== TAG_EXTENDED_OPTION
) {
367 TCHECK2(*(bp
+ 1), 2);
368 tag
= EXTRACT_16BITS(bp
+ 1);
369 /* XXX we don't know yet if the IANA will
370 * preclude overlap of 1-byte and 2-byte spaces.
371 * If not, we need to offset tag after this step.
373 cp
= tok2str(xtag2str
, "?xT%u", tag
);
375 cp
= tok2str(tag2str
, "?T%u", tag
);
379 /* Get the length; check for truncation */
380 if (bp
+ 1 >= snapend
) {
385 if (bp
+ len
>= snapend
) {
390 if (tag
== TAG_DHCP_MESSAGE
&& len
== 1) {
393 case DHCPDISCOVER
: printf("DISCOVER"); break;
394 case DHCPOFFER
: printf("OFFER"); break;
395 case DHCPREQUEST
: printf("REQUEST"); break;
396 case DHCPDECLINE
: printf("DECLINE"); break;
397 case DHCPACK
: printf("ACK"); break;
398 case DHCPNAK
: printf("NACK"); break;
399 case DHCPRELEASE
: printf("RELEASE"); break;
400 case DHCPINFORM
: printf("INFORM"); break;
401 default: printf("%u", uc
); break;
406 if (tag
== TAG_PARM_REQUEST
) {
410 cp
= tok2str(tag2str
, "?T%u", uc
);
413 printf("%s", cp
+ 1);
418 if (tag
== TAG_EXTENDED_REQUEST
) {
422 us
= EXTRACT_16BITS(bp
);
424 cp
= tok2str(xtag2str
, "?xT%u", us
);
427 printf("%s", cp
+ 1);
436 /* Base default formats for unknown tags on data size */
450 (void)fn_printn(bp
, size
, NULL
);
459 /* ip addresses/32-bit words */
460 while (size
>= sizeof(ul
)) {
463 ul
= EXTRACT_32BITS(bp
);
466 printf("%s", ipaddr_string(&ul
));
478 /* IP address pairs */
479 while (size
>= 2*sizeof(ul
)) {
482 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
483 printf("(%s:", ipaddr_string(&ul
));
485 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
486 printf("%s)", ipaddr_string(&ul
));
488 size
-= 2*sizeof(ul
);
495 while (size
>= sizeof(us
)) {
498 us
= EXTRACT_16BITS(bp
);
534 putchar(c
== 'x' ? ':' : '.');
546 /* Guys we can't handle with one of the usual cases */
549 case TAG_NETBIOS_NODE
:
552 fputs(tok2str(nbo2str
, NULL
, tag
), stdout
);
555 case TAG_OPT_OVERLOAD
:
558 fputs(tok2str(oo2str
, NULL
, tag
), stdout
);
561 case TAG_CLIENT_FQDN
:
565 printf("%u/%u/", *bp
, *(bp
+1));
568 (void)fn_printn(bp
, size
- 3, NULL
);
579 (void)fn_printn(bp
, size
, NULL
);
583 printf("[%s]", tok2str(arp2str
, "type-%d", type
));
597 printf("[unknown special tag %u, size %u]",
605 /* Data left over? */
607 printf("[len %u]", len
);
611 printf("|[rfc1048]");
615 cmu_print(register const u_char
*bp
)
617 register const struct cmu_vend
*cmu
;
619 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
620 if (cmu->m.s_addr != 0) \
621 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
624 cmu
= (const struct cmu_vend
*)bp
;
626 /* Only print if there are unknown bits */
627 TCHECK(cmu
->v_flags
);
628 if ((cmu
->v_flags
& ~(VF_SMASK
)) != 0)
629 printf(" F:0x%x", cmu
->v_flags
);
630 PRINTCMUADDR(v_dgate
, "DG");
631 PRINTCMUADDR(v_smask
, cmu
->v_flags
& VF_SMASK
? "SM" : "SM*");
632 PRINTCMUADDR(v_dns1
, "NS1");
633 PRINTCMUADDR(v_dns2
, "NS2");
634 PRINTCMUADDR(v_ins1
, "IEN1");
635 PRINTCMUADDR(v_ins2
, "IEN2");
636 PRINTCMUADDR(v_ts1
, "TS1");
637 PRINTCMUADDR(v_ts2
, "TS2");