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

📄 dns_v1.h

📁 我自己用C写的客户端组包发送DNS报文的小程序
💻 H
字号:
#include <winsock.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
#include <Winbase.h>
#include <math.h>
#pragma comment(lib,"Ws2_32.lib")
#pragma     once   


//接收数据,缓冲区   
static const int RecvBufSize = 4086;   

struct SEND_PACKAGE   
{                     
	char* pData;                                    
	int iDataLen;   
};   

static const USHORT   DNS_FLAG_QR = 0x8000;   
static const USHORT   DNS_FLAG_AA = 0x0400;   
static const USHORT   DNS_FLAG_TC = 0x0200;   
static const USHORT   DNS_FLAG_RD = 0x0100;   
static const USHORT   DNS_FLAG_RA = 0x0080;   
static const USHORT   DNS_HEAD_SIZE = 12;   

static const USHORT   DNS_RRTYPE_A = 1;   
static const USHORT   DNS_RRTYPE_NS = 2;   
static const USHORT   DNS_RRTYPE_CNAME = 5;   
static const USHORT   DNS_RRTYPE_SOA = 6;   
static const USHORT   DNS_RRTYPE_WKS = 11;   
static const USHORT   DNS_RRTYPE_PTR = 12;   
static const USHORT   DNS_RRTYPE_HINFO = 13;   
static const USHORT   DNS_RRTYPE_MX = 15;   
static const USHORT   DNS_TAIL_SIZE = 4;   

struct DNS_REQUEST_HEAD   
{   
	USHORT usSessionID;   
	USHORT usFlag;     
	USHORT usQuestions;   
	USHORT usAnswer;   
	USHORT usAuthority;    
	USHORT usAdditional;   
};  
 
struct DNS_REQUEST_TAIL   
{   
	USHORT   usRequestType;   
	USHORT   usRequestClass;   
};

bool getDomainIP(const char*, char*, int &);     

//根据输入的DomainStr   得到一个StrArray   
void getArrayByDomainStr(const char*, int &);   

//组织一个请求Domain   IP的包包   
void getPackageRequestIP(SEND_PACKAGE &, const char*, int &);   

//解析一个RequestReply的包包   
void processRequestReply(char* );   

//发送一个包包,删除包包的内容   
bool sendDestPackage(   
					 const SOCKET sockLocal,   
					 const SOCKADDR_IN saDest,   
					 SEND_PACKAGE &sendPackage,   
					 const USHORT usSendTimes = 1   
					 ); 
  
//sigh,show   
void HexDump(const unsigned char *, int);
bool initLocalSocket(); 
static UINT ThreadRecvData(LPVOID pParam);    //接收数据的线程  

⌨️ 快捷键说明

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