QQicmp之源代码如下:#include
#include
#include
#include
#define maxsize 64*1024typedef struct ipheader
{
unsigned char h_lenver;
unsigned char tos;
unsigned short total_len;
unsigned short ident;
unsigned short frag_and_flags;
unsigned char ttl;
unsigned char proto;
unsigned short checksum;
unsigned int sourceip;
unsigned int destip;
}ipheader;typedef struct icmpheader
{
unsigned char type;
unsigned char code;
unsigned short checksum;
unsigned short seq;
unsigned short id;
}icmpheader;unsigned short checksum(unsigned short *buffer,int size)
{
unsigned long cksum=0;
while(size>0)
{
cksum =*buffer;
size-=sizeof(unsigned short);
}
if(size)
cksum =*(unsigned char *)buffer;
cksum=(cksum>>16) (cksum & 0xffff);
cksum =(cksum>>16);
return (unsigned short)(~cksum);
}void start()
{
cout<<" ---------------------------------------------------n";
cout<<" || || n";
cout<<" || QQicmp (ICMP转发) || n";
cout<<" || || n";
cout<<" || Author:TOo2y SafeChina || n";
cout<<" || || n";
cout<<" ---------------------------------------------------"<
{
cout<<"nUsage:rntQQicmp -l[-g] ip port"<
cout<<"tQQicmp -l 192.168.0.1 8000"<
SOCKET sock[2][2];
struct sockaddr_in sin[2][4],sag,sal,tempr,temps;DWORD WINAPI u2i(LPVOID num)
{
UNREFERENCED_PARAMETER(num);
char msgrecv[maxsize]={0},msgsend[maxsize]={0};
fd_set fdread,fdwrite;
int iret,ret,istbcs=0;
struct icmpheader icmphdr;memset(&icmphdr,0,sizeof(icmphdr));
icmphdr.code=0;
icmphdr.id=htons(65456);
icmphdr.seq=htons(65456);
icmphdr.type=0;
icmphdr.checksum=checksum((unsigned short *)&icmphdr,sizeof(icmphdr));if((sock[0][1]=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP))==INVALID_SOCKET)
{
cout<<"Socket sock[0][1] Error: "<
}
if(bind(sock[0][1],(struct sockaddr *)&sin[0][2],addrlen)==SOCKET_ERROR)
{
cout<<"Bind sock[0][1] Error: "<
}while(1)
{
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_SET(sock[0][0],&fdread);
FD_SET(sock[0][1],&fdwrite);if((ret=select(0,&fdread,&fdwrite,NULL,NULL))==SOCKET_ERROR)
{
cout<<"Select in thread 0 Error: "<
}
if(ret>0)
{
if(FD_ISSET(sock[0][0],&fdread))
{
iret=recvfrom(sock[0][0],msgrecv,sizeof(msgrecv),0,(struct sockaddr *)&tempr,&addrlen);
if(iret==SOCKET_ERROR)
{
cout<<"nRecvfrom sock[0][0] Error: "<
}
else if(iret==0)
{
cout<<"Iret==0"<
}
cout<<"nThread 0 Recv "<
{
memset(msgsend,0,sizeof(msgsend));
memcpy(msgsend,&icmphdr,sizeof(icmphdr));
istbcs =sizeof(icmphdr);
}
memcpy(msgsend istbcs,msgrecv,iret);
istbcs =iret;
memset(msgrecv,0,sizeof(msgrecv));
}
else if(FD_ISSET(sock[0][1],&fdwrite))
{while(istbcs>0)
{if(sin[0][3].sin_addr.s_addr==htonl(0))
{
cout<<"sin[0][3].sin_addr.s_addr==htonl(0)"<
memset(msgsend,0,sizeof(msgsend));
break;
}iret=sendto(sock[0][1],msgsend,istbcs,0,(struct sockaddr *)&sin[0][3],addrlen);
if(iret==SOCKET_ERROR)
{
cout<<"Sendto sock[0][1] Error: "<
}
cout<<"Thread 0 send "
推荐阅读
- 英华OK OK318短信功能篇
- K750C试飞之无限连接篇
- 小汇m66的缺点
- 商务伴侣,影音随行--A100之手写篇
- A728试飞手记-屏幕篇:效果与保护
- 商务伴侣,影音随行--A100之缺憾篇
- 东信ES1009试飞手记——资料初识篇
- 诺基亚6030购买使用感受
- 软件篇 索尼爱立信J300C评测
- 东信ES1009试飞手记——ES1009与A780资料对比篇