I am trying to extract a DNS query from an captured DNS packet with libpcap api, however there must be a problem with my structures, after the last cast (using struct question) the char* name
pointer is pointing at correct adress, the start of the query name, however it contains only
42 45 20 00
but it should
20 45 48 45 50 45 50 45 48 45 4d 45 46 43 4f 45 44 45 50 45 4e 43 41 43 41 43
41 43 41 43 41 41 41 00 00 20 00 01
The code is here
struct dnshdr{
uint16_t id;
uint16_t flags;
uint16_t ques;
uint16_t anRR;
uint16_t auRR;
uint16_t addRR;
};
struct question{
char * name;
uint16_t type;
uint16_t cls;
};
void packetProc(u_char *args, const struct pcap_pkthdr *header,const u_char *packet){
struct iphdr *IP_header;
struct udphdr *UDP_header;
struct dnshdr *DNS_header;
struct question *ques;
IP_header = (struct iphdr*) (packet + sizeof(struct ethhdr));
UDP_header = (struct udphdr*) (packet + sizeof(struct iphdr) + sizeof(struct ethhdr));
DNS_header = (struct dnshdr*) (packet + sizeof(struct iphdr) + sizeof(struct ethhdr) + sizeof(struct udphdr) );
ques = (struct question*) (packet + sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct udphdr) + sizeof(struct dnshdr)-1 ); //fatal
}
I am honestly puzzled what to do here