2 * @brief IRC resolver API.
9 #ifndef INCLUDED_config_h
13 #ifndef INCLUDED_sys_types_h
14 #include <sys/types.h>
15 #define INCLUDED_sys_types_h
18 #ifndef INCLUDED_sys_socket_h
19 #include <sys/socket.h>
20 #define INCLUDED_sys_socket_h
25 #ifndef INCLUDED_netinet_in_h
26 #include <netinet/in.h>
27 #define INCLUDED_netinet_in_h
31 #ifndef INCLUDED_stdint_h
33 #define INCLUDED_stdint_h
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. */
56 /** Structure to store an IP address. */
59 unsigned short in6_16[8]; /**< IPv6 encoded parts, little-endian. */
62 /** Structure to store an IP address and port number. */
65 struct irc_in_addr addr; /**< IP address. */
66 unsigned short port; /**< Port number, host-endian. */
69 /** DNS reply structure. */
72 char *h_name; /**< Hostname. */
73 struct irc_in_addr addr; /**< IP address. */
76 /** DNS callback structure. */
79 void *vptr; /**< pointer used by callback to identify request */
80 void (*callback)(void* vptr, struct DNSReply *reply); /**< callback to call */
83 /** DNS query and response header. */
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 */
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 */
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 */
121 extern int init_resolver(void);
122 extern void restart_resolver(void);
123 extern void add_local_domain(char *hname, size_t size);
124 extern size_t cres_mem(struct Client* cptr);
125 extern void delete_resolver_queries(const void *vptr);
126 extern void report_dns_servers(struct Client *source_p, const struct StatDesc *sd, char *param);
127 extern void gethost_byname(const char *name, const struct DNSQuery *query);
128 extern void gethost_byaddr(const struct irc_in_addr *addr, const struct DNSQuery *query);
130 extern int irc_in_addr_valid(const struct irc_in_addr *addr);
131 extern int irc_in_addr_cmp(const struct irc_in_addr *a, const struct irc_in_addr *b);
132 extern int irc_in_addr_is_ipv4(const struct irc_in_addr *addr);
133 extern int irc_in_addr_is_loopback(const struct irc_in_addr *addr);