c语言无线网络抓包程序,C语言网络抓包程序

#include

#include

#include

#include

#include

#include

#include

#define MAX_HOSTNAME_LAN 255

#define SIO_RCVALL _WSAIOW(IOC_VENDOR,1)

#define MAX_ADDR_LEN 16

#pragma comment(lib,"WS2_32.lib")

typedef struct tcpheader

{

unsigned short int sport; //source address

unsigned short int dport; //destination address

unsigned int th_seq; //sequence number

unsigned int th_ack; //acknowledge number

unsigned char th_x2:4; //header length

unsigned char th_off:4; //reserved

unsigned char th_flag; //flags: URG ACK PSH RST SYN FIN

unsigned short int th_win; //window size

unsigned short int th_sum; //check sum

unsigned short int th_urp; //urgent pointer

}TCP_HDR;

struct ipheader

{

unsigned char h_lenver; //version & header length

unsigned char ip_tos; //tos

unsigned short int ip_len; //total length

unsigned short int ip_id; //id

unsigned short int ip_off; //offset

unsigned char ip_ttl; //time to live

unsigned char ip_p; //protocal

unsigned short int ip_sum; //check sum

unsigned int ip_src; //source address

unsigned int ip_dst; //destination address

}IP_HDR;

typedef struct udphdr

{

unsigned short sport; //source port

unsigned short dport; //destination port

unsigned short len; //UDP length

unsigned short cksum; //check sum(include data)

} UDP_HDR;

typedef struct icmphdr

{

unsigned short sport;

unsigned short dport;

BYTE i_type;

BYTE i_code;

USHORT i_cksum;

USHORT i_id;

USHORT i_seq;

ULONG timestamp;

}ICMP_HDR;

void main()

{

SOCKET sock;

WSADATA wsd;

char RecvBuf[65535] = {0};

char entity_content[65535]={0};

char temp[65535]= {0};

DWORD dwBytesRet;

int pCount=0;

unsigned int optval = 1; //the pointer , which shows us the payload begin

unsigned char *dataip=NULL;

unsigned char *datatcp=NULL; //the pointer , which shows us the payload begin

unsigned char *dataudp=NULL;

unsigned char *dataicmp=NULL;

int lentcp=0, lenudp,lenicmp,lenip;

int k;

char TcpFlag[6]={'F','S','R','P','A','U'}; //定义TCP的标志位

WSAStartup(MAKEWORD(2,1),&wsd);

if((sock = socket(AF_INET, SOCK_RAW, IPPROTO_IP))==SOCKET_ERROR)

{

exit(0);

}

char FAR name[MAX_HOSTNAME_LAN];

gethostname(name, MAX_HOSTNAME_LAN);

struct hostent FAR * pHostent;

pHostent = (struct hostent * )malloc(sizeof(struct hostent));

pHostent = gethostbyname(name);

SOCKADDR_IN sa;

sa.sin_family = AF_INET;

sa.sin_port = htons(6000);

m

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值