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