DNS解析API文档

DNS 解析 API 文档

参考英文文档:

http://docstore.mik.ua/orelly/networking_2ndEd/dns/ch15_02.htm

http://www.opensource.apple.com/source/libresolv/libresolv-46/ns_name.c


一.工具函数集合

(1)int ns_name_ntop(const u_char *src, char *dst, size_t dstsiz)

功能: 该函数将网络域名格式【eg:3www5baidu3com0】转换为通常类型的域名格式【www.baidu.com】
返回:写到buffer中的字节数,如果失败返回-1.
(2)int ns_name_pton(const char *src, u_char *dst, size_t dstsiz)
功能:该函数将通常类型的域名格式转换为网络格式
返回:
   如果失败返回:-1
  如果完全转换返回:1   部分转化返回:0
(3)u_int ns_get16(const u_char *cp)
(4)void  ns_put16(u_int s, u_char *cp)
(5)u_long ns_get32(const u_char *cp)
(6)void   ns_put32(u_long l, u_char *cp)

二.功能函数集合
(1)获取控制句柄
 int ns_initparse(const u_char *msg, int msglen, ns_msg *handle)
功能:初始化控制句柄handle.
参数:msg:dns报文指针,msglen:dns报文长度。
const u_char *ns_msg_base(ns_msg handle);
const u_char *ns_msg_end(ns_msg handle);
int ns_msg_size(ns_msg handle);
通过据句柄反向获取init时传递的参数。

(2)
标识获取 u_int16_t ns_msg_id(ns_msg handle) 功能:获取DNS头部字段的id 参数:handleinit时产生的句柄 (3)标志获取 u_int16_t ns_msg_get_flag(ns_msg handle, ns_flag flag) 功能:获取指定的标志字段标志位的值。 参数: handle:该参数为init时候产生的句柄 flag该参数为枚举类型,指定对应的flag标志位 (4)问题数获取 u_int16_t ns_msg_count(ns_msg handle, ns_sect section) 功能:返回头部字段中的指定类型记录数 。 参数: handle:控制句柄。 ns_sect:指定的类型,枚举类型。【问题数,资源记录数,授权资源数,额外资源记录数】 ns_s_qd 问题数 ns_s_zn ns_s_an 资源记录数 ns_s_pr ns_s_ns 授权资源数 ns_s_ud ns_s_ar 额外资源记录数 5)解析具体区域获取记录类型数据 int ns_parserr(ns_msg *handle, ns_sect section,int rrnum, ns_rr *rr) 功能:解析某个区域中的某个记录,比如问题域中的第2个问题,则参数分别为:section:ns_s_qd,rrnum:1 (编号最小从0开始 ,最大值为:u_int16_t ns_msg_count(ns_msg handle, ns_sect section)的返回值,通过依次指定rrnum,可以实现遍历该类型记录) 参数: handleDNS控制句柄 section:指定解析的区域 rrnum:指定区域中记录的标号 ns_rr:存放该指定记录 返回值:成功则返回0,解析失败返回-1 6)解析返回的记录类型rr 域名: char *ns_rr_name(ns_rr rr) 类型: u_int16_t ns_rr_type(ns_rr rr) 类: u_int16_t ns_rr_class(ns_rr rr) 生存时间: u_int32_t ns_rr_ttl(ns_rr rr) 资源数据长度: u_int16_t ns_rr_rdlen(ns_rr rr) 资源数据: const u_char *ns_rr_rdata(ns_rr rr)

7)解压缩域名
int ns_name_uncompress(const u_char *msg,
                       const u_char *eomorig,
                       const u_char *comp_dn,
                       char *exp_dn,
                       size_t length);

功能:解压缩域名中压缩区域
参数:
msg:dns报文的开始指针,eomorig:dns报文结束指针(向后一个字节)
comp_dn:压缩报文的开始指针
exp_dn:解压缩后的报文指针
length:存放解压缩的报文长度。一般为:MAXDNAME。

 

转载于:https://www.cnblogs.com/renhao/archive/2011/11/14/2248528.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值