/*
 * author: Darren Bounds <dbounds@intrusense.com>
 * copyright: Copyright (C) 2002 by Darren Bounds
 * license: This software is under GPL version 2 of license
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * packit official page at http://packit.sourceforge.net
 */

#ifndef _PACKIT_HEADERS
#define _PACKIT_HEADERS

#define PACKIT_ARP_H             0x1c    /* ARP header:          28 bytes */
#define PACKIT_DNS_H             0xc     /* DNS header base:     12 bytes */
#define PACKIT_ETH_H             0xe     /* Etherner header:     14 bytes */
#define PACKIT_ICMPV4_H          0x4     /* ICMP header base:     4 bytes */
#define PACKIT_ICMPV6_H          0x08    /* ICMP6 header base:    8 bytes */
#define PACKIT_ICMPV4_ECHO_H     0x8     /* ICMP_ECHO header:     8 bytes */
#define PACKIT_ICMPV4_MASK_H     0xc     /* ICMP_MASK header:    12 bytes */
#define PACKIT_ICMPV4_UNREACH_H  0x8     /* ICMP_UNREACH header:  8 bytes */
#define PACKIT_ICMPV4_TIMXCEED_H 0x8     /* ICMP_TIMXCEED header: 8 bytes */
#define PACKIT_ICMPV4_REDIRECT_H 0x8     /* ICMP_REDIRECT header: 8 bytes */
#define PACKIT_ICMPV4_TS_H       0x14    /* ICMP_TIMESTAMP headr:20 bytes */
#define PACKIT_IPV4_H            0x14    /* IP header:           20 bytes */
#define PACKIT_IPV6_H            0x28    /* IPv6 header:         40 bytes */
#define PACKIT_TCP_H             0x14    /* TCP header:          20 bytes */
#define PACKIT_UDP_H             0x8     /* UDP header:           8 bytes */

#endif /* _PACKIT_HEADERS */

#define BURST_MAX		 10000   /* packet warfare is never a good idea :( */

#define IPV4_DEFAULT		 "0.0.0.0"
#define IPV4_BROADCAST           "255.255.255.255"
#define MASK_DEFAULT		 "255.255.255.0"
#define ETH_DEFAULT 		 "0:0:0:0:0:0"
#define ETH_BROADCAST		 "ff:ff:ff:ff:ff:ff"

unsigned short injection_type;
unsigned short interval;

char *s_dport;

unsigned short rand_dport;
unsigned short rand_sport;
unsigned short sport;
int dport;

int burst;

int payload_len;
char *payload;

unsigned char hwaddr_p[17];

struct ip4hdr_opts
{
    unsigned short ip_proto;         /* layer 3 protocol */		
    unsigned short ip_version;		/* ip version */
    unsigned short ip_frag;		/* fragment option */

    unsigned short ip_rand_id;          /* random ip id */
    unsigned short ip_rand_saddr;       /* random source address flag */ 
    unsigned short ip_rand_daddr; 	/* random destination address flag */

    char *ip_saddr;                     /* src address string */
    char *ip_daddr;                     /* dst address string */
    unsigned long ipn_saddr; 		/* src address network byte order */ 
    unsigned long ipn_daddr; 		/* dst address network byte order */

    unsigned long ip_tos;               /* type of service */
    unsigned short ip_id;    		/* id number */
    unsigned short ip_ttl;	 	/* time to live */
    unsigned short ip_sum;              /* checksum */
} ip4hdr_o;

struct tcphdr_opts
{
    unsigned short th_rand_seqn;	/* random sequence number (default) */

    unsigned short th_urg;		/* tcp urg flag */
    unsigned short th_ack;		/* tcp ack flag */ 
    unsigned short th_psh;		/* tcp psh flag */
    unsigned short th_rst;		/* tcp rst flag */
    unsigned short th_syn;		/* tcp syn flag */
    unsigned short th_fin;		/* tcp fin flag */

    unsigned short th_urp;		/* tcp urg pointer */
    unsigned short th_win; 		/* tcp window size */	
    unsigned long th_ackn;		/* tcp ack number */
    unsigned long th_seqn;		/* tcp seq number */
} thdr_o;

struct udphdr_opts
{
    unsigned short uh_sum;     		/* udp checksum */
} uhdr_o;

struct icmp4hdr_opts
{
    unsigned short ih_type;    		/* icmp4 type */
    unsigned short ih_code;		/* icmp4 code */ 

    unsigned short ih_id;		/* icmp4 id */ 
    unsigned short ih_seq;              /* icmp4 seq */
    
    unsigned short ih_rand_saddr;      
    unsigned short ih_rand_daddr;
    unsigned short ih_rand_gw;

    char *ih_gw;                        /* new gateway (redirect only) */

    unsigned short ih_ttl;		/* original ttl */
    unsigned short ih_sum;		/* original checksum */
    unsigned short ih_proto;            /* original protocol */
    unsigned int ih_tos;                /* original type of service */

    char *ih_saddr;                     /* original source address */
    unsigned short ih_sport;	        /* original source port */    
    char *ih_daddr;                     /* original destination address */
    unsigned short ih_dport;            /* original destination port */

    char *ih_mask;			/* icmp4 mask */

    unsigned long ih_otime;             /* original timestamp */
    unsigned long ih_rtime;             /* recieved timestamp */
    unsigned long ih_ttime;             /* transmit timestamp */
} i4hdr_o;

struct enethdr_opts
{
    unsigned short eh_rand_saddr;
    unsigned short eh_rand_daddr;

    char *s_addr;			/* source ethernet address string */
    char shw_addr[17];
    char *d_addr; 	  		/* destination ethernet address string */
    char dhw_addr[17];
} ehdr_o; 

struct arphdr_opts
{
    unsigned short ah_rand_s_paddr;
    unsigned short ah_rand_r_paddr;
    unsigned short ah_rand_s_eaddr;
    unsigned short ah_rand_r_eaddr;
    
    unsigned short optype;              /* arp operation */
    
    char *s_paddr;                      /* sender protocol address */
    char *r_paddr;                      /* receiver protocol address */

    char *s_eaddr;                      /* sender ethernet address */
    char shw_addr[17];
    char *r_eaddr;                      /* receiver ethernet address */
    char rhw_addr[17];
} ahdr_o;

#ifndef _INJECT_FUNC
#define _INJECT_FUNC

void            injection_stats();
void            injection_clean_exit(int sig);
void 		print_injection(short init_type, unsigned int p_count);
int		parse_port_range(char *rangestr);
int             format_ethernet_addr(char *ethstr, unsigned char u_eaddr[6]);
unsigned char * format_dhcpv4_options();
unsigned char * retrieve_rand_ipv4_addr();
unsigned char * retrieve_rand_ethernet_addr();
libnet_t *	build_ethernet_hdr(libnet_t *packet_d);
libnet_t *	build_ethernet_hdr_auto(libnet_t *packet_d);
libnet_t *	build_arp_hdr(libnet_t *packet_d);
libnet_t * 	build_ipv4_hdr(libnet_t *packet_d);
libnet_t *	build_tcp_hdr(libnet_t *packet_d);
libnet_t *	build_udp_hdr(libnet_t *packet_d);
libnet_t *	build_icmpv4_hdr(libnet_t *packet_d);
libnet_t *	build_dhcpv4_hdr(libnet_t *packet_d);

#endif /* _INJECT_FUNC */
