40 #include "asterisk/network.h"
41 #include <arpa/nameser.h>
51 #if __BYTE_ORDER == __PDP_ENDIAN
52 #define DETERMINED_BYTE_ORDER __LITTLE_ENDIAN
55 #if __BYTE_ORDER == __BIG_ENDIAN
56 #define DETERMINED_BYTE_ORDER __BIG_ENDIAN
58 #if __BYTE_ORDER == __LITTLE_ENDIAN
59 #define DETERMINED_BYTE_ORDER __LITTLE_ENDIAN
123 #if DETERMINED_BYTE_ORDER == __BIG_ENDIAN
137 #if DETERMINED_BYTE_ORDER == __LITTLE_ENDIAN
160 unsigned short class;
163 } __attribute__((__packed__));
175 if ((*s & 0xc0) == 0xc0) {
190 int class,
int type,
unsigned char *answer,
int len,
191 int (*callback)(
void *context,
unsigned char *answer,
int len,
unsigned char *fullanswer))
193 unsigned char *fullanswer = answer;
204 for (x = 0; x < ntohs(h->
qdcount); x++) {
205 if ((res =
skip_name(answer, len)) < 0) {
217 for (x = 0; x < ntohs(h->
ancount); x++) {
218 if ((res =
skip_name(answer, len)) < 0) {
236 if (ntohs(ans->
class) ==
class && ntohs(ans->
rtype) == type) {
238 if ((res = callback(context, answer, ntohs(ans->
size), fullanswer)) < 0) {
245 answer += ntohs(ans->
size);
246 len -= ntohs(ans->
size);
251 #ifndef HAVE_RES_NINIT
260 const char *dname,
int class,
int type,
261 int (*callback)(
void *context,
unsigned char *answer,
int len,
unsigned char *fullanswer))
263 #ifdef HAVE_RES_NINIT
264 struct __res_state dnsstate;
269 #ifdef HAVE_RES_NINIT
270 memset(&dnsstate, 0,
sizeof(dnsstate));
271 res_ninit(&dnsstate);
272 res = res_nsearch(&dnsstate, dname,
class, type, answer,
sizeof(answer));
276 res = res_search(dname,
class, type, answer,
sizeof(answer));
279 if ((res =
dns_parse_answer(context,
class, type, answer, res, callback)) < 0) {
282 }
else if (res == 0) {
283 ast_debug(1,
"No matches found in DNS for %s\n", dname);
288 #ifdef HAVE_RES_NINIT
289 #ifdef HAVE_RES_NDESTROY
290 res_ndestroy(&dnsstate);
292 res_nclose(&dnsstate);
295 #ifdef HAVE_RES_CLOSE
Asterisk main include file. File version handling, generic pbx functions.
int ast_search_dns(void *context, const char *dname, int class, int type, int(*callback)(void *context, unsigned char *answer, int len, unsigned char *fullanswer))
Perform DNS lookup (used by DNS, enum and SRV lookups)
#define ast_mutex_lock(a)
#define ast_debug(level,...)
Log a DEBUG message.
General Asterisk PBX channel definitions.
Asterisk architecture endianess compatibility definitions.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
static int skip_name(unsigned char *s, int len)
static char context[AST_MAX_CONTEXT]
#define AST_MUTEX_DEFINE_STATIC(mutex)
DNS support for Asterisk.
static int dns_parse_answer(void *context, int class, int type, unsigned char *answer, int len, int(*callback)(void *context, unsigned char *answer, int len, unsigned char *fullanswer))
Parse DNS lookup result, call callback.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
#define ast_mutex_unlock(a)