且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C中的DNS客户端

更新时间:2023-11-30 12:51:04

看起来像我从RFC发现的任何东西(是的,我已经写了很多DNS数据包解码软件)。

Your structures don't look like anything I recognise from the RFCs (yes, I've written lots of DNS packet decoding software).

查看 RFC 1035 ,特别是您可以直接从其中显示的字段布局映射所需的大多数结构。

Look at RFC 1035 in particular - most of the structures you need can be mapped directly from the field layouts show therein.

例如,你需要一个标题(见s4.1.1):

For example, you need a header (see s4.1.1):

struct dns_header {
     uint16_t     query_id;
     uint16_t     flags;
     uint16_t     qdcount;
     uint16_t     ancount;
     uint16_t     nscount;
     uint16_t     arcount;
};

不要忘记使用 ntohs()将这些字段的有线格式转换为机器的本机字节顺序。网络订单是大端的,大多数机器这些天是小端。

Don't forget to use ntohs() to convert the wire format of these fields into your machine's native byte order. The network order is big-endian, and most machines these days are little-endian.

你需要一个问题结构(见s4.1.2),和一个通用的资源记录结构(见s4.1.3)。

You'll need a "question" structure (see s4.1.2), and a generic "resource record" structure too (see s4.1.3).

请注意,这两个的线格式开始可变长度标签,也可以包括压缩指针(见s4.1.4)。这意味着你不能在这些情况下将整个线框简单地映射到C结构上。

Note however that the wire format of both of these starts with a variable length "label", which can also include compression pointers (see s4.1.4). This means that you can't in these cases trivially map the whole wire block onto a C structure.

希望这有帮助...