X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/c9d84d15c5c4dc8eca7594101fe5026080ed641e..f0d4fb1e2fa6cc9e81e9c65a1a433951e54bb8ed:/print-tcp.c diff --git a/print-tcp.c b/print-tcp.c index 80335c1d..895be3bf 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -21,7 +21,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.57 1999-10-30 05:11:21 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.61 1999-11-22 04:27:10 fenner Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include @@ -104,6 +108,8 @@ struct tcp_seq_hash { static struct tcp_seq_hash tcp_seq_hash[TSEQ_HASHSIZE]; +#define NETBIOS_SSN_PORT 139 + void tcp_print(register const u_char *bp, register u_int length, register const u_char *bp2) @@ -114,7 +120,8 @@ tcp_print(register const u_char *bp, register u_int length, register int hlen; register char ch; u_short sport, dport, win, urp; - u_int32_t seq, ack; + u_int32_t seq, ack, thseq, thack; + int threv; #ifdef INET6 register const struct ip6_hdr *ip6; #endif @@ -128,18 +135,15 @@ tcp_print(register const u_char *bp, register u_int length, ip6 = NULL; #endif /*INET6*/ ch = '\0'; - TCHECK(*tp); - if (length < sizeof(*tp)) { - (void)printf("truncated-tcp %d", length); + if (!TTEST(tp->th_dport)) { + (void)printf("%s > %s: [|tcp]", + ipaddr_string(&ip->ip_src), + ipaddr_string(&ip->ip_dst)); return; } sport = ntohs(tp->th_sport); dport = ntohs(tp->th_dport); - seq = ntohl(tp->th_seq); - ack = ntohl(tp->th_ack); - win = ntohs(tp->th_win); - urp = ntohs(tp->th_urp); #ifdef INET6 if (ip6) { @@ -168,6 +172,13 @@ tcp_print(register const u_char *bp, register u_int length, } } + TCHECK(*tp); + + seq = ntohl(tp->th_seq); + ack = ntohl(tp->th_ack); + win = ntohs(tp->th_win); + urp = ntohs(tp->th_urp); + if (qflag) { (void)printf("tcp %d", length - tp->th_off * 4); return; @@ -192,6 +203,15 @@ tcp_print(register const u_char *bp, register u_int length, } else putchar('.'); + if (flags&0xc0) { + printf(" ["); + if (flags&0x40) + printf("ECN-Echo"); + if (flags&0x80) + printf("%sCWR", (flags&0x40) ? "," : ""); + printf("]"); + } + if (!Sflag && (flags & TH_ACK)) { register struct tcp_seq_hash *th; register int rev; @@ -258,6 +278,7 @@ tcp_print(register const u_char *bp, register u_int length, } #endif + threv = rev; for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE]; th->nxt; th = th->nxt) if (!memcmp((char *)&tha, (char *)&th->addr, @@ -278,6 +299,10 @@ tcp_print(register const u_char *bp, register u_int length, else th->seq = seq, th->ack = ack - 1; } else { + + thseq = th->seq; + thack = th->ack; + if (rev) seq -= th->ack, ack -= th->seq; else @@ -290,7 +315,7 @@ tcp_print(register const u_char *bp, register u_int length, return; } length -= hlen; - if (length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) + if (vflag > 1 || length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) (void)printf(" %u:%u(%d)", seq, seq + length, length); if (flags & TH_ACK) (void)printf(" ack %u", ack); @@ -360,15 +385,28 @@ tcp_print(register const u_char *bp, register u_int length, case TCPOPT_SACK: (void)printf("sack"); datalen = len - 2; - for (i = 0; i < datalen; i += 4) { - LENCHECK(i + 4); - /* block-size@relative-origin */ - (void)printf(" %u@%u", - EXTRACT_16BITS(cp + i + 2), - EXTRACT_16BITS(cp + i)); + if (datalen % 8 != 0) { + (void)printf(" malformed sack "); + } else { + u_int32_t s, e; + + (void)printf(" sack %d ", datalen / 8); + for (i = 0; i < datalen; i += 8) { + LENCHECK(i + 4); + s = EXTRACT_32BITS(cp + i); + LENCHECK(i + 8); + e = EXTRACT_32BITS(cp + i + 4); + if (threv) { + s -= thseq; + e -= thseq; + } else { + s -= thack; + e -= thack; + } + (void)printf("{%u:%u}", s, e); + } + (void)printf(" "); } - if (datalen % 4) - (void)printf("[len %d]", len); break; case TCPOPT_ECHO: @@ -451,6 +489,8 @@ tcp_print(register const u_char *bp, register u_int length, bp += (tp->th_off * 4); if (sport == 179 || dport == 179) bgp_print(bp, length); + if (sport == NETBIOS_SSN_PORT || dport == NETBIOS_SSN_PORT) + nbt_tcp_print(bp, length); return; bad: fputs("[bad opt]", stdout);