1 /* 2 * Copyright (C) 2022 Beken Corporation 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef __DNS_H__ 16 #define __DNS_H__ 17 18 struct dns_header { 19 uint16_t id; 20 union { 21 struct { 22 uint16_t rcode:4, /* response code */ 23 cd:1, /* checking disabled RFC-2535 */ 24 ad:1, /* authentic data RFC-2535 */ 25 z:1, /* zero */ 26 ra:1, /* recursion available */ 27 rd:1, /* recursion desired */ 28 tc:1, /* truncated */ 29 aa:1, /* authoritative answer */ 30 opcode:4, /* (should be 0 for normal DNS messages) */ 31 qr:1; /* query/response */ 32 } fields ; 33 uint16_t num; 34 } flags ; 35 uint16_t num_questions; 36 uint16_t answer_rrs; 37 uint16_t authority_rrs; 38 uint16_t additional_rrs; 39 } __attribute__((packed)); 40 41 struct dns_question { 42 /* query name (label) field */ 43 uint16_t type; 44 uint16_t class; 45 } __attribute__((packed)); 46 47 struct dns_rr { 48 uint16_t name_ptr; /* pointer to name */ 49 uint16_t type; /* resource type */ 50 uint16_t class; /* resource class */ 51 uint32_t ttl; /* time to live */ 52 uint16_t rdlength; /* resource data length */ 53 uint32_t rd; /* resource data: we only provide a 54 4-byte data response (an IP 55 address) but this is actually a 56 field of length rdlength */ 57 } __attribute__((packed)); 58 59 #endif /* __DNS_H__ */ 60