X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/2813c22cf1ab58ee309749eae16f6211cea59952..2e065e6bcde70f8c54a19d9ff7e4710f60f296af:/print-tcp.c diff --git a/print-tcp.c b/print-tcp.c index 4cb88861..fe8f5eab 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.63 1999-12-22 15:44:10 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.66 2000-06-01 01:09:32 assar Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -31,6 +31,8 @@ static const char rcsid[] = #include #include +#include + #include #include #include @@ -82,6 +84,17 @@ static const char rcsid[] = #define TCPOPT_CCECHO 13 /* T/TCP CC options (rfc1644) */ #endif +/* + * Definitions required for ECN + * for use if the OS running tcpdump does not have ECN + */ +#ifndef TH_ECNECHO +#define TH_ECNECHO 0x40 /* ECN Echo in tcp header */ +#endif +#ifndef TH_CWR +#define TH_CWR 0x80 /* ECN Cwnd Reduced in tcp header*/ +#endif + struct tha { #ifndef INET6 struct in_addr src; @@ -115,6 +128,9 @@ static struct tcp_seq_hash tcp_seq_hash[TSEQ_HASHSIZE]; #define BGP_PORT 179 #endif #define NETBIOS_SSN_PORT 139 +#ifndef NFS_PORT +#define NFS_PORT 2049 +#endif void tcp_print(register const u_char *bp, register u_int length, @@ -125,7 +141,7 @@ tcp_print(register const u_char *bp, register u_int length, register u_char flags; register int hlen; register char ch; - u_short sport, dport, win, urp; + u_int16_t sport, dport, win, urp; u_int32_t seq, ack, thseq, thack; int threv; #ifdef INET6 @@ -151,6 +167,28 @@ tcp_print(register const u_char *bp, register u_int length, sport = ntohs(tp->th_sport); dport = ntohs(tp->th_dport); + + hlen = tp->th_off * 4; + + /* + * If data present and NFS port used, assume NFS. + * Pass offset of data plus 4 bytes for RPC TCP msg length + * to NFS print routines. + */ + if (!qflag) { + if ((u_char *)tp + 4 + sizeof(struct rpc_msg) <= snapend && + dport == NFS_PORT) { + nfsreq_print((u_char *)tp + hlen + 4, length-hlen, + (u_char *)ip); + return; + } else if ((u_char *)tp + 4 + sizeof(struct rpc_msg) + <= snapend && + sport == NFS_PORT) { + nfsreply_print((u_char *)tp + hlen + 4,length-hlen, + (u_char *)ip); + return; + } + } #ifdef INET6 if (ip6) { if (ip6->ip6_nxt == IPPROTO_TCP) { @@ -180,8 +218,8 @@ tcp_print(register const u_char *bp, register u_int length, TCHECK(*tp); - seq = ntohl(tp->th_seq); - ack = ntohl(tp->th_ack); + seq = (u_int32_t)ntohl(tp->th_seq); + ack = (u_int32_t)ntohl(tp->th_ack); win = ntohs(tp->th_win); urp = ntohs(tp->th_urp); @@ -189,12 +227,8 @@ tcp_print(register const u_char *bp, register u_int length, (void)printf("tcp %d", length - tp->th_off * 4); return; } -#ifdef TH_ECN - if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH|TH_ECN)) -#else - if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH)) -#endif - { + if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH| + TH_ECNECHO|TH_CWR)) { if (flags & TH_SYN) putchar('S'); if (flags & TH_FIN) @@ -203,22 +237,13 @@ tcp_print(register const u_char *bp, register u_int length, putchar('R'); if (flags & TH_PUSH) putchar('P'); -#ifdef TH_ECN - if (flags & TH_ECN) - putchar('C'); -#endif + if (flags & TH_CWR) + putchar('W'); /* congestion _W_indow reduced (ECN) */ + if (flags & TH_ECNECHO) + putchar('E'); /* ecn _E_cho sent (ECN) */ } 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; @@ -292,7 +317,7 @@ tcp_print(register const u_char *bp, register u_int length, sizeof(th->addr))) break; - if (!th->nxt || flags & TH_SYN) { + if (!th->nxt || (flags & TH_SYN)) { /* didn't find it or new conversation */ if (th->nxt == NULL) { th->nxt = (struct tcp_seq_hash *) @@ -305,18 +330,20 @@ tcp_print(register const u_char *bp, register u_int length, th->ack = seq, th->seq = ack - 1; else th->seq = seq, th->ack = ack - 1; - } else { - - thseq = th->seq; - thack = th->ack; + } else { if (rev) seq -= th->ack, ack -= th->seq; else seq -= th->seq, ack -= th->ack; } + + thseq = th->seq; + thack = th->ack; + } else { + /*fool gcc*/ + thseq = thack = threv = 0; } - hlen = tp->th_off * 4; if (hlen > length) { (void)printf(" [bad hdr length]"); return;