| 1 |
/* |
| 2 |
* dns/reslib.h |
| 3 |
* |
| 4 |
* $Id: reslib.h 446 2006-02-12 02:46:54Z db $ |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef MOWGLI_SRC_LIBMOWGLI_DNS_EVLOOP_RESLIB_H_INCLUDE_GUARD |
| 8 |
#define MOWGLI_SRC_LIBMOWGLI_DNS_EVLOOP_RESLIB_H_INCLUDE_GUARD 1 |
| 9 |
|
| 10 |
/* Here we define some values lifted from nameser.h */ |
| 11 |
#define MOWGLI_DNS_NS_NOTIFY_OP 4 |
| 12 |
#define MOWGLI_DNS_NS_INT16SIZE 2 |
| 13 |
#define MOWGLI_DNS_NS_IN6ADDRSIZE 16 |
| 14 |
#define MOWGLI_DNS_NS_INADDRSIZE 4 |
| 15 |
#define MOWGLI_DNS_NS_INT32SIZE 4 |
| 16 |
#define MOWGLI_DNS_NS_CMPRSFLAGS 0xc0 |
| 17 |
#define MOWGLI_DNS_NS_MAXCDNAME 255 |
| 18 |
#define MOWGLI_DNS_QUERY 0 |
| 19 |
#define MOWGLI_DNS_IQUERY 1 |
| 20 |
#define MOWGLI_DNS_NO_ERRORS 0 |
| 21 |
#define MOWGLI_DNS_SERVFAIL 2 |
| 22 |
#define MOWGLI_DNS_NXDOMAIN 3 |
| 23 |
#define MOWGLI_DNS_C_IN 1 |
| 24 |
#define MOWGLI_DNS_QFIXEDSIZE 4 |
| 25 |
#define MOWGLI_DNS_RRFIXEDSIZE 10 |
| 26 |
#define MOWGLI_DNS_HFIXEDSIZE 12 |
| 27 |
|
| 28 |
typedef struct |
| 29 |
{ |
| 30 |
unsigned id : 16; /* query identification number */ |
| 31 |
#ifdef WORDS_BIGENDIAN |
| 32 |
|
| 33 |
/* fields in third byte */ |
| 34 |
unsigned qr : 1;/* response flag */ |
| 35 |
unsigned opcode : 4; /* purpose of message */ |
| 36 |
unsigned aa : 1;/* authoritive answer */ |
| 37 |
unsigned tc : 1;/* truncated message */ |
| 38 |
unsigned rd : 1;/* recursion desired */ |
| 39 |
/* fields in fourth byte */ |
| 40 |
unsigned ra : 1;/* recursion available */ |
| 41 |
unsigned unused : 1; /* unused bits (MBZ as of 4.9.3a3) */ |
| 42 |
unsigned ad : 1;/* authentic data from named */ |
| 43 |
unsigned cd : 1;/* checking disabled by resolver */ |
| 44 |
unsigned rcode : 4; /* response code */ |
| 45 |
#else |
| 46 |
|
| 47 |
/* fields in third byte */ |
| 48 |
unsigned rd : 1;/* recursion desired */ |
| 49 |
unsigned tc : 1;/* truncated message */ |
| 50 |
unsigned aa : 1;/* authoritive answer */ |
| 51 |
unsigned opcode : 4; /* purpose of message */ |
| 52 |
unsigned qr : 1;/* response flag */ |
| 53 |
/* fields in fourth byte */ |
| 54 |
unsigned rcode : 4; /* response code */ |
| 55 |
unsigned cd : 1;/* checking disabled by resolver */ |
| 56 |
unsigned ad : 1;/* authentic data from named */ |
| 57 |
unsigned unused : 1; /* unused bits (MBZ as of 4.9.3a3) */ |
| 58 |
unsigned ra : 1;/* recursion available */ |
| 59 |
#endif |
| 60 |
|
| 61 |
/* remaining bytes */ |
| 62 |
unsigned qdcount : 16; /* number of question entries */ |
| 63 |
unsigned ancount : 16; /* number of answer entries */ |
| 64 |
unsigned nscount : 16; /* number of authority entries */ |
| 65 |
unsigned arcount : 16; /* number of resource entries */ |
| 66 |
} mowgli_dns_resheader_t; |
| 67 |
|
| 68 |
/* |
| 69 |
* Inline versions of get/put short/long. Pointer is advanced. |
| 70 |
*/ |
| 71 |
#define MOWGLI_DNS_NS_GET16(s, cp) { \ |
| 72 |
const unsigned char *t_cp = (const unsigned char *) (cp); \ |
| 73 |
(s) = ((uint16_t) t_cp[0] << 8) \ |
| 74 |
| ((uint16_t) t_cp[1]) \ |
| 75 |
; \ |
| 76 |
(cp) += MOWGLI_DNS_NS_INT16SIZE; \ |
| 77 |
} |
| 78 |
|
| 79 |
#define MOWGLI_DNS_NS_GET32(l, cp) { \ |
| 80 |
const unsigned char *t_cp = (const unsigned char *) (cp); \ |
| 81 |
(l) = ((uint32_t) t_cp[0] << 24) \ |
| 82 |
| ((uint32_t) t_cp[1] << 16) \ |
| 83 |
| ((uint32_t) t_cp[2] << 8) \ |
| 84 |
| ((uint32_t) t_cp[3]) \ |
| 85 |
; \ |
| 86 |
(cp) += MOWGLI_DNS_NS_INT32SIZE; \ |
| 87 |
} |
| 88 |
|
| 89 |
#define MOWGLI_DNS_NS_PUT16(s, cp) { \ |
| 90 |
uint16_t t_s = (uint16_t) (s); \ |
| 91 |
unsigned char *t_cp = (unsigned char *) (cp); \ |
| 92 |
*t_cp++ = t_s >> 8; \ |
| 93 |
*t_cp = t_s; \ |
| 94 |
(cp) += MOWGLI_DNS_NS_INT16SIZE; \ |
| 95 |
} |
| 96 |
|
| 97 |
#define MOWGLI_DNS_NS_PUT32(l, cp) { \ |
| 98 |
uint32_t t_l = (uint32_t) (l); \ |
| 99 |
unsigned char *t_cp = (unsigned char *) (cp); \ |
| 100 |
*t_cp++ = t_l >> 24; \ |
| 101 |
*t_cp++ = t_l >> 16; \ |
| 102 |
*t_cp++ = t_l >> 8; \ |
| 103 |
*t_cp = t_l; \ |
| 104 |
(cp) += MOWGLI_DNS_NS_INT32SIZE; \ |
| 105 |
} |
| 106 |
|
| 107 |
extern int mowgli_dns_dn_expand(const unsigned char *msg, const unsigned char *eom, const unsigned char *src, char *dst, int dstsiz); |
| 108 |
extern int mowgli_dns_dn_skipname(const unsigned char *ptr, const unsigned char *eom); |
| 109 |
extern unsigned int mowgli_dns_ns_get16(const unsigned char *src); |
| 110 |
extern unsigned long mowgli_dns_ns_get32(const unsigned char *src); |
| 111 |
extern void mowgli_dns_ns_put16(unsigned int src, unsigned char *dst); |
| 112 |
extern void mowgli_dns_ns_put32(unsigned long src, unsigned char *dst); |
| 113 |
extern int mowgli_dns_res_mkquery(const char *dname, int query_class, int type, unsigned char *buf, int buflen); |
| 114 |
|
| 115 |
#endif /* MOWGLI_SRC_LIBMOWGLI_DNS_EVLOOP_RESLIB_H_INCLUDE_GUARD */ |