diff options
author | itojun <itojun> | 2000-12-30 15:47:58 +0000 |
---|---|---|
committer | itojun <itojun> | 2000-12-30 15:47:58 +0000 |
commit | f4bc38ab2666c09fccbcbbddc128159232de8c1a (patch) | |
tree | 4ecfb9c3eb82c2e8c408131e55bcd9c2d2c53b2f /print-domain.c | |
parent | 79ce1730d70ed57a0e49c534bbebfd46b7196ba1 (diff) | |
download | tcpdump-f4bc38ab2666c09fccbcbbddc128159232de8c1a.tar.gz |
correct bit string label decoding. jinmei@kame.net
Diffstat (limited to 'print-domain.c')
-rw-r--r-- | print-domain.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/print-domain.c b/print-domain.c index 74e63547..16212c8f 100644 --- a/print-domain.c +++ b/print-domain.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.60 2000-12-30 09:07:40 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-domain.c,v 1.61 2000-12-30 15:47:58 itojun Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -180,26 +180,34 @@ ns_nskip(register const u_char *cp, register const u_char *bp) static const u_char * blabel_print(const u_char *cp) { - int bitlen, bytelen; + int bitlen, slen, b; int truncated = 0; const u_char *bitp, *lim; + char tc; if (cp >= snapend) return(NULL); if ((bitlen = *cp) == 0) bitlen = 256; - bytelen = (bitlen + 7) / 8; - if ((lim = cp + 1 + bytelen) > snapend) { + slen = (bitlen + 3) / 4; + if ((lim = cp + 1 + slen) > snapend) { truncated = 1; lim = snapend; } /* print the bit string as a hex string */ printf("\\[x"); - for (bitp = cp + 1; bitp < lim; bitp++) + for (bitp = cp + 1, b = bitlen; bitp < lim && b > 3; b -= 8, bitp++) printf("%02x", *bitp); - if (truncated) + if (bitp == lim) printf("..."); + else if (b > 4) { + tc = *bitp++; + printf("%02x", tc & (0xff << (8 - tc))); + } else if (b > 0) { + tc = *bitp++; + printf("%1x", (tc >> 4) & 0x0f); + } printf("/%d]", bitlen); return(truncated ? NULL : lim); |