From owner-freebsd-questions Wed Aug 7 5: 6:51 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F1E9037B400 for ; Wed, 7 Aug 2002 05:06:47 -0700 (PDT) Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id 76B1443E5E for ; Wed, 7 Aug 2002 05:06:46 -0700 (PDT) (envelope-from keramida@ceid.upatras.gr) Received: from hades.hell.gr (patr530-a051.otenet.gr [212.205.215.51]) by mailsrv.otenet.gr (8.12.4/8.12.4) with ESMTP id g77C53PL003634; Wed, 7 Aug 2002 15:05:04 +0300 (EEST) Received: from hades.hell.gr (hades [127.0.0.1]) by hades.hell.gr (8.12.5/8.12.5) with ESMTP id g77C5Fup004970; Wed, 7 Aug 2002 15:05:15 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from charon@localhost) by hades.hell.gr (8.12.5/8.12.5/Submit) id g77C4qeL004892; Wed, 7 Aug 2002 15:04:52 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Wed, 7 Aug 2002 15:04:52 +0300 From: Giorgos Keramidas To: soheil h Cc: freebsd-questions@FreeBSD.ORG, hassas@ce.sharif.ac.ir Subject: Re: accessing tcp header in the ip_input.c::ip_forward() !!!!! Message-ID: <20020807120452.GA4760@hades.hell.gr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 5.0-CURRENT i386 X-PGP-Fingerprint: C1EB 0653 DB8B A557 3829 00F9 D60F 941A 3186 03B6 X-Phone: +30-944-116520 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 2002-08-05 22:50 +0000, soheil h wrote: > i made a change in ip_forward() in ip_input.c to print the window > sizes passes through my gateway. but it doesn't work properly and > doesn't show the true th_win (window size) and the th_dport they > doesn't mach the tcpdump output but shows the true ip->ip_p for TCP > it means that i make a wrong cast in ip packet means not at the > place of the tcphdr some byte more or less i don't know please > verify me if my code is true and if not please help me !!!!! [...] > static void > ip_forward(m, srcrt) > struct mbuf *m; > int srcrt; > { > register struct ip *ip = mtod(m, struct ip *); [...] > int s_len; /* the ip length */ [...] > s_len = IP_VHL_HL(ip->ip_vhl) << 2; > if(ip->ip_p == IPPROTO_TCP) > { > s_hdr = (struct tcpShdr *)( (caddr_t) ip + s_len); If my understanding of the relevant issues is not flawed, you have missed just a very minor detail, and used the `ip' pointer to print the contents of random memory instead of the true tcphdr->th_win values you think you are printing. The packet is stored in a chain of mbufs. The first mbuf might contain less data than you'd normally expect. You will need to use m_pullup() to ensure that the proper amount of data is available at the head of the packet's mbuf chain. Note that m_pullup() might be an expensive operation that involves memory copies. You will almost invariably find that it's a good idea to call m_pullup() only if it is absolutely and unavoidably necessary, i.e. you should call it only if: m->m_len < (sizeof(struct iphdr) + sizeof(struct tcphdr)) with code similar to: int hlen; struct mbuf *p; hlen = sizeof(struct iphdr) + sizeof(struct tcphdr); if (m->m_len < hlen) { if ((p = m_pullup(m, hlen)) == NULL) { /* Failed. Handle the error. */ } } /* Work on the `m' chain of mbufs like you do until now. */ - Giorgos To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message