我有這些結構:Ç - 字節數組結構(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查詢。 我想從字節數組結構是這樣的:
TdnsQuery* dnsQuery = (TdnsQuery*)buf;
printf("%u", dnsQuery->querySection->question.qtype);
爲什麼我得到錯誤提領指向不完全類型?我做對了嗎?或者我該如何從該數組中獲取dns查詢結構?我需要該dns查詢問題和類型。
通過'recvfrom'收到的dns查詢不包含指針值,所以你不能直接將它映射到你在問題中顯示的結構。要麼你需要修改你的結構體定義不要包含指針,要麼你需要解析接收到的數據,並按字段填充結構體。 –