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