Diff for /embedaddon/libnet/src/libnet_build_ip.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2012/02/21 22:14:23 version 1.1.1.2, 2013/07/22 11:54:42
Line 40 Line 40
 #endif  #endif
   
   
   /* TODO len - should be calculated if -1 */
 libnet_ptag_t  libnet_ptag_t
libnet_build_ipv4(u_int16_t len, u_int8_t tos, u_int16_t id, u_int16_t frag,libnet_build_ipv4(uint16_t ip_len, uint8_t tos, uint16_t id, uint16_t frag,
u_int8_t ttl, u_int8_t prot, u_int16_t sum, u_int32_t src, u_int32_t dst,uint8_t ttl, uint8_t prot, uint16_t sum, uint32_t src, uint32_t dst,
u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
 {  {
    int offset;    uint32_t n = LIBNET_IPV4_H; /* size of memory block */
    u_int32_t h, n, i, j; 
     libnet_pblock_t *p, *p_data, *p_temp;      libnet_pblock_t *p, *p_data, *p_temp;
     struct libnet_ipv4_hdr ip_hdr;      struct libnet_ipv4_hdr ip_hdr;
    libnet_ptag_t ptag_data, ptag_hold;    libnet_ptag_t ptag_data = 0; /* used if there is ipv4 payload */
     libnet_ptag_t ptag_hold;
   
     if (l == NULL)      if (l == NULL)
     {       { 
         return (-1);          return (-1);
     }       } 
   
     n = LIBNET_IPV4_H;                      /* size of memory block */  
     h = len;                                /* header length */  
     ptag_data = 0;                          /* used if options are present */  
   
     if (h + payload_s > IP_MAXPACKET)  
     {  
          snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,  
                 "%s(): IP packet too large\n", __func__);  
         return (-1);  
     }  
   
     /*      /*
      *  Find the existing protocol block if a ptag is specified, or create       *  Find the existing protocol block if a ptag is specified, or create
      *  a new one.       *  a new one.
Line 77  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l Line 67  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
         return (-1);          return (-1);
     }      }
   
        memset(&ip_hdr, 0, sizeof(ip_hdr));    memset(&ip_hdr, 0, sizeof(ip_hdr));
    ip_hdr.ip_v          = 4;                         /* version 4 */    ip_hdr.ip_v          = 4;      /* version 4 */
    ip_hdr.ip_hl         = 5;                         /* 20 byte header */    ip_hdr.ip_hl         = 5;      /* 20 byte header,  measured in 32-bit words */
   
     /* check to see if there are IP options to include */      /* check to see if there are IP options to include */
     if (p->prev)      if (p->prev)
     {      {
         if (p->prev->type == LIBNET_PBLOCK_IPO_H)          if (p->prev->type == LIBNET_PBLOCK_IPO_H)
         {          {
            /*            /* IPO block's length must be multiple of 4, or it's incorrectly
             *  Count up number of 32-bit words in options list, padding if             * padded, in which case there is no "correct" IP header length,
             *  neccessary.             * it will too short or too long, we choose too short.
              */               */
            for (i = 0, j = 0; i < p->prev->b_len; i++)            ip_hdr.ip_hl += p->prev->b_len / 4;
            { 
                (i % 4) ? j : j++; 
            } 
            ip_hdr.ip_hl += j; 
         }          }
     }      }
       /* Note that p->h_len is not adjusted. This seems a bug, but it is because
        * it is not used!  libnet_do_checksum() is passed the h_len (as `len'),
        * but for IPPROTO_IP it is ignored in favor of the ip_hl.
        */
   
     ip_hdr.ip_tos        = tos;                       /* IP tos */      ip_hdr.ip_tos        = tos;                       /* IP tos */
    ip_hdr.ip_len        = htons(h);                  /* total length */    ip_hdr.ip_len        = htons(ip_len);             /* total length */
     ip_hdr.ip_id         = htons(id);                 /* IP ID */      ip_hdr.ip_id         = htons(id);                 /* IP ID */
     ip_hdr.ip_off        = htons(frag);               /* fragmentation flags */      ip_hdr.ip_off        = htons(frag);               /* fragmentation flags */
     ip_hdr.ip_ttl        = ttl;                       /* time to live */      ip_hdr.ip_ttl        = ttl;                       /* time to live */
Line 108  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l Line 98  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
     ip_hdr.ip_src.s_addr = src;                       /* source ip */      ip_hdr.ip_src.s_addr = src;                       /* source ip */
     ip_hdr.ip_dst.s_addr = dst;                       /* destination ip */      ip_hdr.ip_dst.s_addr = dst;                       /* destination ip */
           
    n = libnet_pblock_append(l, p, (u_int8_t *)&ip_hdr, LIBNET_IPV4_H);    n = libnet_pblock_append(l, p, (uint8_t *)&ip_hdr, LIBNET_IPV4_H);
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
Line 123  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l Line 113  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
     }      }
   
     /* find and set the appropriate ptag, or else use the default of 0 */      /* find and set the appropriate ptag, or else use the default of 0 */
    offset = payload_s;    /* When updating the ipv4 block, we need to find the data block, and
      * adjust our ip_offset if the new payload size is different from what
      * it used to be.
      */
     if (ptag_hold && p->prev)      if (ptag_hold && p->prev)
     {      {
         p_temp = p->prev;          p_temp = p->prev;
Line 137  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l Line 130  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
         if (p_temp->type == LIBNET_PBLOCK_IPDATA)          if (p_temp->type == LIBNET_PBLOCK_IPDATA)
         {          {
             ptag_data = p_temp->ptag;              ptag_data = p_temp->ptag;
             offset -=  p_temp->b_len;  
             p->h_len += offset;  
         }          }
         else          else
         {          {
Line 147  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l Line 138  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
         }          }
     }      }
   
    if ((payload && !payload_s) || (!payload && payload_s))    if (payload_s && !payload)
     {      {
          snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,           snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
                  "%s(): payload inconsistency\n", __func__);                   "%s(): payload inconsistency\n", __func__);
         goto bad;          goto bad;
     }      }
   
    if (payload && payload_s)    if (payload_s)
     {      {
         /* update ptag_data with the new payload */          /* update ptag_data with the new payload */
           /* on create:
            *    b_len = payload_s
            *    l->total_size += b_len
            *    h_len = 0
            * on update:
            *    b_len = payload_s
            *    h_len += <diff in size between new b_len and old b_len>
            *      increments if if b_len goes up, down if it goes down
            * in either case:
            *    copied = 0
            */
         p_data = libnet_pblock_probe(l, ptag_data, payload_s,          p_data = libnet_pblock_probe(l, ptag_data, payload_s,
                 LIBNET_PBLOCK_IPDATA);                  LIBNET_PBLOCK_IPDATA);
         if (p_data == NULL)          if (p_data == NULL)
Line 171  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l Line 173  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
   
         if (ptag_data == LIBNET_PTAG_INITIALIZER)          if (ptag_data == LIBNET_PTAG_INITIALIZER)
         {          {
               /* IPDATA's h_len gets set to payload_s in both branches */
             if (p_data->prev->type == LIBNET_PBLOCK_IPV4_H)              if (p_data->prev->type == LIBNET_PBLOCK_IPV4_H)
             {              {
                 libnet_pblock_update(l, p_data, payload_s,                  libnet_pblock_update(l, p_data, payload_s,
Line 180  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l Line 183  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
             }              }
             else              else
             {              {
                   /* SR - I'm not sure how to reach this code. Maybe if the first
                    * time we added an ipv4 block, there was no payload, but when
                    * we modify the block the next time, we have payload?
                    */
   
                 /* update without setting this as the final pblock */                  /* update without setting this as the final pblock */
                 p_data->type  =  LIBNET_PBLOCK_IPDATA;                  p_data->type  =  LIBNET_PBLOCK_IPDATA;
                 p_data->ptag  =  ++(l->ptag_state);                  p_data->ptag  =  ++(l->ptag_state);
                p_data->h_len =  payload_s;                p_data->h_len =  payload_s; /* TODO dead code, data blocks don't have headers */
   
                 /* Adjust h_len for checksum. */  
                 p->h_len += payload_s;  
   
                 /* data was added after the initial construction */                  /* data was added after the initial construction */
                 for (p_temp = l->protocol_blocks;                  for (p_temp = l->protocol_blocks;
                         p_temp->type == LIBNET_PBLOCK_IPV4_H ||                          p_temp->type == LIBNET_PBLOCK_IPV4_H ||
Line 234  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l Line 239  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
         libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);          libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);
     }      }
   
     /*  
      * FREDRAYNAL: as we insert a new IP header, all checksums for headers  
      * placed after this one will refer to here.  
      */  
     libnet_pblock_record_ip_offset(l, l->total_size);  
   
     return (ptag);      return (ptag);
 bad:  bad:
     libnet_pblock_delete(l, p);      libnet_pblock_delete(l, p);
Line 247  bad: Line 246  bad:
 }  }
   
 libnet_ptag_t  libnet_ptag_t
libnet_autobuild_ipv4(u_int16_t len, u_int8_t prot, u_int32_t dst, libnet_t *l)libnet_autobuild_ipv4(uint16_t len, uint8_t prot, uint32_t dst, libnet_t *l)
 {  {
    u_int32_t n, i, j, src;    uint32_t n, i, j, src;
    u_int16_t h;    uint16_t h;
     libnet_pblock_t *p;      libnet_pblock_t *p;
     libnet_ptag_t ptag;      libnet_ptag_t ptag;
     struct libnet_ipv4_hdr ip_hdr;      struct libnet_ipv4_hdr ip_hdr;
Line 310  libnet_autobuild_ipv4(u_int16_t len, u_int8_t prot, u_ Line 309  libnet_autobuild_ipv4(u_int16_t len, u_int8_t prot, u_
     ip_hdr.ip_src.s_addr = src;                       /* source ip */      ip_hdr.ip_src.s_addr = src;                       /* source ip */
     ip_hdr.ip_dst.s_addr = dst;                       /* destination ip */      ip_hdr.ip_dst.s_addr = dst;                       /* destination ip */
   
    n = libnet_pblock_append(l, p, (u_int8_t *)&ip_hdr, LIBNET_IPV4_H);    n = libnet_pblock_append(l, p, (uint8_t *)&ip_hdr, LIBNET_IPV4_H);
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
Line 319  libnet_autobuild_ipv4(u_int16_t len, u_int8_t prot, u_ Line 318  libnet_autobuild_ipv4(u_int16_t len, u_int8_t prot, u_
     libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);      libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);
     ptag = libnet_pblock_update(l, p, LIBNET_IPV4_H, LIBNET_PBLOCK_IPV4_H);      ptag = libnet_pblock_update(l, p, LIBNET_IPV4_H, LIBNET_PBLOCK_IPV4_H);
   
     /*  
      * FREDRAYNAL: as we insert a new IP header, all checksums for headers  
      * placed after this one will refer to here.  
      */  
     libnet_pblock_record_ip_offset(l, l->total_size);  
     return (ptag);      return (ptag);
   
 bad:  bad:
Line 332  bad: Line 326  bad:
 }  }
   
 libnet_ptag_t  libnet_ptag_t
libnet_build_ipv4_options(u_int8_t *options, u_int32_t options_s, libnet_t *l, libnet_build_ipv4_options(const uint8_t *options, uint32_t options_s, libnet_t *l, 
 libnet_ptag_t ptag)  libnet_ptag_t ptag)
 {  {
    int offset, underflow;    int options_size_increase = 0; /* increase will be negative if it's a decrease */
    u_int32_t i, j, n, adj_size;    uint32_t n, adj_size;
     libnet_pblock_t *p, *p_temp;      libnet_pblock_t *p, *p_temp;
     struct libnet_ipv4_hdr *ip_hdr;      struct libnet_ipv4_hdr *ip_hdr;
   
Line 345  libnet_ptag_t ptag) Line 339  libnet_ptag_t ptag)
         return (-1);          return (-1);
     }      }
   
     underflow = 0;  
     offset = 0;  
   
     /* check options list size */      /* check options list size */
     if (options_s > LIBNET_MAXOPTION_SIZE)      if (options_s > LIBNET_MAXOPTION_SIZE)
     {      {
Line 369  libnet_ptag_t ptag) Line 360  libnet_ptag_t ptag)
         p_temp = libnet_pblock_find(l, ptag);          p_temp = libnet_pblock_find(l, ptag);
         if (p_temp)          if (p_temp)
         {          {
            if (adj_size >= p_temp->b_len)            options_size_increase = adj_size - p_temp->b_len;
            {                                    
                offset = adj_size - p_temp->b_len;                              
            } 
            else 
            {                                                            
                offset = p_temp->b_len - adj_size;                              
                underflow = 1; 
            } 
         }          }
         else  
         {  
             /*   
              * XXX - When this completes successfully, libnet errbuf contains   
              * an error message so to come correct, we'll clear it.  
              */   
             memset(l->err_buf, 0, sizeof (l->err_buf));  
         }  
     }      }
    /* If we aren't modifying an options block, we are pushing a new one, and
      * since it must be pushed before the IPv4 block is pushed, there is no
      * need to remember that options size has "increased".
      */
     
     /*      /*
      *  Find the existing protocol block if a ptag is specified, or create       *  Find the existing protocol block if a ptag is specified, or create
      *  a new one.       *  a new one.
Line 407  libnet_ptag_t ptag) Line 386  libnet_ptag_t ptag)
     }      }
   
     /* append padding */      /* append padding */
    n = libnet_pblock_append(l, p, "\0\0\0", adj_size - options_s);    n = libnet_pblock_append(l, p, (uint8_t*)"\0\0\0", adj_size - options_s);
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
Line 416  libnet_ptag_t ptag) Line 395  libnet_ptag_t ptag)
     if (ptag && p->next)      if (ptag && p->next)
     {      {
         p_temp = p->next;          p_temp = p->next;
         while ((p_temp->next) && (p_temp->type != LIBNET_PBLOCK_IPV4_H))  
         {  
             p_temp = p_temp->next;  
         }  
   
        /* fix the IP header size */        /* fix the IP header sizes */
         if (p_temp->type == LIBNET_PBLOCK_IPV4_H)          if (p_temp->type == LIBNET_PBLOCK_IPV4_H)
         {          {
             /*  
              *  Count up number of 32-bit words in options list, padding if  
              *  neccessary.  
              */  
             for (i = 0, j = 0; i < p->b_len; i++)  
             {  
                 (i % 4) ? j : j++;  
             }  
             ip_hdr = (struct libnet_ipv4_hdr *) p_temp->buf;              ip_hdr = (struct libnet_ipv4_hdr *) p_temp->buf;
            ip_hdr->ip_hl = j + 5;            ip_hdr->ip_hl = 5 + adj_size / 4; /* 4 bits wide, so no byte order concerns */
             ip_hdr->ip_len = htons(ntohs(ip_hdr->ip_len) + options_size_increase);
   
            if (!underflow)            p_temp->h_len = ip_hdr->ip_hl * 4; /* Dead code, h_len isn't used for IPv4 block */
            { 
                p_temp->h_len += offset; 
            } 
            else 
            { 
                p_temp->h_len -= offset; 
            } 
         }          }
     }      }
   
