C - dns query to structure
- by Bibo
I have these structures:
typedef struct dnsQuery {
char header[12];
struct dnsQuerySection *querySection;
} TdnsQuery;
typedef struct dnsQuerySection {
unsigned char *name;
struct dnsQueryQuestion *question;
} TdnsQuerySection;
typedef struct dnsQueryQuestion {
unsigned short qtype;
unsigned short qclass;
} TdnsQueryQuestion;
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;
When I tried to access qtype like this:
printf("%u", dnsQuery->querySection->question.qtype);
I get seg fault 11.
Can someone help me with these structures? What´s wrong with them? I tried to add structure:
typedef struct udpPacket {
char header[8];
structr dnsQuery query;
}
and mapped this structure from byte array but it didn´t help. Can someone help me with these structures? How they should look like for dns query with udp protocol?