资源简介
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系统登陆用户名
相关资源
- 兰勃托地图投影VC源码
- 易语言zc源码易语言收银系统源码易语
- 易语言C源码易语言S源码易语言远程控
- zlc源码众利模式.zip
- nc源码含unix、windows版本
- STM 32 仿三菱PLC源码
- 串口调试助手VC源码
- 基于51单片机的智能抢答器+C源码+原理
- 车型识别系统vc源码opencv
- cc攻击源码
- 运动车辆检测跟踪系统vc源码opencv
- SM9算法测试VC项目源码
- 基于LIS3DH的简易倾角仪C源码
- 车牌识别系统vc源码基于opencv
- ASN1编码文档及ASN1C源码例程
- 基于RFID的学生门禁系统C源码、说明文
- 指纹提取与识别系统VC源码opencv
- 春彩SSC源码带后台和开奖.zip
- swapIDC源码破解官方限制
- lis3dh三轴传感器计步实现C源码
- 开源商城B2B2C源码
- windows高级编程指南中文版+25个c源码案
- BrnShop开源网上商城2.1版本源码已改为
- MVC源码完整版
- 编译好的libflac源码
- 区块链挖矿gec源码二开修复无后门版
- 磁盘分区隐藏 vc源码
- 传奇脱机挂VC源码.rar
- keeloq_C源码,包含3种加密方式的解码
- 串口调试助手[VC源码]
评论
共有 条评论