Ç - 字节数组结构(DNS查询) [英] C - byte array to structure (dns query)

查看:243
本文介绍了Ç - 字节数组结构(DNS查询)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些结构:

typedef struct dnsQuery {
  char header[12];
  struct TdnsQuerySection *querySection;
} TdnsQuery;

typedef struct dnsQuerySection {
  unsigned char *name;
  struct TdnsQueryQuestion *question;
} TdnsQuerySection;

typedef struct dnsQueryQuestion {
  unsigned short qtype;
  unsigned short qclass;
} TdnsQueryQuestion;

和我从 recvfrom的字节数组DNS查询。
我想从字节数组像这样得到的结构:

and I have dns query in byte array from recvfrom. I am trying to get structure from byte array like this:

TdnsQuery* dnsQuery = (TdnsQuery*)buf;
printf("%u", dnsQuery->querySection->question.qtype);

为什么我得到错误取消引用指针不完全类型?我这样做对吗?或者我怎样才能得到DNS查询的结构从数组?我需要一个DNS查询问题和类型。

Why I get error Dereferencing pointer to incomplete type? Am I doing this right? Or how can I get dns query structure from that array? I need that dns query question and type.

推荐答案

您的查询部分打印机是一个不完整的类型。你需要或者它的typedef事前,而不是使用这种结构的关键字,或使用结构的名称,而不是类型定义。例如:

your query section printer is an incomplete type. you need to either typedef it beforehand and not use the structure keyword or use the structure name rather than the typedef. e.g.:

typedef struct foo Foo;

struct {
    Foo* querySection;
    // effectively same as above
    struct foo* querySection2;

    // NOT the following. 
    struct Foo* querySectionWrong; 
}; 

这篇关于Ç - 字节数组结构(DNS查询)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