资源简介
DNS解析,gethostbyname的C源码
本人已经测试过,可以用。没有的话可以喷我。
代码片段和文件信息
//DNS Query Program
//Author : Prasshhant Pugalia (prasshhant.p@gmail.com)
//Dated : 26/2/2007
//Header Files
#include “winsock2.h“
#include “windows.h“
#include “stdio.h“
#include “conio.h“
#pragma comment(lib“ws2_32.lib“) //Winsock Library
//List of DNS Servers registered on the system
char dns_servers[10][100];
//Type field of Query and Answer
#define T_A 1 /* host address */
#define T_NS 2 /* authoritative server */
#define T_CNAME 5 /* canonical name */
#define T_SOA 6 /* start of authority zone */
#define T_PTR 12 /* domain name pointer */
#define T_MX 15 /* mail routing information */
//Function Prototypes
void ngethostbyname (unsigned char*);
void ChangetoDnsNameFormat (unsigned char*unsigned char*);
unsigned char* ReadName (unsigned char*unsigned char*int*);
void RetrieveDnsServersFromRegistry(void);
unsigned char* PrepareDnsQueryPacket (unsigned char*);
//DNS header structure
struct DNS_HEADER
{
unsigned short id; // identification number
unsigned char rd :1; // recursion desired
unsigned char tc :1; // truncated message
unsigned char aa :1; // authoritive answer
unsigned char opcode :4; // purpose of message
unsigned char qr :1; // query/response flag
unsigned char rcode :4; // response code
unsigned char cd :1; // checking disabled
unsigned char ad :1; // authenticated data
unsigned char z :1; // its z! reserved
unsigned char ra :1; // recursion available
unsigned short q_count; // number of question entries
unsigned short ans_count; // number of answer entries
unsigned short auth_count; // number of authority entries
unsigned short add_count; // number of resource entries
};
//Constant sized fields of query structure
struct QUESTION
{
unsigned short qtype;
unsigned short qclass;
};
//Constant sized fields of the resource record structure
#pragma pack(push 1)
struct R_DATA
{
unsigned short type;
unsigned short _class;
unsigned int ttl;
unsigned short data_len;
};
#pragma pack(pop)
//Pointers to resource record contents
struct RES_RECORD
{
unsigned char *name;
struct R_DATA *resource;
unsigned char *rdata;
};
//Structure of a Query
typedef struct
{
unsigned char *name;
struct QUESTION *ques;
} QUERY;
int main() //do you know what is int main() ?
{
unsigned char hostname[100];
WSADATA firstsock;
RetrieveDnsServersFromRegistry();
printf(“\nInitialising Winsock...“);
if (WSAStartup(MAKEWORD(22)&firstsock) != 0)
{
printf(“Failed. Error Code : %d“WSAGetLastError());
return 1;
}
printf(“Initialised.“);
printf(“\nEnter Hostname to Lookup : “);
gets((char*)hostname);
ngethostbyname(hostname);
_getch();
return 0;
}
void ngethostbyname(unsigned char *host)
{
unsigne
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 11388 2007-07-24 12:21 main.c
文件 4286 2007-02-26 20:50 dns.dsp
文件 531 2007-02-26 19:54 dns.dsw
- 上一篇:热敏打印机图形生成工具
- 下一篇:如何获取Windows系统登陆用户名
相关资源
- PGP加密源程序C源码
- 51单片机的步进电机控制,lcd1602显示
- 捆绑文件异步同步操作vc源码
- 成绩管理系统源码
- stm32 spi方式读写EEPROM
- DTW算法C源码语音识别算法
- G.729的编解码C源码(使用Intel的IPP包)
- μCOS-II中OS_TASK.C源码中文注释版
- 瑞士军刀NC源码
- 华中科技大学编译原理实验yacc源码
- 网际校验和算法VC源码
- Win7进程注入绕UAC源码
- uCOS-II移植到PC源码uCOS-II版本v2.91.zip
- webrtc中AEC代码解读.zip
- TEQC_Win源码
- malloc的实现源码
- 操作系统课设银行家算法(C源码+报告
- FX2N-HT32源码+sch+pcbKeil4/5/STM32/FX2N/PLC源
- XMODEM程序VC源码
- DSP28335的I2C源码
- Google的word2vec源码
- 遗传算法 vc源码
- 凸轮课程设计c源码
- PFC源码 基于dspic30F
- D2hackmap1.13c源码
- 自写的完整SIP协议栈c源码,编译后即
- 国外开源plc源码
- 图像识别遥感图像配准系统VC源码op
- STM32F103 IIC源码
评论
共有 条评论