| 96 | | |
| 97 | | void lamont_hdump(unsigned char *bp, unsigned int length) |
| 98 | | { |
| 99 | | |
| 100 | | /* stolen from tcpdump, then kludged extensively */ |
| 101 | | |
| 102 | | static const char asciify[] = |
| 103 | | "................................ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~................................................................................................................................."; |
| 104 | | |
| 105 | | const unsigned short *sp; |
| 106 | | const unsigned char *ap; |
| 107 | | unsigned int i, j; |
| 108 | | int nshorts, nshorts2; |
| 109 | | int padding; |
| 110 | | |
| 111 | | printf("\n\t"); |
| 112 | | padding = 0; |
| 113 | | sp = (unsigned short *)bp; |
| 114 | | ap = (unsigned char *)bp; |
| 115 | | nshorts = (unsigned int)length / sizeof(unsigned short); |
| 116 | | nshorts2 = (unsigned int)length / sizeof(unsigned short); |
| 117 | | i = 0; |
| 118 | | j = 0; |
| 119 | | while (1) { |
| 120 | | while (--nshorts >= 0) { |
| 121 | | printf(" %04x", ntohs(*sp)); |
| 122 | | sp++; |
| 123 | | if ((++i % 8) == 0) |
| 124 | | break; |
| 125 | | } |
| 126 | | if (nshorts < 0) { |
| 127 | | if ((length & 1) && (((i - 1) % 8) != 0)) { |
| 128 | | printf(" %02x ", *(unsigned char *)sp); |
| 129 | | padding++; |
| 130 | | } |
| 131 | | nshorts = (8 - (nshorts2 - nshorts)); |
| 132 | | while (--nshorts >= 0) { |
| 133 | | printf(" "); |
| 134 | | } |
| 135 | | if (!padding) |
| 136 | | printf(" "); |
| 137 | | } |
| 138 | | printf(" "); |
| 139 | | |
| 140 | | while (--nshorts2 >= 0) { |
| 141 | | printf("%c%c", asciify[*ap], asciify[*(ap + 1)]); |
| 142 | | ap += 2; |
| 143 | | if ((++j % 8) == 0) { |
| 144 | | printf("\n\t"); |
| 145 | | break; |
| 146 | | } |
| 147 | | } |
| 148 | | if (nshorts2 < 0) { |
| 149 | | if ((length & 1) && (((j - 1) % 8) != 0)) { |
| 150 | | printf("%c", asciify[*ap]); |
| 151 | | } |
| 152 | | break; |
| 153 | | } |
| 154 | | } |
| 155 | | if ((length & 1) && (((i - 1) % 8) == 0)) { |
| 156 | | printf(" %02x", *(unsigned char *)sp); |
| 157 | | printf(" %c", |
| 158 | | asciify[*ap]); |
| 159 | | } |
| 160 | | printf("\n"); |
| 161 | | } |
| 162 | | |