+ if (ip6) {
+ register struct tcp_seq_hash6 *th;
+ struct tcp_seq_hash6 *tcp_seq_hash;
+ const struct in6_addr *src, *dst;
+ struct tha6 tha;
+
+ tcp_seq_hash = tcp_seq_hash6;
+ src = &ip6->ip6_src;
+ dst = &ip6->ip6_dst;
+ if (sport > dport)
+ rev = 1;
+ else if (sport == dport) {
+ if (UNALIGNED_MEMCMP(src, dst, sizeof ip6->ip6_dst) > 0)
+ rev = 1;
+ }
+ if (rev) {
+ UNALIGNED_MEMCPY(&tha.src, dst, sizeof ip6->ip6_dst);
+ UNALIGNED_MEMCPY(&tha.dst, src, sizeof ip6->ip6_src);
+ tha.port = dport << 16 | sport;
+ } else {
+ UNALIGNED_MEMCPY(&tha.dst, dst, sizeof ip6->ip6_dst);
+ UNALIGNED_MEMCPY(&tha.src, src, sizeof ip6->ip6_src);
+ tha.port = sport << 16 | dport;
+ }
+
+ for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE];
+ th->nxt; th = th->nxt)
+ if (memcmp((char *)&tha, (char *)&th->addr,
+ sizeof(th->addr)) == 0)
+ break;
+
+ if (!th->nxt || (flags & TH_SYN)) {
+ /* didn't find it or new conversation */
+ if (th->nxt == NULL) {
+ th->nxt = (struct tcp_seq_hash6 *)
+ calloc(1, sizeof(*th));
+ if (th->nxt == NULL)
+ error("tcp_print: calloc");
+ }
+ th->addr = tha;
+ if (rev)
+ th->ack = seq, th->seq = ack - 1;
+ else
+ th->seq = seq, th->ack = ack - 1;
+ } else {
+ if (rev)
+ seq -= th->ack, ack -= th->seq;
+ else
+ seq -= th->seq, ack -= th->ack;
+ }
+
+ thseq = th->seq;
+ thack = th->ack;
+ } else {
+#else /*INET6*/
+ {
+#endif /*INET6*/
+ register struct tcp_seq_hash *th;
+ struct tcp_seq_hash *tcp_seq_hash;
+ const struct in_addr *src, *dst;
+ struct tha tha;
+
+ tcp_seq_hash = tcp_seq_hash4;
+ src = &ip->ip_src;
+ dst = &ip->ip_dst;
+ if (sport > dport)
+ rev = 1;
+ else if (sport == dport) {
+ if (UNALIGNED_MEMCMP(src, dst, sizeof ip->ip_dst) > 0)
+ rev = 1;
+ }
+ if (rev) {
+ UNALIGNED_MEMCPY(&tha.src, dst, sizeof ip->ip_dst);
+ UNALIGNED_MEMCPY(&tha.dst, src, sizeof ip->ip_src);
+ tha.port = dport << 16 | sport;
+ } else {
+ UNALIGNED_MEMCPY(&tha.dst, dst, sizeof ip->ip_dst);
+ UNALIGNED_MEMCPY(&tha.src, src, sizeof ip->ip_src);
+ tha.port = sport << 16 | dport;
+ }
+
+ for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE];
+ th->nxt; th = th->nxt)
+ if (memcmp((char *)&tha, (char *)&th->addr,
+ sizeof(th->addr)) == 0)
+ break;
+
+ if (!th->nxt || (flags & TH_SYN)) {
+ /* didn't find it or new conversation */
+ if (th->nxt == NULL) {
+ th->nxt = (struct tcp_seq_hash *)
+ calloc(1, sizeof(*th));
+ if (th->nxt == NULL)
+ error("tcp_print: calloc");
+ }
+ th->addr = tha;
+ if (rev)
+ th->ack = seq, th->seq = ack - 1;
+ else
+ th->seq = seq, th->ack = ack - 1;
+ } 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 = rev = 0;
+ }
+ if (hlen > length) {
+ ND_PRINT((ndo, " [bad hdr length %u - too long, > %u]",
+ hlen, length));
+ return;
+ }
+
+ if (ndo->ndo_vflag && !ndo->ndo_Kflag && !fragmented) {
+ /* Check the checksum, if possible. */
+ uint16_t sum, tcp_sum;
+
+ if (IP_V(ip) == 4) {
+ if (ND_TTEST2(tp->th_sport, length)) {
+ sum = tcp_cksum(ndo, ip, tp, length);
+ tcp_sum = EXTRACT_16BITS(&tp->th_sum);
+
+ ND_PRINT((ndo, ", cksum 0x%04x", tcp_sum));
+ if (sum != 0)
+ ND_PRINT((ndo, " (incorrect -> 0x%04x)",
+ in_cksum_shouldbe(tcp_sum, sum)));
+ else
+ ND_PRINT((ndo, " (correct)"));
+ }
+ }
+#ifdef INET6
+ else if (IP_V(ip) == 6 && ip6->ip6_plen) {
+ if (ND_TTEST2(tp->th_sport, length)) {
+ sum = nextproto6_cksum(ip6, (const uint8_t *)tp,
+ length, length, IPPROTO_TCP);
+ tcp_sum = EXTRACT_16BITS(&tp->th_sum);
+
+ ND_PRINT((ndo, ", cksum 0x%04x", tcp_sum));
+ if (sum != 0)
+ ND_PRINT((ndo, " (incorrect -> 0x%04x)",
+ in_cksum_shouldbe(tcp_sum, sum)));
+ else
+ ND_PRINT((ndo, " (correct)"));
+
+ }
+ }