bootstrap
[www.jankratochvil.net.git] / project / tcpdump / tcpdump-3.4-ASCIIdump.diff
1 --- tcpdump-3.4a5-orig/tcpdump.c        Sat May 30 12:23:33 1998
2 +++ tcpdump-3.4a5/tcpdump.c     Tue Dec 15 15:26:36 1998
3 @@ -405,22 +406,31 @@
4  void
5  default_print_unaligned(register const u_char *cp, register u_int length)
6  {
7 -       register u_int i, s;
8 -       register int nshorts;
9 +       register u_int i,offs=0;
10  
11 -       nshorts = (u_int) length / sizeof(u_short);
12 -       i = 0;
13 -       while (--nshorts >= 0) {
14 -               if ((i++ % 8) == 0)
15 -                       (void)printf("\n\t\t\t");
16 -               s = *cp++;
17 -               (void)printf(" %02x%02x", s, *cp++);
18 -       }
19 -       if (length & 1) {
20 -               if ((i % 8) == 0)
21 -                       (void)printf("\n\t\t\t");
22 -               (void)printf(" %02x", *cp);
23 -       }
24 +#define prBYTES 16
25 +
26 +       while (length) {
27 +               printf("\n%5u=$%04X: ",offs,offs);
28 +               for (i=0;i<prBYTES;i++) {
29 +                       if (i<length) printf("%02X ",cp[i]);
30 +                       else fputs("   ",stdout);
31 +                       if ((i&7)==7 && i!=prBYTES-1) putchar(' ');
32 +                       }
33 +               fputs("| ",stdout);
34 +               for (i=0;i<prBYTES && i<length;i++)
35 +                       if (cp[i]>=0x20 && cp[i]<0x7F) putchar(cp[i]);
36 +                       else putchar('.');
37 +               length-=i;
38 +               cp+=i;
39 +               offs+=i;
40 +// For trailing ASCII space padding (too wide!)
41 +#if 0
42 +               while (i++<prBYTES) putchar(' ');
43 +               fputs(" |",stdout);
44 +#endif
45 +               }
46 +#undef prBYTES
47  }
48  
49  /*
50 @@ -431,27 +441,7 @@
51  void
52  default_print(register const u_char *bp, register u_int length)
53  {
54 -       register const u_short *sp;
55 -       register u_int i;
56 -       register int nshorts;
57 -
58 -       if ((long)bp & 1) {
59 -               default_print_unaligned(bp, length);
60 -               return;
61 -       }
62 -       sp = (u_short *)bp;
63 -       nshorts = (u_int) length / sizeof(u_short);
64 -       i = 0;
65 -       while (--nshorts >= 0) {
66 -               if ((i++ % 8) == 0)
67 -                       (void)printf("\n\t\t\t");
68 -               (void)printf(" %04x", ntohs(*sp++));
69 -       }
70 -       if (length & 1) {
71 -               if ((i % 8) == 0)
72 -                       (void)printf("\n\t\t\t");
73 -               (void)printf(" %02x", *(u_char *)sp);
74 -       }
75 +       default_print_unaligned(bp, length);
76  }
77  
78  __dead void