Line 454  bad: Line 415  bad:
 }  }
   
 libnet_ptag_t  libnet_ptag_t
libnet_build_ipv6(u_int8_t tc, u_int32_t fl, u_int16_t len, u_int8_t nh,libnet_build_ipv6(uint8_t tc, uint32_t fl, uint16_t len, uint8_t nh,
u_int8_t hl, struct libnet_in6_addr src, struct libnet_in6_addr dst, uint8_t hl, struct libnet_in6_addr src, struct libnet_in6_addr dst, 
u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
 {     {   
    u_int32_t n;    uint32_t n;
     libnet_pblock_t *p;      libnet_pblock_t *p;
     struct libnet_ipv6_hdr ip_hdr;      struct libnet_ipv6_hdr ip_hdr;
   
Line 487  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l Line 448  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
     }        }  
           
     memset(&ip_hdr, 0, sizeof(ip_hdr));      memset(&ip_hdr, 0, sizeof(ip_hdr));
    ip_hdr.ip_flags[0] = 0x06 << 4;    ip_hdr.ip_flags[0] = (0x06 << 4) | ((tc & 0xF0) >> 4);
     ip_hdr.ip_flags[1] = ((tc & 0x0F) << 4) | ((fl & 0xF0000) >> 16);      ip_hdr.ip_flags[1] = ((tc & 0x0F) << 4) | ((fl & 0xF0000) >> 16);
     ip_hdr.ip_flags[2] = fl & 0x0FF00 >> 8;      ip_hdr.ip_flags[2] = fl & 0x0FF00 >> 8;
     ip_hdr.ip_flags[3] = fl & 0x000FF;      ip_hdr.ip_flags[3] = fl & 0x000FF;
Line 497  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l Line 458  u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
     ip_hdr.ip_src      = src;      ip_hdr.ip_src      = src;
     ip_hdr.ip_dst      = dst;      ip_hdr.ip_dst      = dst;
             
    n = libnet_pblock_append(l, p, (u_int8_t *)&ip_hdr, LIBNET_IPV6_H);    n = libnet_pblock_append(l, p, (uint8_t *)&ip_hdr, LIBNET_IPV6_H);
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
    if ((payload && !payload_s) || (!payload && payload_s))    /* boilerplate payload sanity check / append macro */
    {    LIBNET_DO_PAYLOAD(l, p);
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, 
                 "%s(): payload inconsistency\n", __func__); 
        goto bad; 
    } 
  
    if (payload && payload_s) 
    {   
        n = libnet_pblock_append(l, p, payload, payload_s); 
        if (n == -1) 
        { 
            goto bad; 
        } 
    } 
   
     /* no checksum for IPv6 */      /* no checksum for IPv6 */
    return (ptag ? ptag : libnet_pblock_update(l, p, LIBNET_IPV6_H,    ptag = ptag ? ptag : libnet_pblock_update(l, p, LIBNET_IPV6_H,
            LIBNET_PBLOCK_IPV6_H));            LIBNET_PBLOCK_IPV6_H);
 
     return ptag;
 
 bad:  bad:
     libnet_pblock_delete(l, p);      libnet_pblock_delete(l, p);
     return (-1);      return (-1);
 }  }
   
 libnet_ptag_t  libnet_ptag_t
