]> jfr.im git - irc/rqf/shadowircd.git/blob - include/reslib.h
SVN Id removal part two
[irc/rqf/shadowircd.git] / include / reslib.h
1 /*
2 * include/irc_reslib.h
3 *
4 */
5
6 #ifndef _CHARYBDIS_RESLIB_H
7 #define _CHARYBDIS_RESLIB_H
8
9 /* Longest hostname we're willing to work with.
10 * Due to DNSBLs this is more than HOSTLEN.
11 */
12 #define IRCD_RES_HOSTLEN 255
13
14 /* Here we define some values lifted from nameser.h */
15 #define NS_NOTIFY_OP 4
16 #define NS_INT16SZ 2
17 #define NS_IN6ADDRSZ 16
18 #define NS_INADDRSZ 4
19 #define NS_INT32SZ 4
20 #define NS_CMPRSFLGS 0xc0
21 #define NS_MAXCDNAME 255
22 #define QUERY 0
23 #define IQUERY 1
24 #define NO_ERRORS 0
25 #define SERVFAIL 2
26 #define NXDOMAIN 3
27 #define T_A 1
28 #define T_AAAA 28
29 #define T_PTR 12
30 #define T_CNAME 5
31 #define T_NULL 10
32 #define C_IN 1
33 #define QFIXEDSZ 4
34 #define RRFIXEDSZ 10
35 #define HFIXEDSZ 12
36
37 typedef struct
38 {
39 unsigned id :16; /* query identification number */
40 #ifdef WORDS_BIGENDIAN
41 /* fields in third byte */
42 unsigned qr: 1; /* response flag */
43 unsigned opcode: 4; /* purpose of message */
44 unsigned aa: 1; /* authoritive answer */
45 unsigned tc: 1; /* truncated message */
46 unsigned rd: 1; /* recursion desired */
47 /* fields in fourth byte */
48 unsigned ra: 1; /* recursion available */
49 unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
50 unsigned ad: 1; /* authentic data from named */
51 unsigned cd: 1; /* checking disabled by resolver */
52 unsigned rcode :4; /* response code */
53 #else
54 /* fields in third byte */
55 unsigned rd :1; /* recursion desired */
56 unsigned tc :1; /* truncated message */
57 unsigned aa :1; /* authoritive answer */
58 unsigned opcode :4; /* purpose of message */
59 unsigned qr :1; /* response flag */
60 /* fields in fourth byte */
61 unsigned rcode :4; /* response code */
62 unsigned cd: 1; /* checking disabled by resolver */
63 unsigned ad: 1; /* authentic data from named */
64 unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
65 unsigned ra :1; /* recursion available */
66 #endif
67 /* remaining bytes */
68 unsigned qdcount :16; /* number of question entries */
69 unsigned ancount :16; /* number of answer entries */
70 unsigned nscount :16; /* number of authority entries */
71 unsigned arcount :16; /* number of resource entries */
72 } HEADER;
73
74 /*
75 * Inline versions of get/put short/long. Pointer is advanced.
76 */
77 #define IRC_NS_GET16(s, cp) { \
78 const unsigned char *t_cp = (const unsigned char *)(cp); \
79 (s) = ((u_int16_t)t_cp[0] << 8) \
80 | ((u_int16_t)t_cp[1]) \
81 ; \
82 (cp) += NS_INT16SZ; \
83 }
84
85 #define IRC_NS_GET32(l, cp) { \
86 const unsigned char *t_cp = (const unsigned char *)(cp); \
87 (l) = ((u_int32_t)t_cp[0] << 24) \
88 | ((u_int32_t)t_cp[1] << 16) \
89 | ((u_int32_t)t_cp[2] << 8) \
90 | ((u_int32_t)t_cp[3]) \
91 ; \
92 (cp) += NS_INT32SZ; \
93 }
94
95 #define IRC_NS_PUT16(s, cp) { \
96 u_int16_t t_s = (u_int16_t)(s); \
97 unsigned char *t_cp = (unsigned char *)(cp); \
98 *t_cp++ = t_s >> 8; \
99 *t_cp = t_s; \
100 (cp) += NS_INT16SZ; \
101 }
102
103 #define IRC_NS_PUT32(l, cp) { \
104 u_int32_t t_l = (u_int32_t)(l); \
105 unsigned char *t_cp = (unsigned char *)(cp); \
106 *t_cp++ = t_l >> 24; \
107 *t_cp++ = t_l >> 16; \
108 *t_cp++ = t_l >> 8; \
109 *t_cp = t_l; \
110 (cp) += NS_INT32SZ; \
111 }
112
113 extern int irc_res_init(void);
114 extern int irc_dn_expand(const unsigned char *msg, const unsigned char *eom, const unsigned char *src, char *dst, int dstsiz);
115 extern int irc_dn_skipname(const unsigned char *ptr, const unsigned char *eom);
116 extern unsigned int irc_ns_get16(const unsigned char *src);
117 extern unsigned long irc_ns_get32(const unsigned char *src);
118 extern void irc_ns_put16(unsigned int src, unsigned char *dst);
119 extern void irc_ns_put32(unsigned long src, unsigned char *dst);
120 extern int irc_res_mkquery(const char *dname, int class, int type, unsigned char *buf, int buflen);
121
122 extern char irc_domain[IRCD_RES_HOSTLEN + 1];
123
124 #endif