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