Skip to content

Commit

Permalink
Add DNS response address
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuele-f committed Mar 29, 2019
1 parent 8dbe781 commit c496c79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ struct ndpi_flow_struct {
struct {
u_int8_t num_queries, num_answers, reply_code;
u_int16_t query_type, query_class, rsp_type;
ndpi_ip_addr_t rsp_addr; /* The first address in a DNS response packet */
} dns;

struct {
Expand Down
16 changes: 16 additions & 0 deletions src/lib/protocols/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd

rsp_type = get16(&x, flow->packet.payload);
flow->protos.dns.rsp_type = rsp_type;

/* here x points to the response "class" field */
if((x+12) < flow->packet.payload_packet_len) {
x += 6;
data_len = get16(&x, flow->packet.payload);

if(((x + data_len) < flow->packet.payload_packet_len)
&& (((rsp_type == 0x1) && (data_len == 4)) /* A */
#ifdef NDPI_DETECTION_SUPPORT_IPV6
|| ((rsp_type == 0x1c) && (data_len == 16)) /* AAAA */
#endif
)) {
memcpy(&flow->protos.dns.rsp_addr, flow->packet.payload + x, data_len);
}
}

break;
}
}
Expand Down

0 comments on commit c496c79

Please sign in to comment.