Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 May 2000 00:11:07 +1200 
From:      "MATTHEW JOHN,LUCKIE" <mjl12@waikato.ac.nz>
To:        "'freebsd-hackers@freebsd.org '" <freebsd-hackers@freebsd.org>
Subject:   mbufs & ip stack
Message-ID:  <45E87454FFC2D211AD9800508B6500942392F8@stu-ex1.waikato.ac.nz>

next in thread | raw e-mail | index | archive | help
Hi

I am writing some custom code into the freebsd ip stack (as a project)

I am trying to get the payload of an ip packet out of an mbuf and cast it to
the type of data being carried (an ipmp header).

When i try to get the ipmp_hdr out of the mbuf, and try to do some work with
it, i seem to be referencing the ip_hdr with the ipmp_hdr pointer (based on
the values i extract from it)

What am i doing wrong?  I have based my code on the Freebsd 3.2 icmp code
and am running under freebsd 3.2

Also, why is the ICMP_ADVLENMIN defined as (8 + sizeof(struct ip) + 8) in
ip_icmp.h ??

Below is the source for what i am doing

Hopefully someone can help

Matthew

#define IPMP_ADVLENMIN (8 + sizeof(struct ip) + 8)
void ipmp_input(struct mbuf *m, int off)
{
  struct ip          *ip_hdr;
  int                 ipmplen;
  int                 hlen;
  int                 i;
  struct ipmp_header *ipmp_hdr;

  ip_hdr  = mtod(m, struct ip *);
  ipmplen = ip_hdr->ip_len;
  hlen    = off;

/* check that the length of the data in the packet is the minimum reqd */
  if(ipmplen < IPMP_MINLEN)
    {
      ipmpstat.tooshort++;
      goto freeit;
    }

  /* pull up the header of the ipmp packet */
  i = hlen + min(ipmplen, IPMP_ADVLENMIN);

  if(m->m_len < i && (m = m_pullup(m,i)) == 0)
    {
    /* if the call fails to m_pullup, the buffer is freed automatically */
      ipmpstat.tooshort++;
      return;
    }

  /* get the ip header again as the mbuf locn has probably changed */
  ip_hdr = mtod(m, struct ip *);

  /* get the ipmp header */
  m->m_len  -= hlen;
  m->m_data += hlen;
  ipmp_hdr   = mtod(m, struct ipmp_header *);
  m->m_len  += hlen;
  m->m_data -= hlen;


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




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