home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / fragrouter / Libnet-0.99b / src / build_ip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-26  |  2.8 KB  |  72 lines

  1. /*
  2.  *  $Id: build_ip.c,v 1.1.1.1 1999/05/18 15:33:42 dugsong Exp $
  3.  *
  4.  *  libnet
  5.  *  build_ip.c - IP packet assembler
  6.  *
  7.  *  Copyright (c) 1998, 1999 Mike D. Schiffman <mike@infonexus.com>
  8.  *                           route|daemon9 <route@infonexus.com>
  9.  *  All rights reserved.
  10.  *
  11.  * Redistribution and use in source and binary forms, with or without
  12.  * modification, are permitted provided that the following conditions
  13.  * are met:
  14.  * 1. Redistributions of source code must retain the above copyright
  15.  *    notice, this list of conditions and the following disclaimer.
  16.  * 2. Redistributions in binary form must reproduce the above copyright
  17.  *    notice, this list of conditions and the following disclaimer in the
  18.  *    documentation and/or other materials provided with the distribution.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  21.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  24.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30.  * SUCH DAMAGE.
  31.  *
  32.  */
  33.  
  34. #if (HAVE_CONFIG_H)
  35. #include "../include/config.h"
  36. #endif
  37. #include "../include/libnet.h"
  38.  
  39. void
  40. build_ip(u_short len, u_char tos, u_short id, u_short frag, u_char ttl,
  41.         u_char prot, u_long src, u_long dst, const u_char *payload,
  42.         int payload_s, u_char *buf)
  43. {
  44.     struct ip ip_hdr;
  45.  
  46.     assert(buf);
  47.  
  48.     ip_hdr.ip_v    = 4;                            /* version 4 */
  49.     ip_hdr.ip_hl   = 5;                            /* 20 byte header */
  50.     ip_hdr.ip_tos  = tos;                          /* IP tos */
  51.     ip_hdr.ip_len  = htons(IP_H + len);            /* total length */
  52.     ip_hdr.ip_id   = htons(id);                    /* IP ID */
  53.     ip_hdr.ip_off  = htons(frag);                  /* fragmentation flags */
  54.     ip_hdr.ip_ttl  = ttl;                          /* time to live */
  55.     ip_hdr.ip_p    = prot;                         /* transport protocol */
  56.     ip_hdr.ip_sum  = 0;                            /* do this later */
  57.     ip_hdr.ip_src.s_addr = src;
  58.     ip_hdr.ip_dst.s_addr = dst;
  59.     if (payload && payload_s)
  60.     {
  61.         /*
  62.          *  Unchecked runtime error for buf + IP_H + payload to be greater than
  63.          *  the allocated heap memory.
  64.          */
  65.         memcpy(buf + IP_H, payload, payload_s);
  66.     }
  67.     memcpy((u_char *)buf, (u_char *)&ip_hdr, sizeof(ip_hdr));
  68. }
  69.  
  70.  
  71. /* EOF */
  72.