]>
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.47 1999-10-17 23:35:47 mcr Exp $ (LBL)";
28 #include <sys/param.h>
30 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <netinet/if_ether.h>
48 #include "interface.h"
49 #include "addrtoname.h"
52 static void rfc1048_print(const u_char
*, u_int
);
53 static void cmu_print(const u_char
*, u_int
);
55 static char tstr
[] = " [|bootp]";
58 * Print bootp requests
61 bootp_print(register const u_char
*cp
, u_int length
,
62 u_short sport
, u_short dport
)
64 register const struct bootp
*bp
;
65 static u_char vm_cmu
[4] = VM_CMU
;
66 static u_char vm_rfc1048
[4] = VM_RFC1048
;
68 bp
= (struct bootp
*)cp
;
73 /* Usually, a request goes from a client to a server */
74 if (sport
!= IPPORT_BOOTPC
|| dport
!= IPPORT_BOOTPS
)
79 /* Usually, a reply goes from a server to a client */
80 if (sport
!= IPPORT_BOOTPS
|| dport
!= IPPORT_BOOTPC
)
85 printf(" bootp-#%d", bp
->bp_op
);
90 /* The usual hardware address type is 1 (10Mb Ethernet) */
91 if (bp
->bp_htype
!= 1)
92 printf(" htype-#%d", bp
->bp_htype
);
94 /* The usual length for 10Mb Ethernet address is 6 bytes */
95 if (bp
->bp_htype
!= 1 || bp
->bp_hlen
!= 6)
96 printf(" hlen:%d", bp
->bp_hlen
);
98 /* Only print interesting fields */
100 printf(" hops:%d", bp
->bp_hops
);
102 printf(" xid:0x%x", (u_int32_t
)ntohl(bp
->bp_xid
));
104 printf(" secs:%d", ntohs(bp
->bp_secs
));
106 printf(" flags:0x%x", ntohs(bp
->bp_flags
));
108 /* Client's ip address */
109 TCHECK(bp
->bp_ciaddr
);
110 if (bp
->bp_ciaddr
.s_addr
)
111 printf(" C:%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(" Y:%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(" S:%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(" G:%s", ipaddr_string(&bp
->bp_giaddr
));
128 /* Client's Ethernet address */
129 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6) {
130 register const struct ether_header
*eh
;
131 register const char *e
;
133 TCHECK2(bp
->bp_chaddr
[0], 6);
134 eh
= (struct ether_header
*)packetp
;
135 if (bp
->bp_op
== BOOTREQUEST
)
136 e
= (const char *)ESRC(eh
);
137 else if (bp
->bp_op
== BOOTREPLY
)
138 e
= (const char *)EDST(eh
);
141 if (e
== 0 || memcmp((char *)bp
->bp_chaddr
, e
, 6) != 0)
142 printf(" ether %s", etheraddr_string(bp
->bp_chaddr
));
145 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
148 if (fn_print(bp
->bp_sname
, snapend
)) {
150 fputs(tstr
+ 1, stdout
);
155 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
158 if (fn_print(bp
->bp_file
, snapend
)) {
160 fputs(tstr
+ 1, stdout
);
166 /* Decode the vendor buffer */
167 TCHECK(bp
->bp_vend
[0]);
168 length
-= sizeof(*bp
) - sizeof(bp
->bp_vend
);
169 if (memcmp((char *)bp
->bp_vend
, (char *)vm_rfc1048
,
170 sizeof(u_int32_t
)) == 0)
171 rfc1048_print(bp
->bp_vend
, length
);
172 else if (memcmp((char *)bp
->bp_vend
, (char *)vm_cmu
,
173 sizeof(u_int32_t
)) == 0)
174 cmu_print(bp
->bp_vend
, length
);
178 memcpy((char *)&ul
, (char *)bp
->bp_vend
, sizeof(ul
));
180 printf("vend-#0x%x", ul
);
188 /* The first character specifies the format to print */
189 static struct tok tag2str
[] = {
192 { TAG_SUBNET_MASK
, "iSM" }, /* subnet mask (RFC950) */
193 { TAG_TIME_OFFSET
, "lTZ" }, /* seconds from UTC */
194 { TAG_GATEWAY
, "iDG" }, /* default gateway */
195 { TAG_TIME_SERVER
, "iTS" }, /* time servers (RFC868) */
196 { TAG_NAME_SERVER
, "iIEN" }, /* IEN name servers (IEN116) */
197 { TAG_DOMAIN_SERVER
, "iNS" }, /* domain name (RFC1035) */
198 { TAG_LOG_SERVER
, "iLOG" }, /* MIT log servers */
199 { TAG_COOKIE_SERVER
, "iCS" }, /* cookie servers (RFC865) */
200 { TAG_LPR_SERVER
, "iLPR" }, /* lpr server (RFC1179) */
201 { TAG_IMPRESS_SERVER
, "iIM" }, /* impress servers (Imagen) */
202 { TAG_RLP_SERVER
, "iRL" }, /* resource location (RFC887) */
203 { TAG_HOSTNAME
, "aHN" }, /* ascii hostname */
204 { TAG_BOOTSIZE
, "sBS" }, /* 512 byte blocks */
207 { TAG_DUMPPATH
, "aDP" },
208 { TAG_DOMAINNAME
, "aDN" },
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
, "lMA" },
219 { TAG_MTU_TABLE
, "sMT" },
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
, "BRD" },
226 { TAG_RTR_SOL_ADDR
, "iRSA" },
227 { TAG_STATIC_ROUTE
, "pSR" },
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
, "bVO" },
238 { TAG_NETBIOS_NS
, "iWNS" },
239 { TAG_NETBIOS_DDS
, "iWDD" },
240 { TAG_NETBIOS_NODE
, "bWNT" },
241 { TAG_NETBIOS_SCOPE
, "aWSC" },
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
, "iRQ" },
256 { TAG_IP_LEASE
, "lLT" },
257 { TAG_OPT_OVERLOAD
, "bOO" },
258 { TAG_TFTP_SERVER
, "aTFTP" },
259 { TAG_BOOTFILENAME
, "aBF" },
260 { TAG_DHCP_MESSAGE
, " DHCP" },
261 { TAG_SERVER_ID
, "iSID" },
262 { TAG_PARM_REQUEST
, "bPR" },
263 { TAG_MESSAGE
, "aMSG" },
264 { TAG_MAX_MSG_SIZE
, "sMSZ" },
265 { TAG_RENEWAL_TIME
, "lRN" },
266 { TAG_REBIND_TIME
, "lRB" },
267 { TAG_VENDOR_CLASS
, "bVC" },
268 { TAG_CLIENT_ID
, "bCID" },
273 rfc1048_print(register const u_char
*bp
, register u_int length
)
276 register u_int len
, size
;
277 register const char *cp
;
283 printf(" vend-rfc1048");
285 /* Step over magic cookie */
286 bp
+= sizeof(int32_t);
288 /* Loop while we there is a tag left in the buffer */
289 while (bp
+ 1 < snapend
) {
295 cp
= tok2str(tag2str
, "?T%d", tag
);
299 /* Get the length; check for truncation */
300 if (bp
+ 1 >= snapend
) {
305 if (bp
+ len
>= snapend
) {
310 if (tag
== TAG_DHCP_MESSAGE
&& len
== 1) {
313 case DHCPDISCOVER
: printf("DISCOVER"); break;
314 case DHCPOFFER
: printf("OFFER"); break;
315 case DHCPREQUEST
: printf("REQUEST"); break;
316 case DHCPDECLINE
: printf("DECLINE"); break;
317 case DHCPACK
: printf("ACK"); break;
318 case DHCPNAK
: printf("NACK"); break;
319 case DHCPRELEASE
: printf("RELEASE"); break;
320 case DHCPINFORM
: printf("INFORM"); break;
321 default: printf("%u", c
); break;
326 if (tag
== TAG_PARM_REQUEST
) {
330 cp
= tok2str(tag2str
, "?%d", c
);
333 printf("%s", cp
+ 1);
342 /* Base default formats for unknown tags on data size */
356 (void)fn_printn(bp
, size
, NULL
);
364 /* ip addresses/32-bit words */
365 while (size
>= sizeof(ul
)) {
368 memcpy((char *)&ul
, (char *)bp
, sizeof(ul
));
370 printf("%s", ipaddr_string(&ul
));
380 /* IP address pairs */
381 while (size
>= 2*sizeof(ul
)) {
384 memcpy((char *)&ul
, (char *)bp
, sizeof(ul
));
385 printf("(%s:", ipaddr_string(&ul
));
387 memcpy((char *)&ul
, (char *)bp
, sizeof(ul
));
388 printf("%s)", ipaddr_string(&ul
));
390 size
-= 2*sizeof(ul
);
397 while (size
>= sizeof(us
)) {
400 memcpy((char *)&us
, (char *)bp
, sizeof(us
));
443 /* Data left over? */
445 printf("[len %d]", len
);
450 cmu_print(register const u_char
*bp
, register u_int length
)
452 register const struct cmu_vend
*cmu
;
453 char *fmt
= " %s:%s";
455 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
456 if (cmu->m.s_addr != 0) \
457 printf(fmt, s, ipaddr_string(&cmu->m.s_addr)); }
460 cmu
= (struct cmu_vend
*)bp
;
462 /* Only print if there are unknown bits */
463 TCHECK(cmu
->v_flags
);
464 if ((cmu
->v_flags
& ~(VF_SMASK
)) != 0)
465 printf(" F:0x%x", cmu
->v_flags
);
466 PRINTCMUADDR(v_dgate
, "DG");
467 PRINTCMUADDR(v_smask
, cmu
->v_flags
& VF_SMASK
? "SM" : "SM*");
468 PRINTCMUADDR(v_dns1
, "NS1");
469 PRINTCMUADDR(v_dns2
, "NS2");
470 PRINTCMUADDR(v_ins1
, "IEN1");
471 PRINTCMUADDR(v_ins2
, "IEN2");
472 PRINTCMUADDR(v_ts1
, "TS1");
473 PRINTCMUADDR(v_ts2
, "TS2");