1 #ifndef DNS_PROTOCOL_H 2 #define DNS_PROTOCOL_H 3 /* dnsmasq is Copyright (c) 2000-2012 Simon Kelley 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; version 2 dated June, 1991, or 8 (at your option) version 3 dated 29 June, 2007. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 /** 19 * DNS Protocol Header 20 * 21 * file from dnsmasq/src/dns-protocol.h with slight modification. 22 */ 23 24 #define NAMESERVER_PORT 53 25 #define TFTP_PORT 69 26 27 #define IN6ADDRSZ 16 28 #define INADDRSZ 4 29 30 #define PACKETSZ 512 /* maximum packet size */ 31 #define MAXDNAME 1025 /* maximum presentation domain name */ 32 #define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ 33 #define MAXLABEL 63 /* maximum length of domain label */ 34 35 #define NOERROR 0 /* no error */ 36 #define FORMERR 1 /* format error */ 37 #define SERVFAIL 2 /* server failure */ 38 #define NXDOMAIN 3 /* non existent domain */ 39 #define NOTIMP 4 /* not implemented */ 40 #define REFUSED 5 /* query refused */ 41 42 #define QUERY 0 /* opcode */ 43 44 #define C_IN 1 /* the arpa internet */ 45 #define C_CHAOS 3 /* for chaos net (MIT) */ 46 #define C_ANY 255 /* wildcard match */ 47 48 #define T_A 1 49 #define T_NS 2 50 #define T_CNAME 5 51 #define T_SOA 6 52 #define T_PTR 12 53 #define T_MX 15 54 #define T_TXT 16 55 #define T_SIG 24 56 #define T_AAAA 28 57 #define T_SRV 33 58 #define T_NAPTR 35 59 #define T_OPT 41 60 #define T_TKEY 249 61 #define T_TSIG 250 62 #define T_MAILB 253 63 #define T_ANY 255 64 65 struct dns_header { 66 uint16_t id; 67 uint8_t hb3,hb4; 68 uint16_t qdcount,ancount,nscount,arcount; 69 }; 70 71 #define HB3_QR 0x80 72 #define HB3_OPCODE 0x78 73 #define HB3_AA 0x04 74 #define HB3_TC 0x02 75 #define HB3_RD 0x01 76 77 #define HB4_RA 0x80 78 #define HB4_AD 0x20 79 #define HB4_CD 0x10 80 #define HB4_RCODE 0x0f 81 82 #define OPCODE(x) (((x)->hb3 & HB3_OPCODE) >> 3) 83 #define RCODE(x) ((x)->hb4 & HB4_RCODE) 84 #define SET_RCODE(x, code) (x)->hb4 = ((x)->hb4 & ~HB4_RCODE) | code 85 86 #define GETSHORT(s, cp) { \ 87 unsigned char *t_cp = (unsigned char *)(cp); \ 88 (s) = ((uint16_t)t_cp[0] << 8) \ 89 | ((uint16_t)t_cp[1]) \ 90 ; \ 91 (cp) += 2; \ 92 } 93 94 #define GETLONG(l, cp) { \ 95 unsigned char *t_cp = (unsigned char *)(cp); \ 96 (l) = ((uint32_t)t_cp[0] << 24) \ 97 | ((uint32_t)t_cp[1] << 16) \ 98 | ((uint32_t)t_cp[2] << 8) \ 99 | ((uint32_t)t_cp[3]) \ 100 ; \ 101 (cp) += 4; \ 102 } 103 104 #define PUTSHORT(s, cp) { \ 105 uint16_t t_s = (uint16_t)(s); \ 106 unsigned char *t_cp = (unsigned char *)(cp); \ 107 *t_cp++ = t_s >> 8; \ 108 *t_cp = t_s; \ 109 (cp) += 2; \ 110 } 111 112 #define PUTLONG(l, cp) { \ 113 uint32_t t_l = (uint32_t)(l); \ 114 unsigned char *t_cp = (unsigned char *)(cp); \ 115 *t_cp++ = t_l >> 24; \ 116 *t_cp++ = t_l >> 16; \ 117 *t_cp++ = t_l >> 8; \ 118 *t_cp = t_l; \ 119 (cp) += 4; \ 120 } 121 122 #endif 123