update
This commit is contained in:
22
dns.h
22
dns.h
@@ -71,10 +71,10 @@ struct dns_head {
|
||||
unsigned short id; // identification number
|
||||
unsigned short qr; /* Query/Response Flag */
|
||||
unsigned short opcode; /* Operation Code */
|
||||
unsigned char aa; /* Authoritative Answer Flag */
|
||||
unsigned char tc; /* Truncation Flag */
|
||||
unsigned char rd; /* Recursion Desired */
|
||||
unsigned char ra; /* Recursion Available */
|
||||
unsigned char aa; /* Authoritative Answer Flag */
|
||||
unsigned char tc; /* Truncation Flag */
|
||||
unsigned char rd; /* Recursion Desired */
|
||||
unsigned char ra; /* Recursion Available */
|
||||
unsigned short rcode; /* Response Code */
|
||||
unsigned short qdcount; // number of question entries
|
||||
unsigned short ancount; // number of answer entries
|
||||
@@ -100,6 +100,20 @@ struct dns_packet {
|
||||
unsigned char data[0];
|
||||
};
|
||||
|
||||
struct dns_data_context
|
||||
{
|
||||
unsigned char *data;
|
||||
unsigned char *ptr;
|
||||
unsigned int maxsize;
|
||||
};
|
||||
|
||||
struct dns_context {
|
||||
struct dns_packet *packet;
|
||||
unsigned char *data;
|
||||
unsigned int maxsize;
|
||||
unsigned char *ptr;
|
||||
};
|
||||
|
||||
struct dns_rrs *dns_get_rrs_next(struct dns_packet *packet, struct dns_rrs *rrs);
|
||||
|
||||
struct dns_rrs *dns_get_rrs_start(struct dns_packet *packet, int type, int *count);
|
||||
|
||||
21
dns_server.c
21
dns_server.c
@@ -46,6 +46,7 @@ static void tv_sub(struct timeval *out, struct timeval *in)
|
||||
|
||||
void _dns_server_period_run()
|
||||
{
|
||||
return;
|
||||
unsigned char packet_data[DNS_INPACKET_SIZE];
|
||||
unsigned char data[DNS_INPACKET_SIZE];
|
||||
|
||||
@@ -93,13 +94,19 @@ static int _dns_server_process(struct timeval *now)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
dns_decode(packet, DNS_INPACKET_SIZE, inpacket, len);
|
||||
len = dns_decode(packet, DNS_INPACKET_SIZE, inpacket, len);
|
||||
if (len) {
|
||||
printf("decode failed.\n");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
int count;
|
||||
struct dns_rrs *rrs;
|
||||
char name[128];
|
||||
int i = 0;
|
||||
int ttl;
|
||||
int qtype;
|
||||
int qclass;
|
||||
|
||||
rrs = dns_get_rrs_start(packet, DNS_RRS_AN, &count);
|
||||
for (i = 0; i < count && rrs; i++, rrs = dns_get_rrs_next(packet, rrs)) {
|
||||
@@ -114,6 +121,18 @@ static int _dns_server_process(struct timeval *now)
|
||||
}
|
||||
}
|
||||
|
||||
rrs = dns_get_rrs_start(packet, DNS_RRS_QD, &count);
|
||||
for (i = 0; i < count && rrs; i++, rrs = dns_get_rrs_next(packet, rrs)) {
|
||||
switch (rrs->type) {
|
||||
case DNS_T_CNAME: {
|
||||
dns_get_domain(rrs, name, 128, &qtype, &qclass);
|
||||
printf("domain: %s qtype: %d qclass: %d\n", name, qtype, qclass);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
errout:
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user