Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Aug 2002 15:04:52 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        soheil h <soheil_h_y@hotmail.com>
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>
In-Reply-To: <F170mpN7JvVAabAQJ6j0000c5ab@hotmail.com>
References:  <F170mpN7JvVAabAQJ6j0000c5ab@hotmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020807120452.GA4760>