windows-filter-windivert/include/dns_parser.h

38 lines
997 B
C++

#ifndef DNS_PARSER_H
#define DNS_PARSER_H
#include "common.h"
#include <cstdint>
#include <string>
class DNSParser {
public:
struct DNSQuery {
std::string domain;
uint16_t qtype;
uint16_t qclass;
bool is_query;
bool is_valid;
DNSQuery() : qtype(0), qclass(0), is_query(false), is_valid(false) {}
};
// Parse DNS packet and extract query information
static DNSQuery ParsePacket(const uint8_t* packet, size_t length);
private:
// Parse DNS name in label format
static std::string ParseDomainName(const uint8_t* packet,
size_t packet_len,
size_t& offset,
int depth = 0);
// Validate DNS header
static bool ValidateDNSHeader(const uint8_t* packet, size_t length);
// Check if this is a query packet (QR bit = 0)
static bool IsQueryPacket(const uint8_t* packet);
};
#endif // DNS_PARSER_H