print-bootp.c revision 1.5 1 1.1 gwr /*
2 1.1 gwr * Copyright (c) 1988-1990 The Regents of the University of California.
3 1.1 gwr * All rights reserved.
4 1.1 gwr *
5 1.1 gwr * Redistribution and use in source and binary forms, with or without
6 1.1 gwr * modification, are permitted provided that: (1) source code distributions
7 1.1 gwr * retain the above copyright notice and this paragraph in its entirety, (2)
8 1.1 gwr * distributions including binary code include the above copyright notice and
9 1.1 gwr * this paragraph in its entirety in the documentation or other materials
10 1.1 gwr * provided with the distribution, and (3) all advertising materials mentioning
11 1.1 gwr * features or use of this software display the following acknowledgement:
12 1.1 gwr * ``This product includes software developed by the University of California,
13 1.1 gwr * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 1.1 gwr * the University nor the names of its contributors may be used to endorse
15 1.1 gwr * or promote products derived from this software without specific prior
16 1.1 gwr * written permission.
17 1.1 gwr * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 1.1 gwr * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 1.1 gwr * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 1.1 gwr *
21 1.1 gwr * Format and print bootp packets.
22 1.1 gwr *
23 1.1 gwr * This file was copied from tcpdump-2.1.1 and modified.
24 1.1 gwr * There is an e-mail list for tcpdump: <tcpdump (at) ee.lbl.gov>
25 1.1 gwr */
26 1.4 lukem
27 1.4 lukem #include <sys/cdefs.h>
28 1.1 gwr #ifndef lint
29 1.5 thorpej __RCSID("$NetBSD: print-bootp.c,v 1.5 1998/03/26 06:44:19 thorpej Exp $");
30 1.2 gwr /* 93/10/10 <gwr (at) mc.com> New data-driven option print routine. */
31 1.1 gwr #endif
32 1.1 gwr
33 1.1 gwr #include <stdio.h>
34 1.1 gwr
35 1.1 gwr #include <sys/param.h>
36 1.1 gwr #include <sys/types.h>
37 1.1 gwr #include <sys/socket.h>
38 1.1 gwr #include <net/if.h>
39 1.1 gwr #include <netinet/in.h>
40 1.1 gwr #include <string.h>
41 1.1 gwr #include <ctype.h>
42 1.1 gwr
43 1.1 gwr #include "bootp.h"
44 1.1 gwr #include "bootptest.h"
45 1.1 gwr
46 1.4 lukem #ifdef __STDC__
47 1.4 lukem #define P(args) args
48 1.4 lukem #else
49 1.4 lukem #define P(args) ()
50 1.4 lukem #endif
51 1.4 lukem
52 1.1 gwr /* These decode the vendor data. */
53 1.4 lukem static void cmu_print P((u_char *, int));
54 1.4 lukem static void dump_hex P((u_char *, int));
55 1.4 lukem static void other_print P((u_char *, int));
56 1.4 lukem static void rfc1048_print P((u_char *, int));
57 1.4 lukem
58 1.4 lukem #undef P
59 1.1 gwr
60 1.1 gwr /*
61 1.1 gwr * Print bootp requests
62 1.1 gwr */
63 1.1 gwr void
64 1.1 gwr bootp_print(bp, length, sport, dport)
65 1.1 gwr struct bootp *bp;
66 1.1 gwr int length;
67 1.1 gwr u_short sport, dport;
68 1.1 gwr {
69 1.1 gwr static char tstr[] = " [|bootp]";
70 1.1 gwr static unsigned char vm_cmu[4] = VM_CMU;
71 1.1 gwr static unsigned char vm_rfc1048[4] = VM_RFC1048;
72 1.1 gwr u_char *ep;
73 1.1 gwr int vdlen;
74 1.1 gwr
75 1.1 gwr #define TCHECK(var, l) if ((u_char *)&(var) > ep - l) goto trunc
76 1.1 gwr
77 1.1 gwr /* Note funny sized packets */
78 1.1 gwr if (length != sizeof(struct bootp))
79 1.1 gwr (void) printf(" [len=%d]", length);
80 1.1 gwr
81 1.1 gwr /* 'ep' points to the end of avaible data. */
82 1.1 gwr ep = (u_char *) snapend;
83 1.1 gwr
84 1.1 gwr switch (bp->bp_op) {
85 1.1 gwr
86 1.1 gwr case BOOTREQUEST:
87 1.1 gwr /* Usually, a request goes from a client to a server */
88 1.1 gwr if (sport != IPPORT_BOOTPC || dport != IPPORT_BOOTPS)
89 1.1 gwr printf(" (request)");
90 1.1 gwr break;
91 1.1 gwr
92 1.1 gwr case BOOTREPLY:
93 1.1 gwr /* Usually, a reply goes from a server to a client */
94 1.1 gwr if (sport != IPPORT_BOOTPS || dport != IPPORT_BOOTPC)
95 1.1 gwr printf(" (reply)");
96 1.1 gwr break;
97 1.1 gwr
98 1.1 gwr default:
99 1.1 gwr printf(" bootp-#%d", bp->bp_op);
100 1.1 gwr }
101 1.1 gwr
102 1.1 gwr /* The usual hardware address type is 1 (10Mb Ethernet) */
103 1.1 gwr if (bp->bp_htype != 1)
104 1.1 gwr printf(" htype:%d", bp->bp_htype);
105 1.1 gwr
106 1.1 gwr /* The usual length for 10Mb Ethernet address is 6 bytes */
107 1.1 gwr if (bp->bp_hlen != 6)
108 1.1 gwr printf(" hlen:%d", bp->bp_hlen);
109 1.1 gwr
110 1.1 gwr /* Client's Hardware address */
111 1.1 gwr if (bp->bp_hlen) {
112 1.1 gwr register struct ether_header *eh;
113 1.1 gwr register char *e;
114 1.1 gwr
115 1.1 gwr TCHECK(bp->bp_chaddr[0], 6);
116 1.1 gwr eh = (struct ether_header *) packetp;
117 1.1 gwr if (bp->bp_op == BOOTREQUEST)
118 1.1 gwr e = (char *) ESRC(eh);
119 1.1 gwr else if (bp->bp_op == BOOTREPLY)
120 1.1 gwr e = (char *) EDST(eh);
121 1.1 gwr else
122 1.1 gwr e = 0;
123 1.1 gwr if (e == 0 || bcmp((char *) bp->bp_chaddr, e, 6))
124 1.1 gwr dump_hex(bp->bp_chaddr, bp->bp_hlen);
125 1.1 gwr }
126 1.1 gwr /* Only print interesting fields */
127 1.1 gwr if (bp->bp_hops)
128 1.1 gwr printf(" hops:%d", bp->bp_hops);
129 1.1 gwr
130 1.1 gwr if (bp->bp_xid)
131 1.1 gwr printf(" xid:%d", ntohl(bp->bp_xid));
132 1.1 gwr
133 1.1 gwr if (bp->bp_secs)
134 1.1 gwr printf(" secs:%d", ntohs(bp->bp_secs));
135 1.1 gwr
136 1.1 gwr /* Client's ip address */
137 1.1 gwr TCHECK(bp->bp_ciaddr, sizeof(bp->bp_ciaddr));
138 1.1 gwr if (bp->bp_ciaddr.s_addr)
139 1.1 gwr printf(" C:%s", ipaddr_string(&bp->bp_ciaddr));
140 1.1 gwr
141 1.1 gwr /* 'your' ip address (bootp client) */
142 1.1 gwr TCHECK(bp->bp_yiaddr, sizeof(bp->bp_yiaddr));
143 1.1 gwr if (bp->bp_yiaddr.s_addr)
144 1.1 gwr printf(" Y:%s", ipaddr_string(&bp->bp_yiaddr));
145 1.1 gwr
146 1.1 gwr /* Server's ip address */
147 1.1 gwr TCHECK(bp->bp_siaddr, sizeof(bp->bp_siaddr));
148 1.1 gwr if (bp->bp_siaddr.s_addr)
149 1.1 gwr printf(" S:%s", ipaddr_string(&bp->bp_siaddr));
150 1.1 gwr
151 1.1 gwr /* Gateway's ip address */
152 1.1 gwr TCHECK(bp->bp_giaddr, sizeof(bp->bp_giaddr));
153 1.1 gwr if (bp->bp_giaddr.s_addr)
154 1.1 gwr printf(" G:%s", ipaddr_string(&bp->bp_giaddr));
155 1.1 gwr
156 1.1 gwr TCHECK(bp->bp_sname[0], sizeof(bp->bp_sname));
157 1.1 gwr if (*bp->bp_sname) {
158 1.1 gwr printf(" sname:");
159 1.1 gwr if (printfn(bp->bp_sname, ep)) {
160 1.1 gwr fputs(tstr + 1, stdout);
161 1.1 gwr return;
162 1.1 gwr }
163 1.1 gwr }
164 1.1 gwr TCHECK(bp->bp_file[0], sizeof(bp->bp_file));
165 1.1 gwr if (*bp->bp_file) {
166 1.1 gwr printf(" file:");
167 1.1 gwr if (printfn(bp->bp_file, ep)) {
168 1.1 gwr fputs(tstr + 1, stdout);
169 1.1 gwr return;
170 1.1 gwr }
171 1.1 gwr }
172 1.1 gwr /* Don't try to decode the vendor buffer unless we're verbose */
173 1.1 gwr if (vflag <= 0)
174 1.1 gwr return;
175 1.1 gwr
176 1.1 gwr vdlen = sizeof(bp->bp_vend);
177 1.1 gwr /* Vendor data can extend to the end of the packet. */
178 1.1 gwr if (vdlen < (ep - bp->bp_vend))
179 1.1 gwr vdlen = (ep - bp->bp_vend);
180 1.1 gwr
181 1.1 gwr TCHECK(bp->bp_vend[0], vdlen);
182 1.1 gwr printf(" vend");
183 1.1 gwr if (!bcmp(bp->bp_vend, vm_rfc1048, sizeof(u_int32)))
184 1.1 gwr rfc1048_print(bp->bp_vend, vdlen);
185 1.1 gwr else if (!bcmp(bp->bp_vend, vm_cmu, sizeof(u_int32)))
186 1.1 gwr cmu_print(bp->bp_vend, vdlen);
187 1.1 gwr else
188 1.1 gwr other_print(bp->bp_vend, vdlen);
189 1.1 gwr
190 1.1 gwr return;
191 1.1 gwr trunc:
192 1.1 gwr fputs(tstr, stdout);
193 1.1 gwr #undef TCHECK
194 1.1 gwr }
195 1.1 gwr
196 1.1 gwr /*
198 1.1 gwr * Option description data follows.
199 1.1 gwr * These are decribed in: RFC-1048, RFC-1395, RFC-1497, RFC-1533
200 1.1 gwr *
201 1.1 gwr * The first char of each option string encodes the data format:
202 1.1 gwr * ?: unknown
203 1.1 gwr * a: ASCII
204 1.1 gwr * b: byte (8-bit)
205 1.1 gwr * i: inet address
206 1.1 gwr * l: int32
207 1.1 gwr * s: short (16-bit)
208 1.1 gwr */
209 1.1 gwr char *
210 1.1 gwr rfc1048_opts[] = {
211 1.1 gwr /* Originally from RFC-1048: */
212 1.1 gwr "?PAD", /* 0: Padding - special, no data. */
213 1.1 gwr "iSM", /* 1: subnet mask (RFC950)*/
214 1.1 gwr "lTZ", /* 2: time offset, seconds from UTC */
215 1.1 gwr "iGW", /* 3: gateways (or routers) */
216 1.1 gwr "iTS", /* 4: time servers (RFC868) */
217 1.1 gwr "iINS", /* 5: IEN name servers (IEN116) */
218 1.1 gwr "iDNS", /* 6: domain name servers (RFC1035)(1034?) */
219 1.1 gwr "iLOG", /* 7: MIT log servers */
220 1.1 gwr "iCS", /* 8: cookie servers (RFC865) */
221 1.1 gwr "iLPR", /* 9: lpr server (RFC1179) */
222 1.1 gwr "iIPS", /* 10: impress servers (Imagen) */
223 1.1 gwr "iRLP", /* 11: resource location servers (RFC887) */
224 1.1 gwr "aHN", /* 12: host name (ASCII) */
225 1.1 gwr "sBFS", /* 13: boot file size (in 512 byte blocks) */
226 1.1 gwr
227 1.1 gwr /* Added by RFC-1395: */
228 1.1 gwr "aDUMP", /* 14: Merit Dump File */
229 1.1 gwr "aDNAM", /* 15: Domain Name (for DNS) */
230 1.1 gwr "iSWAP", /* 16: Swap Server */
231 1.1 gwr "aROOT", /* 17: Root Path */
232 1.1 gwr
233 1.1 gwr /* Added by RFC-1497: */
234 1.1 gwr "aEXTF", /* 18: Extensions Path (more options) */
235 1.1 gwr
236 1.1 gwr /* Added by RFC-1533: (many, many options...) */
237 1.1 gwr #if 1 /* These might not be worth recognizing by name. */
238 1.1 gwr
239 1.1 gwr /* IP Layer Parameters, per-host (RFC-1533, sect. 4) */
240 1.1 gwr "bIP-forward", /* 19: IP Forwarding flag */
241 1.1 gwr "bIP-srcroute", /* 20: IP Source Routing Enable flag */
242 1.1 gwr "iIP-filters", /* 21: IP Policy Filter (addr pairs) */
243 1.1 gwr "sIP-maxudp", /* 22: IP Max-UDP reassembly size */
244 1.1 gwr "bIP-ttlive", /* 23: IP Time to Live */
245 1.1 gwr "lIP-pmtuage", /* 24: IP Path MTU aging timeout */
246 1.1 gwr "sIP-pmtutab", /* 25: IP Path MTU plateau table */
247 1.1 gwr
248 1.1 gwr /* IP parameters, per-interface (RFC-1533, sect. 5) */
249 1.1 gwr "sIP-mtu-sz", /* 26: IP MTU size */
250 1.1 gwr "bIP-mtu-sl", /* 27: IP MTU all subnets local */
251 1.1 gwr "bIP-bcast1", /* 28: IP Broadcast Addr ones flag */
252 1.1 gwr "bIP-mask-d", /* 29: IP do mask discovery */
253 1.1 gwr "bIP-mask-s", /* 30: IP do mask supplier */
254 1.1 gwr "bIP-rt-dsc", /* 31: IP do router discovery */
255 1.1 gwr "iIP-rt-sa", /* 32: IP router solicitation addr */
256 1.1 gwr "iIP-routes", /* 33: IP static routes (dst,router) */
257 1.1 gwr
258 1.1 gwr /* Link Layer parameters, per-interface (RFC-1533, sect. 6) */
259 1.1 gwr "bLL-trailer", /* 34: do tralier encapsulation */
260 1.1 gwr "lLL-arp-tmo", /* 35: ARP cache timeout */
261 1.1 gwr "bLL-ether2", /* 36: Ethernet version 2 (IEEE 802.3) */
262 1.1 gwr
263 1.1 gwr /* TCP parameters (RFC-1533, sect. 7) */
264 1.1 gwr "bTCP-def-ttl", /* 37: default time to live */
265 1.1 gwr "lTCP-KA-tmo", /* 38: keepalive time interval */
266 1.1 gwr "bTCP-KA-junk", /* 39: keepalive sends extra junk */
267 1.1 gwr
268 1.1 gwr /* Application and Service Parameters (RFC-1533, sect. 8) */
269 1.1 gwr "aNISDOM", /* 40: NIS Domain (Sun YP) */
270 1.1 gwr "iNISSRV", /* 41: NIS Servers */
271 1.1 gwr "iNTPSRV", /* 42: NTP (time) Servers (RFC 1129) */
272 1.1 gwr "?VSINFO", /* 43: Vendor Specific Info (encapsulated) */
273 1.1 gwr "iNBiosNS", /* 44: NetBIOS Name Server (RFC-1001,1..2) */
274 1.1 gwr "iNBiosDD", /* 45: NetBIOS Datagram Dist. Server. */
275 1.1 gwr "bNBiosNT", /* 46: NetBIOS Note Type */
276 1.1 gwr "?NBiosS", /* 47: NetBIOS Scope */
277 1.1 gwr "iXW-FS", /* 48: X Window System Font Servers */
278 1.1 gwr "iXW-DM", /* 49: X Window System Display Managers */
279 1.1 gwr
280 1.1 gwr /* DHCP extensions (RFC-1533, sect. 9) */
281 1.1 gwr #endif
282 1.1 gwr };
283 1.1 gwr #define KNOWN_OPTIONS (sizeof(rfc1048_opts) / sizeof(rfc1048_opts[0]))
284 1.1 gwr
285 1.1 gwr static void
286 1.1 gwr rfc1048_print(bp, length)
287 1.1 gwr register u_char *bp;
288 1.1 gwr int length;
289 1.1 gwr {
290 1.1 gwr u_char tag;
291 1.4 lukem u_char *ep;
292 1.1 gwr register int len;
293 1.1 gwr u_int32 ul;
294 1.1 gwr u_short us;
295 1.1 gwr struct in_addr ia;
296 1.1 gwr char *optstr;
297 1.1 gwr
298 1.1 gwr printf("-rfc1395");
299 1.1 gwr
300 1.1 gwr /* Step over magic cookie */
301 1.1 gwr bp += sizeof(int32);
302 1.1 gwr /* Setup end pointer */
303 1.1 gwr ep = bp + length;
304 1.1 gwr while (bp < ep) {
305 1.1 gwr tag = *bp++;
306 1.1 gwr /* Check for tags with no data first. */
307 1.1 gwr if (tag == TAG_PAD)
308 1.1 gwr continue;
309 1.1 gwr if (tag == TAG_END)
310 1.1 gwr return;
311 1.1 gwr if (tag < KNOWN_OPTIONS) {
312 1.1 gwr optstr = rfc1048_opts[tag];
313 1.1 gwr printf(" %s:", optstr + 1);
314 1.1 gwr } else {
315 1.1 gwr printf(" T%d:", tag);
316 1.1 gwr optstr = "?";
317 1.1 gwr }
318 1.1 gwr /* Now scan the length byte. */
319 1.1 gwr len = *bp++;
320 1.1 gwr if (bp + len > ep) {
321 1.5 thorpej /* truncated option */
322 1.1 gwr printf(" |(%d>%ld)", len, (long)(ep - bp));
323 1.1 gwr return;
324 1.1 gwr }
325 1.1 gwr /* Print the option value(s). */
326 1.1 gwr switch (optstr[0]) {
327 1.1 gwr
328 1.1 gwr case 'a': /* ASCII string */
329 1.1 gwr printfn(bp, bp + len);
330 1.1 gwr bp += len;
331 1.1 gwr len = 0;
332 1.1 gwr break;
333 1.1 gwr
334 1.1 gwr case 's': /* Word formats */
335 1.1 gwr while (len >= 2) {
336 1.1 gwr bcopy((char *) bp, (char *) &us, 2);
337 1.1 gwr printf("%d", ntohs(us));
338 1.1 gwr bp += 2;
339 1.1 gwr len -= 2;
340 1.1 gwr if (len) printf(",");
341 1.1 gwr }
342 1.1 gwr if (len) printf("(junk=%d)", len);
343 1.1 gwr break;
344 1.1 gwr
345 1.1 gwr case 'l': /* Long words */
346 1.1 gwr while (len >= 4) {
347 1.1 gwr bcopy((char *) bp, (char *) &ul, 4);
348 1.1 gwr printf("%d", ntohl(ul));
349 1.1 gwr bp += 4;
350 1.1 gwr len -= 4;
351 1.1 gwr if (len) printf(",");
352 1.1 gwr }
353 1.1 gwr if (len) printf("(junk=%d)", len);
354 1.1 gwr break;
355 1.1 gwr
356 1.1 gwr case 'i': /* INET addresses */
357 1.1 gwr while (len >= 4) {
358 1.1 gwr bcopy((char *) bp, (char *) &ia, 4);
359 1.1 gwr printf("%s", ipaddr_string(&ia));
360 1.1 gwr bp += 4;
361 1.1 gwr len -= 4;
362 1.1 gwr if (len) printf(",");
363 1.1 gwr }
364 1.1 gwr if (len) printf("(junk=%d)", len);
365 1.1 gwr break;
366 1.1 gwr
367 1.1 gwr case 'b':
368 1.1 gwr default:
369 1.1 gwr break;
370 1.1 gwr
371 1.1 gwr } /* switch */
372 1.1 gwr
373 1.1 gwr /* Print as characters, if appropriate. */
374 1.1 gwr if (len) {
375 1.1 gwr dump_hex(bp, len);
376 1.1 gwr if (isascii(*bp) && isprint(*bp)) {
377 1.1 gwr printf("(");
378 1.1 gwr printfn(bp, bp + len);
379 1.1 gwr printf(")");
380 1.1 gwr }
381 1.1 gwr bp += len;
382 1.1 gwr len = 0;
383 1.1 gwr }
384 1.1 gwr } /* while bp < ep */
385 1.1 gwr }
386 1.1 gwr
387 1.1 gwr static void
388 1.1 gwr cmu_print(bp, length)
389 1.1 gwr register u_char *bp;
390 1.1 gwr int length;
391 1.1 gwr {
392 1.1 gwr struct cmu_vend *v;
393 1.1 gwr u_char *ep;
394 1.1 gwr
395 1.1 gwr printf("-cmu");
396 1.1 gwr
397 1.1 gwr v = (struct cmu_vend *) bp;
398 1.1 gwr if (length < sizeof(*v)) {
399 1.1 gwr printf(" |L=%d", length);
400 1.1 gwr return;
401 1.1 gwr }
402 1.1 gwr /* Setup end pointer */
403 1.1 gwr ep = bp + length;
404 1.1 gwr
405 1.1 gwr /* Subnet mask */
406 1.1 gwr if (v->v_flags & VF_SMASK) {
407 1.1 gwr printf(" SM:%s", ipaddr_string(&v->v_smask));
408 1.1 gwr }
409 1.1 gwr /* Default gateway */
410 1.1 gwr if (v->v_dgate.s_addr)
411 1.1 gwr printf(" GW:%s", ipaddr_string(&v->v_dgate));
412 1.1 gwr
413 1.1 gwr /* Domain name servers */
414 1.1 gwr if (v->v_dns1.s_addr)
415 1.1 gwr printf(" DNS1:%s", ipaddr_string(&v->v_dns1));
416 1.1 gwr if (v->v_dns2.s_addr)
417 1.1 gwr printf(" DNS2:%s", ipaddr_string(&v->v_dns2));
418 1.1 gwr
419 1.1 gwr /* IEN-116 name servers */
420 1.1 gwr if (v->v_ins1.s_addr)
421 1.1 gwr printf(" INS1:%s", ipaddr_string(&v->v_ins1));
422 1.1 gwr if (v->v_ins2.s_addr)
423 1.1 gwr printf(" INS2:%s", ipaddr_string(&v->v_ins2));
424 1.1 gwr
425 1.1 gwr /* Time servers */
426 1.1 gwr if (v->v_ts1.s_addr)
427 1.1 gwr printf(" TS1:%s", ipaddr_string(&v->v_ts1));
428 1.1 gwr if (v->v_ts2.s_addr)
429 1.1 gwr printf(" TS2:%s", ipaddr_string(&v->v_ts2));
430 1.1 gwr
431 1.1 gwr }
432 1.1 gwr
433 1.1 gwr
434 1.1 gwr /*
435 1.1 gwr * Print out arbitrary, unknown vendor data.
436 1.1 gwr */
437 1.1 gwr
438 1.1 gwr static void
439 1.1 gwr other_print(bp, length)
440 1.1 gwr register u_char *bp;
441 1.1 gwr int length;
442 1.1 gwr {
443 1.1 gwr u_char *ep; /* end pointer */
444 1.1 gwr u_char *zp; /* points one past last non-zero byte */
445 1.1 gwr
446 1.1 gwr /* Setup end pointer */
447 1.1 gwr ep = bp + length;
448 1.1 gwr
449 1.1 gwr /* Find the last non-zero byte. */
450 1.1 gwr for (zp = ep; zp > bp; zp--) {
451 1.1 gwr if (zp[-1] != 0)
452 1.1 gwr break;
453 1.1 gwr }
454 1.1 gwr
455 1.1 gwr /* Print the all-zero case in a compact representation. */
456 1.1 gwr if (zp == bp) {
457 1.1 gwr printf("-all-zero");
458 1.1 gwr return;
459 1.1 gwr }
460 1.1 gwr printf("-unknown");
461 1.1 gwr
462 1.1 gwr /* Are there enough trailing zeros to make "00..." worthwhile? */
463 1.1 gwr if (zp + 2 > ep)
464 1.1 gwr zp = ep; /* print them all normally */
465 1.1 gwr
466 1.1 gwr /* Now just print all the non-zero data. */
467 1.1 gwr while (bp < zp) {
468 1.1 gwr printf(".%02X", *bp);
469 1.1 gwr bp++;
470 1.1 gwr }
471 1.1 gwr
472 1.1 gwr if (zp < ep)
473 1.1 gwr printf(".00...");
474 1.1 gwr
475 1.1 gwr return;
476 1.1 gwr }
477 1.1 gwr
478 1.1 gwr static void
479 1.1 gwr dump_hex(bp, len)
480 1.1 gwr u_char *bp;
481 1.1 gwr int len;
482 1.1 gwr {
483 1.1 gwr while (len > 0) {
484 1.1 gwr printf("%02X", *bp);
485 1.1 gwr bp++;
486 1.1 gwr len--;
487 1.1 gwr if (len) printf(".");
488 1.1 gwr }
489 1.1 gwr }
490 1.1 gwr
491 1.1 gwr /*
492 1.1 gwr * Local Variables:
493 1.1 gwr * tab-width: 4
494 1.1 gwr * c-indent-level: 4
495 1.1 gwr * c-argdecl-indent: 4
496 1.1 gwr * c-continued-statement-offset: 4
497 1.1 gwr * c-continued-brace-offset: -4
498 1.1 gwr * c-label-offset: -4
499 1.1 gwr * c-brace-offset: 0
500 1.1 gwr * End:
501 */
502