]>
git.saurik.com Git - apple/network_cmds.git/blob - tcpdump.tproj/print-bootp.c
c93872852af2e189d2714875b5d7ca10a695b600
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that: (1) source code distributions
30 * retain the above copyright notice and this paragraph in its entirety, (2)
31 * distributions including binary code include the above copyright notice and
32 * this paragraph in its entirety in the documentation or other materials
33 * provided with the distribution, and (3) all advertising materials mentioning
34 * features or use of this software display the following acknowledgement:
35 * ``This product includes software developed by the University of California,
36 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
37 * the University nor the names of its contributors may be used to endorse
38 * or promote products derived from this software without specific prior
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
44 * Format and print bootp packets.
47 static const char rcsid
[] =
48 "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-bootp.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)";
51 #include <sys/param.h>
53 #include <sys/socket.h>
61 #include <netinet/in.h>
62 #include <netinet/if_ether.h>
68 #include "interface.h"
69 #include "addrtoname.h"
72 static void rfc1048_print(const u_char
*, u_int
);
73 static void cmu_print(const u_char
*, u_int
);
75 static char tstr
[] = " [|bootp]";
78 * Print bootp requests
81 bootp_print(register const u_char
*cp
, u_int length
,
82 u_short sport
, u_short dport
)
84 register const struct bootp
*bp
;
85 static u_char vm_cmu
[4] = VM_CMU
;
86 static u_char vm_rfc1048
[4] = VM_RFC1048
;
88 bp
= (struct bootp
*)cp
;
93 /* Usually, a request goes from a client to a server */
94 if (sport
!= IPPORT_BOOTPC
|| dport
!= IPPORT_BOOTPS
)
99 /* Usually, a reply goes from a server to a client */
100 if (sport
!= IPPORT_BOOTPS
|| dport
!= IPPORT_BOOTPC
)
105 printf(" bootp-#%d", bp
->bp_op
);
110 /* The usual hardware address type is 1 (10Mb Ethernet) */
111 if (bp
->bp_htype
!= 1)
112 printf(" htype-#%d", bp
->bp_htype
);
114 /* The usual length for 10Mb Ethernet address is 6 bytes */
115 if (bp
->bp_htype
!= 1 || bp
->bp_hlen
!= 6)
116 printf(" hlen:%d", bp
->bp_hlen
);
118 /* Only print interesting fields */
120 printf(" hops:%d", bp
->bp_hops
);
122 printf(" xid:0x%x", (u_int32_t
)ntohl(bp
->bp_xid
));
124 printf(" secs:%d", ntohs(bp
->bp_secs
));
126 /* Client's ip address */
127 TCHECK(bp
->bp_ciaddr
);
128 if (bp
->bp_ciaddr
.s_addr
)
129 printf(" C:%s", ipaddr_string(&bp
->bp_ciaddr
));
131 /* 'your' ip address (bootp client) */
132 TCHECK(bp
->bp_yiaddr
);
133 if (bp
->bp_yiaddr
.s_addr
)
134 printf(" Y:%s", ipaddr_string(&bp
->bp_yiaddr
));
136 /* Server's ip address */
137 TCHECK(bp
->bp_siaddr
);
138 if (bp
->bp_siaddr
.s_addr
)
139 printf(" S:%s", ipaddr_string(&bp
->bp_siaddr
));
141 /* Gateway's ip address */
142 TCHECK(bp
->bp_giaddr
);
143 if (bp
->bp_giaddr
.s_addr
)
144 printf(" G:%s", ipaddr_string(&bp
->bp_giaddr
));
146 /* Client's Ethernet address */
147 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6) {
148 register const struct ether_header
*eh
;
149 register const char *e
;
151 TCHECK2(bp
->bp_chaddr
[0], 6);
152 eh
= (struct ether_header
*)packetp
;
153 if (bp
->bp_op
== BOOTREQUEST
)
154 e
= (const char *)ESRC(eh
);
155 else if (bp
->bp_op
== BOOTREPLY
)
156 e
= (const char *)EDST(eh
);
159 if (e
== 0 || memcmp((char *)bp
->bp_chaddr
, e
, 6) != 0)
160 printf(" ether %s", etheraddr_string(bp
->bp_chaddr
));
163 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
166 if (fn_print(bp
->bp_sname
, snapend
)) {
168 fputs(tstr
+ 1, stdout
);
172 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
175 if (fn_print(bp
->bp_file
, snapend
)) {
177 fputs(tstr
+ 1, stdout
);
182 /* Decode the vendor buffer */
183 TCHECK(bp
->bp_vend
[0]);
184 length
-= sizeof(*bp
) - sizeof(bp
->bp_vend
);
185 if (memcmp((char *)bp
->bp_vend
, (char *)vm_rfc1048
,
186 sizeof(u_int32_t
)) == 0)
187 rfc1048_print(bp
->bp_vend
, length
);
188 else if (memcmp((char *)bp
->bp_vend
, (char *)vm_cmu
,
189 sizeof(u_int32_t
)) == 0)
190 cmu_print(bp
->bp_vend
, length
);
194 memcpy((char *)&ul
, (char *)bp
->bp_vend
, sizeof(ul
));
196 printf("vend-#0x%x", ul
);
204 /* The first character specifies the format to print */
205 static struct tok tag2str
[] = {
208 { TAG_SUBNET_MASK
, "iSM" }, /* subnet mask (RFC950) */
209 { TAG_TIME_OFFSET
, "lTZ" }, /* seconds from UTC */
210 { TAG_GATEWAY
, "iDG" }, /* default gateway */
211 { TAG_TIME_SERVER
, "iTS" }, /* time servers (RFC868) */
212 { TAG_NAME_SERVER
, "iIEN" }, /* IEN name servers (IEN116) */
213 { TAG_DOMAIN_SERVER
, "iNS" }, /* domain name (RFC1035) */
214 { TAG_LOG_SERVER
, "iLOG" }, /* MIT log servers */
215 { TAG_COOKIE_SERVER
, "iCS" }, /* cookie servers (RFC865) */
216 { TAG_LPR_SERVER
, "iLPR" }, /* lpr server (RFC1179) */
217 { TAG_IMPRESS_SERVER
, "iIM" }, /* impress servers (Imagen) */
218 { TAG_RLP_SERVER
, "iRL" }, /* resource location (RFC887) */
219 { TAG_HOSTNAME
, "aHN" }, /* ascii hostname */
220 { TAG_BOOTSIZE
, "sBS" }, /* 512 byte blocks */
223 { TAG_DUMPPATH
, "aDP" },
224 { TAG_DOMAINNAME
, "aDN" },
225 { TAG_SWAP_SERVER
, "iSS" },
226 { TAG_ROOTPATH
, "aRP" },
227 { TAG_EXTPATH
, "aEP" },
232 rfc1048_print(register const u_char
*bp
, register u_int length
)
235 register u_int len
, size
;
236 register const char *cp
;
242 printf(" vend-rfc1048");
244 /* Step over magic cookie */
245 bp
+= sizeof(int32_t);
247 /* Loop while we there is a tag left in the buffer */
248 while (bp
+ 1 < snapend
) {
254 cp
= tok2str(tag2str
, "?T%d", tag
);
258 /* Get the length; check for truncation */
259 if (bp
+ 1 >= snapend
) {
264 if (bp
+ len
>= snapend
) {
272 /* Base default formats for unknown tags on data size */
286 (void)fn_printn(bp
, size
, NULL
);
294 /* ip addresses/32-bit words */
295 while (size
>= sizeof(ul
)) {
298 memcpy((char *)&ul
, (char *)bp
, sizeof(ul
));
300 printf("%s", ipaddr_string(&ul
));
311 while (size
>= sizeof(us
)) {
314 memcpy((char *)&us
, (char *)bp
, sizeof(us
));
335 /* Data left over? */
337 printf("[len %d]", len
);
342 cmu_print(register const u_char
*bp
, register u_int length
)
344 register const struct cmu_vend
*cmu
;
345 char *fmt
= " %s:%s";
347 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
348 if (cmu->m.s_addr != 0) \
349 printf(fmt, s, ipaddr_string(&cmu->m.s_addr)); }
352 cmu
= (struct cmu_vend
*)bp
;
354 /* Only print if there are unknown bits */
355 TCHECK(cmu
->v_flags
);
356 if ((cmu
->v_flags
& ~(VF_SMASK
)) != 0)
357 printf(" F:0x%x", cmu
->v_flags
);
358 PRINTCMUADDR(v_dgate
, "DG");
359 PRINTCMUADDR(v_smask
, cmu
->v_flags
& VF_SMASK
? "SM" : "SM*");
360 PRINTCMUADDR(v_dns1
, "NS1");
361 PRINTCMUADDR(v_dns2
, "NS2");
362 PRINTCMUADDR(v_ins1
, "IEN1");
363 PRINTCMUADDR(v_ins2
, "IEN2");
364 PRINTCMUADDR(v_ts1
, "TS1");
365 PRINTCMUADDR(v_ts2
, "TS2");