Fix resolver code when IPv6 is enabled (or at least make it capable of working).
[ircu2.10.12-pk.git] / include / res.h
1 /** @file
2  * @brief IRC resolver API.
3  * @version $Id$
4  */
5
6 #ifndef INCLUDED_res_h
7 #define INCLUDED_res_h
8
9 #ifndef INCLUDED_config_h
10 #include "config.h"
11 #endif
12
13 #ifndef INCLUDED_sys_types_h
14 #include <sys/types.h>
15 #define INCLUDED_sys_types_h
16 #endif
17
18 #ifndef INCLUDED_sys_socket_h
19 #include <sys/socket.h>
20 #define INCLUDED_sys_socket_h
21 #endif
22
23 #include <netdb.h>
24
25 #ifndef INCLUDED_netinet_in_h
26 #include <netinet/in.h>
27 #define INCLUDED_netinet_in_h
28 #endif
29
30 #ifdef HAVE_STDINT_H
31 #ifndef INCLUDED_stdint_h
32 #include <stdint.h>
33 #define INCLUDED_stdint_h
34 #endif
35 #endif
36
37 struct Client;
38 struct StatDesc;
39
40 /* Here we define some values lifted from nameser.h */
41 #define NS_INT16SZ 2 /**< Size of a 16-bit value. */
42 #define NS_INT32SZ 4 /**< Size of a 32-bit value. */
43 #define NS_CMPRSFLGS 0xc0 /**< Prefix flags that indicate special types */
44 #define NS_MAXCDNAME 255 /**< Maximum length of a compressed domain name. */
45 #define QUERY 0      /**< Forward (normal) DNS query operation. */
46 #define NO_ERRORS 0  /**< No errors processing a query. */
47 #define SERVFAIL 2   /**< Server error while processing a query. */
48 #define T_A 1        /**< Hostname -> IPv4 query type. */
49 #define T_AAAA 28    /**< Hostname -> IPv6 query type. */
50 #define T_PTR 12     /**< IP(v4 or v6) -> hostname query type. */
51 #define T_CNAME 5    /**< Canonical name resolution query type. */
52 #define C_IN 1       /**< Internet query class. */
53 #define QFIXEDSZ 4   /**< Length of fixed-size part of query. */
54 #define HFIXEDSZ 12  /**< Length of fixed-size DNS header. */
55
56 /** Structure to store an IP address. */
57 struct irc_in_addr
58 {
59   unsigned short in6_16[8]; /**< IPv6 encoded parts, little-endian. */
60 };
61
62 /** Structure to store an IP address and port number. */
63 struct irc_sockaddr
64 {
65   struct irc_in_addr addr; /**< IP address. */
66   unsigned short port;     /**< Port number, host-endian. */
67 };
68
69 /** DNS reply structure. */
70 struct DNSReply
71 {
72   char *h_name;   /**< Hostname. */
73   struct irc_in_addr addr; /**< IP address. */
74 };
75
76 /** DNS callback structure. */
77 struct DNSQuery
78 {
79   void *vptr; /**< pointer used by callback to identify request */
80   void (*callback)(void* vptr, struct DNSReply *reply); /**< callback to call */
81 };
82
83 /** DNS query and response header. */
84 typedef struct
85 {
86         unsigned        id :16;         /**< query identification number */
87 #ifdef WORDS_BIGENDIAN
88                         /* fields in third byte */
89         unsigned        qr: 1;          /**< response flag */
90         unsigned        opcode: 4;      /**< purpose of message */
91         unsigned        aa: 1;          /**< authoritive answer */
92         unsigned        tc: 1;          /**< truncated message */
93         unsigned        rd: 1;          /**< recursion desired */
94                         /* fields in fourth byte */
95         unsigned        ra: 1;          /**< recursion available */
96         unsigned        unused :1;      /**< unused bits (MBZ as of 4.9.3a3) */
97         unsigned        ad: 1;          /**< authentic data from named */
98         unsigned        cd: 1;          /**< checking disabled by resolver */
99         unsigned        rcode :4;       /**< response code */
100 #else
101                         /* fields in third byte */
102         unsigned        rd :1;          /**< recursion desired */
103         unsigned        tc :1;          /**< truncated message */
104         unsigned        aa :1;          /**< authoritive answer */
105         unsigned        opcode :4;      /**< purpose of message */
106         unsigned        qr :1;          /**< response flag */
107                         /* fields in fourth byte */
108         unsigned        rcode :4;       /**< response code */
109         unsigned        cd: 1;          /**< checking disabled by resolver */
110         unsigned        ad: 1;          /**< authentic data from named */
111         unsigned        unused :1;      /**< unused bits (MBZ as of 4.9.3a3) */
112         unsigned        ra :1;          /**< recursion available */
113 #endif
114                         /* remaining bytes */
115         unsigned        qdcount :16;    /**< number of question entries */
116         unsigned        ancount :16;    /**< number of answer entries */
117         unsigned        nscount :16;    /**< number of authority entries */
118         unsigned        arcount :16;    /**< number of resource entries */
119 } HEADER;
120
121 extern void restart_resolver(void);
122 extern void add_local_domain(char *hname, size_t size);
123 extern size_t cres_mem(struct Client* cptr);
124 extern void delete_resolver_queries(const void *vptr);
125 extern void report_dns_servers(struct Client *source_p, const struct StatDesc *sd, char *param);
126 extern void gethost_byname(const char *name, const struct DNSQuery *query);
127 extern void gethost_byaddr(const struct irc_in_addr *addr, const struct DNSQuery *query);
128
129 extern int irc_in_addr_valid(const struct irc_in_addr *addr);
130 extern int irc_in_addr_cmp(const struct irc_in_addr *a, const struct irc_in_addr *b);
131 extern int irc_in_addr_is_ipv4(const struct irc_in_addr *addr);
132 extern int irc_in_addr_is_loopback(const struct irc_in_addr *addr);
133
134 #endif