1 /* common #include file for dns library. 2 */ 3 4 #ifndef DNS_PORT 5 6 #define DNS_PORT 53 /* default DNS port */ 7 #define DNS_MAXPACKET 512 /* max size of UDP packet */ 8 #define DNS_EDNS0_MAXPACKET 2048 /* max size of EDNS0 UDP packet */ 9 #define DNS_MAXDN 255 /* max length of DN */ 10 #define DNS_MAXLABEL 63 /* max length of one DN label */ 11 #define DNS_MAXLABELS (DNS_MAXDN/2) /* max # of labels in a DN */ 12 #define DNS_MAXDOMAIN 1024 /* max length of asciiz DN */ 13 14 enum dns_class { 15 DNS_C_INVALID = 0, /* invalid class */ 16 DNS_C_IN = 1, /* Internet */ 17 DNS_C_CH = 3, /* CHAOS */ 18 DNS_C_HS = 4, /* HESIOD */ 19 DNS_C_ANY = 255 /* wildcard */ 20 }; 21 22 enum dns_type { 23 DNS_T_INVALID = 0, /* Cookie. */ 24 DNS_T_A = 1, /* Host address. */ 25 DNS_T_NS = 2, /* Authoritative server. */ 26 DNS_T_MD = 3, /* Mail destination. */ 27 DNS_T_MF = 4, /* Mail forwarder. */ 28 DNS_T_CNAME = 5, /* Canonical name. */ 29 DNS_T_SOA = 6, /* Start of authority zone. */ 30 DNS_T_MB = 7, /* Mailbox domain name. */ 31 DNS_T_MG = 8, /* Mail group member. */ 32 DNS_T_MR = 9, /* Mail rename name. */ 33 DNS_T_NULL = 10, /* Null resource record. */ 34 DNS_T_WKS = 11, /* Well known service. */ 35 DNS_T_PTR = 12, /* Domain name pointer. */ 36 DNS_T_HINFO = 13, /* Host information. */ 37 DNS_T_MINFO = 14, /* Mailbox information. */ 38 DNS_T_MX = 15, /* Mail routing information. */ 39 DNS_T_TXT = 16, /* Text strings. */ 40 DNS_T_RP = 17, /* Responsible person. */ 41 DNS_T_AFSDB = 18, /* AFS cell database. */ 42 DNS_T_X25 = 19, /* X_25 calling address. */ 43 DNS_T_ISDN = 20, /* ISDN calling address. */ 44 DNS_T_RT = 21, /* Router. */ 45 DNS_T_NSAP = 22, /* NSAP address. */ 46 DNS_T_NSAP_PTR = 23, /* Reverse NSAP lookup (deprecated). */ 47 DNS_T_SIG = 24, /* Security signature. */ 48 DNS_T_KEY = 25, /* Security key. */ 49 DNS_T_PX = 26, /* X.400 mail mapping. */ 50 DNS_T_GPOS = 27, /* Geographical position (withdrawn). */ 51 DNS_T_AAAA = 28, /* Ip6 Address. */ 52 DNS_T_LOC = 29, /* Location Information. */ 53 DNS_T_NXT = 30, /* Next domain (security). */ 54 DNS_T_EID = 31, /* Endpoint identifier. */ 55 DNS_T_NIMLOC = 32, /* Nimrod Locator. */ 56 DNS_T_SRV = 33, /* Server Selection. */ 57 DNS_T_ATMA = 34, /* ATM Address */ 58 DNS_T_NAPTR = 35, /* Naming Authority PoinTeR */ 59 DNS_T_KX = 36, /* Key Exchange */ 60 DNS_T_CERT = 37, /* Certification record */ 61 DNS_T_A6 = 38, /* IPv6 address (deprecates AAAA) */ 62 DNS_T_DNAME = 39, /* Non-terminal DNAME (for IPv6) */ 63 DNS_T_SINK = 40, /* Kitchen sink (experimentatl) */ 64 DNS_T_OPT = 41, /* EDNS0 option (meta-RR) */ 65 DNS_T_TSIG = 250, /* Transaction signature. */ 66 DNS_T_IXFR = 251, /* Incremental zone transfer. */ 67 DNS_T_AXFR = 252, /* Transfer zone of authority. */ 68 DNS_T_MAILB = 253, /* Transfer mailbox records. */ 69 DNS_T_MAILA = 254, /* Transfer mail agent records. */ 70 DNS_T_ANY = 255, /* Wildcard match. */ 71 DNS_T_ZXFR = 256, /* BIND-specific, nonstandard. */ 72 DNS_T_MAX = 65536 73 }; 74 75 enum dns_rcode { /* reply code */ 76 DNS_R_NOERROR = 0, /* ok, no error */ 77 DNS_R_FORMERR = 1, /* format error */ 78 DNS_R_SERVFAIL = 2, /* server failed */ 79 DNS_R_NXDOMAIN = 3, /* domain does not exists */ 80 DNS_R_NOTIMPL = 4, /* not implemented */ 81 DNS_R_REFUSED = 5, /* query refused */ 82 /* these are for BIND_UPDATE */ 83 DNS_R_YXDOMAIN = 6, /* Name exists */ 84 DNS_R_YXRRSET = 7, /* RRset exists */ 85 DNS_R_NXRRSET = 8, /* RRset does not exist */ 86 DNS_R_NOTAUTH = 9, /* Not authoritative for zone */ 87 DNS_R_NOTZONE = 10, /* Zone of record different from zone section */ 88 /*ns_r_max = 11,*/ 89 /* The following are TSIG extended errors */ 90 DNS_R_BADSIG = 16, 91 DNS_R_BADKEY = 17, 92 DNS_R_BADTIME = 18 93 }; 94 95 struct dns_nameval { 96 int val; 97 const char *name; 98 }; 99 100 extern const struct dns_nameval dns_classtab[]; 101 extern const struct dns_nameval dns_typetab[]; 102 extern const struct dns_nameval dns_rcodetab[]; 103 const struct dns_nameval * 104 dns_findname(const struct dns_nameval *nv, const char *name); 105 #define dns_findclassname(class) dns_findname(dns_classtab, (class)) 106 #define dns_findtypename(type) dns_findname(dns_typetab, (type)) 107 #define dns_findrcodename(rcode) dns_findname(dns_rcodetab, (rcode)) 108 109 const char *dns_classname(enum dns_class class); 110 const char *dns_typename(enum dns_type type); 111 const char *dns_rcodename(enum dns_rcode rcode); 112 113 unsigned dns_ptodn(const char *name, unsigned char *dn, unsigned dnsiz); 114 /* convert asciiz string `name' to the DN format, return length or 0 */ 115 unsigned dns_dntop(const unsigned char *dn, char *dst, unsigned dstsiz); 116 unsigned dns_dntol(const unsigned char *srcdn, unsigned char *dstdn); 117 #define dns_dnlc(c) ((c) >= 'A' && (c) <= 'Z' ? (c) - 'A' + 'a' : (c)) 118 unsigned dns_dnlen(const unsigned char *dn); 119 unsigned dns_dnlabels(const unsigned char *dn); 120 /* return number of labels in a dn */ 121 int dns_dnequ(const unsigned char *dn1, const unsigned char *dn2); 122 unsigned dns_dnreverse(const unsigned char *dn, unsigned char *rdn, 123 unsigned len); 124 /* reverse order of labels in a dn; len, if non-zero, should be length 125 * of dn (to save some CPU cycles) */ 126 127 #endif 128