libnet_build_ipv6_frag(u_int8_t nh, u_int8_t reserved, u_int16_t frag,libnet_build_ipv6_frag(uint8_t nh, uint8_t reserved, uint16_t frag,
u_int32_t id, u_int8_t *payload, u_int32_t payload_s, libnet_t *l,uint32_t id, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
 libnet_ptag_t ptag)  libnet_ptag_t ptag)
 {  {
    u_int32_t n;    uint32_t n;
    u_int16_t h;    uint16_t h;
     libnet_pblock_t *p;      libnet_pblock_t *p;
     struct libnet_ipv6_frag_hdr ipv6_frag_hdr;      struct libnet_ipv6_frag_hdr ipv6_frag_hdr;
   
Line 571  libnet_ptag_t ptag) Line 522  libnet_ptag_t ptag)
     /*      /*
      *  Appened the protocol unit to the list.       *  Appened the protocol unit to the list.
      */       */
    n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_frag_hdr,    n = libnet_pblock_append(l, p, (uint8_t *)&ipv6_frag_hdr,
         LIBNET_IPV6_FRAG_H);          LIBNET_IPV6_FRAG_H);
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
    /*    /* boilerplate payload sanity check / append macro */
     *  Sanity check the payload arguments.    LIBNET_DO_PAYLOAD(l, p);
     */ 
    if ((payload && !payload_s) || (!payload && payload_s)) 
    { 
        sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__); 
        goto bad; 
    } 
   
     /*      /*
      *  Append the payload to the list if it exists.  
      */  
     if (payload && payload_s)  
     {  
         n = libnet_pblock_append(l, p, payload, payload_s);  
         if (n == -1)  
         {  
             goto bad;  
         }  
     }  
   
     /*  
      *  Update the protocol block's meta information and return the protocol       *  Update the protocol block's meta information and return the protocol
      *  tag id of this pblock.  This tag will be used to locate the pblock       *  tag id of this pblock.  This tag will be used to locate the pblock
      *  in order to modify the protocol header in subsequent calls.       *  in order to modify the protocol header in subsequent calls.
Line 612  bad: Line 545  bad:
 }  }
   
 libnet_ptag_t  libnet_ptag_t
libnet_build_ipv6_routing(u_int8_t nh, u_int8_t len, u_int8_t rtype, libnet_build_ipv6_routing(uint8_t nh, uint8_t len, uint8_t rtype, 
u_int8_t segments, u_int8_t *payload, u_int32_t payload_s, libnet_t *l,uint8_t segments, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
 libnet_ptag_t ptag)  libnet_ptag_t ptag)
 {  {
    u_int32_t n;    uint32_t n;
    u_int16_t h;    uint16_t h;
     libnet_pblock_t *p;      libnet_pblock_t *p;
     struct libnet_ipv6_routing_hdr ipv6_routing_hdr;      struct libnet_ipv6_routing_hdr ipv6_routing_hdr;
   
Line 658  libnet_ptag_t ptag) Line 591  libnet_ptag_t ptag)
     /*      /*
      *  Appened the protocol unit to the list.       *  Appened the protocol unit to the list.
      */       */
    n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_routing_hdr,    n = libnet_pblock_append(l, p, (uint8_t *)&ipv6_routing_hdr,
         LIBNET_IPV6_ROUTING_H);          LIBNET_IPV6_ROUTING_H);
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
    /*    /* boilerplate payload sanity check / append macro */
     *  Sanity check the payload arguments.    LIBNET_DO_PAYLOAD(l, p);
     */ 
    if ((payload && !payload_s) || (!payload && payload_s)) 
    { 
        sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__); 
        goto bad; 
    } 
   
     /*      /*
      *  Append the payload to the list if it exists.  
      */  
     if (payload && payload_s)  
     {  
         n = libnet_pblock_append(l, p, payload, payload_s);  
         if (n == -1)  
         {  
             goto bad;  
         }  
     }  
   
     /*  
      *  Update the protocol block's meta information and return the protocol       *  Update the protocol block's meta information and return the protocol
      *  tag id of this pblock.  This tag will be used to locate the pblock       *  tag id of this pblock.  This tag will be used to locate the pblock
      *  in order to modify the protocol header in subsequent calls.       *  in order to modify the protocol header in subsequent calls.
Line 699  bad: Line 614  bad:
 }  }
   
 libnet_ptag_t  libnet_ptag_t
libnet_build_ipv6_destopts(u_int8_t nh, u_int8_t len, u_int8_t *payload,libnet_build_ipv6_destopts(uint8_t nh, uint8_t len, const uint8_t *payload,
u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
 {  {
    u_int32_t n;    uint32_t n;
    u_int16_t h;    uint16_t h;
     libnet_pblock_t *p;      libnet_pblock_t *p;
     struct libnet_ipv6_destopts_hdr ipv6_destopts_hdr;      struct libnet_ipv6_destopts_hdr ipv6_destopts_hdr;
   
Line 742  u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) Line 657  u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
     /*      /*
      *  Appened the protocol unit to the list.       *  Appened the protocol unit to the list.
      */       */
    n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_destopts_hdr,    n = libnet_pblock_append(l, p, (uint8_t *)&ipv6_destopts_hdr,
         LIBNET_IPV6_DESTOPTS_H);          LIBNET_IPV6_DESTOPTS_H);
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
    /*    /* boilerplate payload sanity check / append macro */
     *  Sanity check the payload arguments.    LIBNET_DO_PAYLOAD(l, p);
     */ 
    if ((payload && !payload_s) || (!payload && payload_s)) 
    { 
        sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__); 
        goto bad; 
    } 
   
     /*      /*
      *  Append the payload to the list if it exists.  
      */  
     if (payload && payload_s)  
     {  
         n = libnet_pblock_append(l, p, payload, payload_s);  
         if (n == -1)  
         {  
             goto bad;  
         }  
     }  
   
     /*  
      *  Update the protocol block's meta information and return the protocol       *  Update the protocol block's meta information and return the protocol
      *  tag id of this pblock.  This tag will be used to locate the pblock       *  tag id of this pblock.  This tag will be used to locate the pblock
      *  in order to modify the protocol header in subsequent calls.       *  in order to modify the protocol header in subsequent calls.
Line 783  bad: Line 680  bad:
 }  }
   
 libnet_ptag_t  libnet_ptag_t
libnet_build_ipv6_hbhopts(u_int8_t nh, u_int8_t len, u_int8_t *payload,libnet_build_ipv6_hbhopts(uint8_t nh, uint8_t len, const uint8_t *payload,
u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
 {  {
    u_int32_t n;    uint32_t n;
    u_int16_t h;    uint16_t h;
     libnet_pblock_t *p;      libnet_pblock_t *p;
     struct libnet_ipv6_hbhopts_hdr ipv6_hbhopts_hdr;      struct libnet_ipv6_hbhopts_hdr ipv6_hbhopts_hdr;
   
Line 826  u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) Line 723  u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
     /*      /*
      *  Appened the protocol unit to the list.       *  Appened the protocol unit to the list.
      */       */
    n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_hbhopts_hdr,    n = libnet_pblock_append(l, p, (uint8_t *)&ipv6_hbhopts_hdr,
         LIBNET_IPV6_HBHOPTS_H);          LIBNET_IPV6_HBHOPTS_H);
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
    /*    /* boilerplate payload sanity check / append macro */
     *  Sanity check the payload arguments.    LIBNET_DO_PAYLOAD(l, p);
     */ 
    if ((payload && !payload_s) || (!payload && payload_s)) 
    { 
        sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__); 
        goto bad; 
    } 
   
     /*      /*
      *  Append the payload to the list if it exists.  
      */  
     if (payload && payload_s)  
     {  
         n = libnet_pblock_append(l, p, payload, payload_s);  
         if (n == -1)  
         {  
             goto bad;  
         }  
     }  
   
     /*  
      *  Update the protocol block's meta information and return the protocol       *  Update the protocol block's meta information and return the protocol
      *  tag id of this pblock.  This tag will be used to locate the pblock       *  tag id of this pblock.  This tag will be used to locate the pblock
      *  in order to modify the protocol header in subsequent calls.       *  in order to modify the protocol header in subsequent calls.
Line 867  bad: Line 746  bad:
 }  }
   
 libnet_ptag_t  libnet_ptag_t
libnet_autobuild_ipv6(u_int16_t len, u_int8_t nh, struct libnet_in6_addr dst,libnet_autobuild_ipv6(uint16_t len, uint8_t nh, struct libnet_in6_addr dst,
            libnet_t *l)            libnet_t *l, libnet_ptag_t ptag)
 {  {
       struct libnet_in6_addr src;
   
    /* NYI */    src = libnet_get_ipaddr6(l);
     snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
             "%s(): not yet implemented\n", __func__);    if (libnet_in6_is_error(src))
    return (-1);    {
         return (-1);
     }
 
     return libnet_build_ipv6(0, 0, len, nh, 64, src, dst, NULL, 0, l, ptag);
 }  }
   
 /* EOF */  

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>