1

私はこれらの構造を持っています:

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;

からのバイト配列にDNSクエリがありますrecvfrom。私は次のようにバイト配列から構造を取得しようとしています:

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

不完全な型へのポインタの逆参照でエラーが発生するのはなぜですか?私はこれを正しくやっていますか?または、その配列からDNSクエリ構造を取得するにはどうすればよいですか?DNSクエリの質問とタイプが必要です。

4

1 に答える 1

1

クエリセクションプリンタは不完全なタイプです。事前にt​​ypedefして、structureキーワードを使用しないか、typedefではなく構造名を使用する必要があります。例えば:

typedef struct foo Foo;

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

    // NOT the following. 
    struct Foo* querySectionWrong; 
}; 
于 2012-11-18T09:41:31.763 に答える