From owner-freebsd-net  Wed Sep 11 19:13:38 2002
Delivered-To: freebsd-net@freebsd.org
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 109DD37B400
	for <net@freebsd.org>; Wed, 11 Sep 2002 19:13:36 -0700 (PDT)
Received: from wall.polstra.com (wall-gw.polstra.com [206.213.73.130])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9BDC043E3B
	for <net@freebsd.org>; Wed, 11 Sep 2002 19:13:34 -0700 (PDT)
	(envelope-from jdp@polstra.com)
Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13])
	by wall.polstra.com (8.11.3/8.11.3) with ESMTP id g8C2DUf63307;
	Wed, 11 Sep 2002 19:13:30 -0700 (PDT)
	(envelope-from jdp@vashon.polstra.com)
Received: (from jdp@localhost)
	by vashon.polstra.com (8.12.5/8.12.5/Submit) id g8C2DUZL032515;
	Wed, 11 Sep 2002 19:13:30 -0700 (PDT)
	(envelope-from jdp)
Date: Wed, 11 Sep 2002 19:13:30 -0700 (PDT)
Message-Id: <200209120213.g8C2DUZL032515@vashon.polstra.com>
To: net@freebsd.org
From: John Polstra <jdp@polstra.com>
Cc: justin@mac.com
Subject: Re: computing the Ack Seq. No.
In-Reply-To: <5A3F3774-C5B2-11D6-A7E3-00306544D642@mac.com>
References: <5A3F3774-C5B2-11D6-A7E3-00306544D642@mac.com>
Organization: Polstra & Co., Seattle, WA
Sender: owner-freebsd-net@FreeBSD.ORG
Precedence: bulk
List-ID: <freebsd-net.FreeBSD.ORG>
List-Archive: <http://docs.freebsd.org/mail/> (Web Archive)
List-Help: <mailto:majordomo@FreeBSD.ORG?subject=help> (List Instructions)
List-Subscribe: <mailto:majordomo@FreeBSD.ORG?subject=subscribe%20freebsd-net>
List-Unsubscribe: <mailto:majordomo@FreeBSD.ORG?subject=unsubscribe%20freebsd-net>
X-Loop: FreeBSD.org

In article <5A3F3774-C5B2-11D6-A7E3-00306544D642@mac.com>,
Justin C. Walker <justin@mac.com> wrote:
> 
> On Wednesday, September 11, 2002, at 10:50 AM, John Polstra wrote:
> 
> > In article <F6467yRLVbNDN4CxpAO000022f6@hotmail.com>,
> > soheil h <soheil_h_y@hotmail.com> wrote:
> >> hi list
> >> I wrote the code below and it doesn't work correctly
> >> please tell me what is wrong
> >> int len, tlen;
> >> tcpiphdr ti, ti_send;
> >> int hlen;
> >> int acklen;
> >> /*
> >> the hlen is ip header hlen
> >> */
> >> ....
> >> /* the ip->ip_len is ntohs'ed by NTOHS in io_input() */
> >> len = ti->ti_len;
> >> tlen = ti->ti_off << 2;
> >> acklen = len - hlen - tlen;
> >> ti_send->ti_ack = htonl(ntohl(ti->ti_seq) + acklen );
> >> /* this field is incorrect  and i don't know why */
> >
> > If the TH_SYN flag is set in the received packet, you must increment
> > the ack by 1.  Likewise, if the TH_FIN flag is set, you must increment
> > the ack by 1.  In other words, each of those flags counts the same as
> > a byte of data, as far as the ack calculation is concerned.
> 
> Also, it's not clear to me why you include the IP header length in the 
> count of acknowledged TCP bytes.  Perhaps I missunderstand your code...

I think that part is OK. "len" is the total packet length including
the IP and TCP headers.  He takes that and subtracts out the lengths
of the headers to get the number of bytes to ack (acklen).  That's
correct: you ack only the payload, not the headers.

John
-- 
  John Polstra
  John D. Polstra & Co., Inc.                        Seattle, Washington USA
  "Disappointment is a good sign of basic intelligence."  -- Chögyam Trungpa


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message