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

📄 ip_gen.c

📁 示范了Unix和Linux下如何利用Raw Socket构造伪装的TCP、IP、UDP的包
💻 C
字号:
/* RAW socket utility routine: *  * Write out an IP header. * shadows@whitefang.com * Thamer Al-Herbish */#include <stdlib.h>#include <stdio.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netinet/in_systm.h>#include <netinet/ip.h>#include <unistd.h>#include <string.h>#if !defined(HAVE_INCKSUM)#include <checksum.h>#endif#if !defined(IPVERSION)#define IPVERSION 4  /* Incase some system does not have this definition. */#endif               /* We'll always be using 4 as the version anyway. */#define DEFAULT_TTL 60  /* Just hard code the ttl in the ip header.*/void ip_gen(char *packet,unsigned char protocol,struct in_addr saddr,	    struct in_addr daddr,unsigned short length){#if !defined(LINUX)  struct ip *iphdr;#else  struct iphdr *iphdr;#endif /* LINUX */#if !defined(LINUX)  iphdr = (struct ip *)packet;  memset((char *)iphdr,'\0',sizeof(struct ip));    iphdr->ip_hl = 5;  iphdr->ip_v = IPVERSION;  #ifdef IP_LEN_HORDER  iphdr->ip_len = length;#else  iphdr->ip_len = htons(length);#endif /* IP_LEN_HORDER */  iphdr->ip_id = htons(getpid());  iphdr->ip_ttl = DEFAULT_TTL;  iphdr->ip_p = protocol;  iphdr->ip_src = saddr;  iphdr->ip_dst = daddr;    iphdr->ip_sum = (unsigned short)in_cksum((unsigned short *)iphdr,					   sizeof(struct ip));  #else /* LINUX */    iphdr = (struct iphdr *)packet;  memset((char *)iphdr,'\0',sizeof(struct iphdr));    iphdr->ihl = 5;  iphdr->version = IPVERSION;    #ifdef IP_LEN_HORDER  iphdr->tot_len = length;#else  iphdr->tot_len = htons(length);#endif /* IP_LEN_HORDER */    iphdr->id = htons(getpid());  iphdr->ttl = DEFAULT_TTL;  iphdr->protocol = protocol;  iphdr->saddr = saddr.s_addr;  iphdr->daddr = daddr.s_addr;  iphdr->check = (unsigned short)in_cksum((unsigned short *)iphdr,					  sizeof(struct iphdr));#endif /* LINUX */  return;}

⌨️ 快捷键说明

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