libdnspacketDNS 数据包解析和构建库

联合创作 · 2023-09-29 06:50

libdnspacket  是一个仅一个单 .hpp 文件,引入即可实现对 DNS 数据包的解析和构建的库,十分的轻量,无任何外部依赖,无平台依赖。


特点:



  • 便于使用


  • 没有外部依赖


  • 解析 DNS 数据包


  • 构建 DNS 数据包


  • DNS 主机名压缩


  • 支持多种 DNS 记录类型



使用方式十分简单,只需要将源码文件dns.hpp放入你的项目中,inclue之后通过调用Parse或Build方法就可以对DNS数据包进行解析或构建了,不用担心什么副作用。


示例:


- 解析原始DNS数据包为消息



/
// Parameters:
// buf: point to the raw DNS packet
// bufSize: indicate the size of [buf]
// Return:
// <bool, DnsMessage>
// #1: indicate whether the packet was parsed successfully or not
// #2: when #1 value is true, this is the final structured DNS message
//
std::tuple<bool, DnsMessage> dns::Parse(const uint8_t* buf, size_t bufSize);

- 构建DNS消息为原始数据包



/
// Parameters:
// message: the structured DNS message
// Return:
// The byte buffer of raw DNS packet
//
std::vector<std::byte> Build(const DnsMessage& message);
浏览 20
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报